Jump to content

Coins script


Jockie

Recommended Posts

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

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

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

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)

Link to comment
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
)

Link to comment

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