Jump to content

Counting Player Rank "HELP!"


.:HyPeX:.

Recommended Posts

Guys, im stuck, totally.

The idea of this podium is to get the current players still alive racing with getAlivePlayers. Yeah it works.

Now the problem is: getAlivePlayers will include also joined and waiting players. So, if a player joins while the race, he's counted as an alive player, and the rank 1 is never reached.

So, how can i fix this? i appreaciate any help

script:

  
  
function AutomaticSetPlayer() 
if get("AutomaticPodium") == "true" then 
local players = getAlivePlayers() 
local playerRank = #players 
if playerRank == 2 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished third!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "3") 
elseif playerRank == 1 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished second!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "2") 
elseif playerRank == 0 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished First!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "1") 
else 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Died!", getRootElement(), 255,255,255,true) 
end 
end 
end 
addEventHandler("onPlayerWasted", getRootElement(), AutomaticSetPlayer) 

Thanks in advance, HyPeX

Link to comment

Hmm i thought about creating a table on map start.. and only use that table..but then the problem is that i dont have how to calculate how many of them are dead..

EDIT: Should this work?

  
DeadTable = {} 
function AutomaticSetPlayer() 
DeadTable[source] = source 
if get("AutomaticPodium") == "true" then 
local TotalPlayers = #PlayingTable 
local DeadPlayers = #DeadTable 
local playerRank = TotalPlayers - DeadPlayers 
if playerRank == 2 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished third!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "3") 
elseif playerRank == 1 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished second!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "2") 
elseif playerRank == 0 then 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Finished First!", getRootElement(), 255,255,255,true) 
triggerClientEvent("PlayerPosWasted", getRootElement(), source, "1") 
else 
outputChatBox("#00cc55Player "..getPlayerNametagText(source).." Died!", getRootElement(), 255,255,255,true) 
end 
end 
end 
addEventHandler("onPlayerWasted", getRootElement(), AutomaticSetPlayer) 
  
function SetPlayerTable() 
PlayingTable = nil 
PlayingTable = {} 
for v,i in ipairs(getElementsByType("players")) do 
PlayingTable[v] = v 
DeadTable[v] = nil 
end 
end 
addEventHandler("onMapStarting", getRootElement(), SetPlayerTable) 

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