Jump to content

DD/DM ranking + Points


Qfury

Recommended Posts

Hi, i need help with this script. I will that the 1st guy that dies get 0 Points and the 2nd 1 Point the 3rd 2 Points and so on

I saw already many script snippets but they didn't help me. So thats what i already have:

Client:

  
localPlayer = getLocalPlayer() 
  
function addColumns() 
    exports.scoreboard:scoreboardAddColumn("Points") 
    exports.scoreboard:scoreboardAddColumn("Race Wins")  
    exports.scoreboard:scoreboardAddColumn("Race Loses")     
    setElementData(localPlayer,"Points",0) 
    setElementData(localPlayer,"Race Loses",0) 
    setElementData(localPlayer,"Race Wins",0)    
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), addColumns) 
  

Server:

  
local rootElement = getRootElement() 
  
  
addEventHandler("onPlayerWasted",rootElement, 
function () 
setElementData(source,"Race Loses",tonumber(getElementData(source,"Race Loses"))+1) 
setElementData(source,"Points",tonumber(getElementData(source,"Points"))+1) 
local serial = getPlayerSerial(source) 
local oldData = executeSQLSelect( "RaceStats", "RaceLoses","serial = '" .. serial .. "'") 
newData = tonumber(oldData[1]["RaceWins"]) + 1 
executeSQLUpdate ( "RaceStats", "RaceLoses = '"..newData.."'","serial = '" .. serial .. "'")     
end) 
  

As you can see all players get 1 Point when they lose. What do i need to add that the 1st loser gets 0 Points the 2nd 1 Point the 3rd 2 Points and so on?

Link to comment

its useless right?

im using a new code:

addEvent("onPlayerWasted") 
function player_Wasted() 
    for i,v in ipairs(getElementsByType('player')) do 
        local rank = exports.race:getPlayerRank(player) 
        if(rank == 2) then 
            givePlayerMoney(v, 1500) 
            outputChatBox('Rank 2:' .. getPlayerName(v).. '') 
        end 
        if(rank == 1) then 
            givePlayerMoney(v, 1500) 
            outputChatBox('Rank 1:' .. getPlayerName(v).. '') 
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), player_Wasted) 

now i need to add getAlivePlayers and the server need to count how many players we have an need to know that the 1st guy who dies is the last rank and get no Points and the 2nd guy who dies gets 1 Point the 3rd guy who dies 2 Points and so on.

Anyone that knows how i can get this?

Link to comment

i added this line above "if(rank == 2) then"

  
        local dead = getDeadPlayers() 
        if (dead == 1) then 
            outputChatBox('1st dead:' .. getPlayerName(v).. '') 
        end 
  

i was hoping the server is posting that in chat but it doesn't. Why?

Link to comment

ok i think i got it.

addEvent("onPlayerWasted") 
function player_Wasted() 
    for i,v in ipairs(getElementsByType('player')) do 
        local rank = exports.race:getPlayerRank(player) 
        if(rank == 2) then 
            givePlayerMoney(v, 1500) 
            outputChatBox('Rank 2:' .. getPlayerName(v).. '') 
        end 
        if(rank == 1) then 
            givePlayerMoney(v, 1500) 
            outputChatBox('Rank 1:' .. getPlayerName(v).. '') 
        end 
    end 
end 
addEventHandler("onPlayerWasted", getRootElement(), player_Wasted) 
  
function playerCount ( ) 
    outputChatBox ( "There are now " .. getPlayerCount() .. " players dead" ) 
    local dead = getPlayerCount() 
        if (dead == 1) then 
            outputChatBox('1st dead') 
            setElementData(source,"Points",tonumber(getElementData(source,"Points"))+1) 
        end 
end 
addEventHandler("onPlayerWasted", getRootElement(), playerCount) 
  

now the Players get counted when they dying. So i can add many ifs up to 32 Ranks where the last one gets the most Points.

But when you have some tips than please post it.

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