Jump to content

Coins script


Jockie

Recommended Posts

Posted

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.

Posted

:o.. 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.

Posted

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"

Posted

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)

Posted

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)

Posted
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*

Posted (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. :S

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 by Guest
Posted

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)

Posted

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 :D

(Because, if the player haven't finished the the race, but is still alive, it gets the coins, now)

Posted
EDIT2: Would be useful to retrieve the mode of the race resource, the Sprint, Base or Destruction Derby things.

exports.race:getRaceMode :D

(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
)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...