Jump to content

Points error


Norhy

Recommended Posts

Posted

Hey guys, i'm making a simple points system, but i'm getting an error.

function checkPoints ( player, command ) 
    local points = getElementData ( player, "kills" ) 
    outputChatBox ( "Points: " .. points, player, getRootElement(), 255, 255, 255 ) 
end 
addCommandHandler ( "points", checkPoints ) 

I get the error: " attempt to concatenate local 'points' ".

I've also tried this code:

function checkPoints ( player, command ) 
    outputChatBox ( "Points: " .. getElementData ( player, "points" ), player, getRootElement(), 255, 255, 255 ) 
end 
addCommandHandler ( "points", checkPoints ) 

But i get the error with this code too. How to solve this?

Posted

Must be because 'kills' is returning 'false', this should return '0' if he has no data.

function checkPoints ( player ) 
    local points = getElementData ( player, "kills" ) or 0 
    outputChatBox ( "Points: ".. points, player, 255, 255, 255 ) 
end 
addCommandHandler ( "points", checkPoints ) 

Posted

Thanks Castillo, you were always a great helper. However you may be confused why i use 'kills' as 'points', it's because i don't know if the system will know what 'points' data is when i use it with setElementData.

However it works now. I have also maked a system when you die you get money and 1 point, but it doesn't work :/

function deathMoney ( player ) 
    givePlayerMoney ( source, 1000 ) 
    outputChatBox ( "hi", getRootElement(), 255, 255, 255, true ) 
    setElementData ( player, "points", 1 ) 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), deathMoney ) 

By the way, is it possible to add (+) the 'points'? Because using setElementData it will always set points to 1.

Thanks for you help and patience.

Posted

Then, instead of using "kills" data name, use "points".

To add + 1 each time use:

setElementData ( player, "points", getElementData ( player, "points" ) + 1 ) 

But the first argument of 'onPlayerWasted' is the totalAmmo, not a player element.

Posted

Thanks. One last question, is it possible to find out on which place the player died in race? I mean if there are 3 player connected, and he dies on the 3rd place, he'll get the lowest amount of money, on 2nd more amount of money and on first the most amount of money? If so, how?

Posted
Thanks. One last question, is it possible to find out on which place the player died in race? I mean if there are 3 player connected, and he dies on the 3rd place, he'll get the lowest amount of money, on 2nd more amount of money and on first the most amount of money? If so, how?

Make an increasable variable , and start to count.

Posted

But if i want to use this i need to get the players online or? Because if i have let's say 10 ranks and 3 players are online (10 - 3 = 7) the 7th rank will be taken as the 1st

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