Jockie Posted July 17, 2010 Share Posted July 17, 2010 I've created a coins script, it gives coins after everymap. I'm using this script while Race is running. But it gives everyone coins instead of 1 player.(even when one player is online. (Normally the script gives coins @ 2 or higher players)) http://mta.pastebin.com/gQeL357K Link to comment
50p Posted July 17, 2010 Share Posted July 17, 2010 If race returns getPlayerRank with value of 1 every time, for every player, then it's fault of race resource not yours and it will always give all players coins as if they were 1st. Link to comment
Jockie Posted July 17, 2010 Author Share Posted July 17, 2010 .. It's possible with getElementData(player,"Race rank") EDIT: Also not possible.. o.o' EDIT2: It works, sort of, only for 1 player. The coins amount of the others doesn't change, when they win. Link to comment
Dark Dragon Posted July 18, 2010 Share Posted July 18, 2010 you should simply use the server-side race event "onPlayerFinish", for destruction derbies use the "onPlayerWasted" and "onPlayerQuit" event and count the alive players by checking every players "state" element data to be "alive" Link to comment
Jockie Posted July 18, 2010 Author Share Posted July 18, 2010 Is it possible to get the number of "alive" and "death" of every player then? function checkPlayers() local players = getElementsByType("player") for everyone,player in ipairs(players) do local state = getElementData(player, "state") -- ? playedPlayers = alive+dead end end addEventHandler("onPlayerQuit", getRootElement(), checkPlayers) Link to comment
Dark Dragon Posted July 18, 2010 Share Posted July 18, 2010 you can simply count them yourself if you set up an easy function: function getAliveRacePlayers() local playertable = {} -- create an empty table for index,player in ipairs(getElementsByType("player")) do -- loop through all players if getElementData(player,"state") == "alive" then -- check if race considers them alive table.insert(playertable,player) -- insert the player in our table if he's alive end end return playertable -- return the table to whatever called the function end all you need to do then is this to check how many players are alive: #getAliveRacePlayers() -- # is used to get the length of stuff, in case of a table it gives you the amount of entries you can then use it like this: function playerCheck() local players = getElementsByType("player") local aliveplayers = getAliveRacePlayers() givePlayerMoney(source,100*(#players-#aliveplayers)) -- give a player 100$ per player they beat end addEventHandler("onPlayerWasted",getRootElement(),playerCheck) Link to comment
50p Posted July 18, 2010 Share Posted July 18, 2010 function playerCheck() local players = getElementsByType("player") local aliveplayers = getAliveRacePlayers() givePlayerMoney(source,100*(#players-#aliveplayers)) -- give a player 100$ per player they beat end addEventHandler("onPlayerWasted",getRootElement(),playerCheck) *give the dead player* Link to comment
Jockie Posted July 18, 2010 Author Share Posted July 18, 2010 (edited) Oh thanks both, it works. (Or not..) (>c^.^)>cOokie EDIT: @ Destruction derby, the script doesn't give the player coins when it wins, it have to die after it wins. Also, the script doesn't give the player the coins when it finished the race. Currently I have this: http://mta.pastebin.com/hGSuAmCS Edited July 19, 2010 by Guest Link to comment
Dark Dragon Posted July 18, 2010 Share Posted July 18, 2010 check if #aliveplayers is 1, if so give money to aliveplayers[1] function playerCheck() local players = getElementsByType("player") local aliveplayers = getAliveRacePlayers() givePlayerMoney(source,100*(#players-#aliveplayers)) -- give a player 100$ per player they beat if #aliveplayers == 1 then givePlayerMoney(aliveplayers[1],100*(#players+1-#aliveplayers)) end end addEventHandler("onPlayerWasted",getRootElement(),playerCheck) Link to comment
Jockie Posted July 18, 2010 Author Share Posted July 18, 2010 But what if the map is a massive bomb map? EDIT: Solved, used event "onRaceStateChanging" + triggering to client for player > trigger to server for coins, Bug found: The last 2 ranks of the players @ PostFinish are 2. You need to check the winner with getElementData(player, "state") > if alive or finished, winner price. EDIT2: Would be useful to retrieve the mode of the race resource, the Sprint, Base or Destruction Derby things. exports.race:getRaceMode (Because, if the player haven't finished the the race, but is still alive, it gets the coins, now) Link to comment
AcidbRain Posted July 19, 2010 Share Posted July 19, 2010 EDIT2: Would be useful to retrieve the mode of the race resource, the Sprint, Base or Destruction Derby things.exports.race:getRaceMode (Because, if the player haven't finished the the race, but is still alive, it gets the coins, now) g_IsDestructionDerby = nil addEventHandler("onMapStarting", root, function(mapInfo, mapOptions, gameOptions) g_IsDestructionDerby = (mapInfo.modename == "Destruction derby") end ) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now