#Paper Posted March 11, 2011 Share Posted March 11, 2011 I need a help to make an script... I must make a Rank System: The ranks haven't a limit. (Level 1, Level 2, Level 3 etc... etc...) Every 500 kills you level up... How i can make that algorithm? (I think that i need to make an algorithm) Link to comment
Moderators Citizen Posted March 11, 2011 Moderators Share Posted March 11, 2011 It's very simple: you have to make: setElementData( thePlayer, "Level", theLevel ) setElementData( thePlayer, "Kills", theLevel ) setElementData( thePlayer, "xp", theXP ) Then in onPedWasted, you increase the Kills and xp of the attacker and call a function like levelUp( thePlayer ): function levelUp( thePlayer ) if getElementType( thePlayer ) == "player" then -- if the attacker is a player local level = getElementData( thePlayer, "Level" ) local xp = getElementData( thePlayer, "xp" ) if xp >= 500 then -- if he kills 500 peds or more ( if there is a bug ^^) setElementData( thePlayer "xp", 0 ) -- go back to 0 setElementData( thePlayer, "Level", level+1 )-- We increase his level outputChatBox("You are now level "..getElementData( thePlayer, "Level" ).." !", thePlayer, 0, 180, 0 ) end end end Try to make your system now Link to comment
#Paper Posted March 11, 2011 Author Share Posted March 11, 2011 It's very simple: you have to make: setElementData( thePlayer, "Level", theLevel ) setElementData( thePlayer, "Kills", theLevel ) setElementData( thePlayer, "xp", theXP ) Then in onPedWasted, you increase the Kills and xp of the attacker and call a function like levelUp( thePlayer ): function levelUp( thePlayer ) if getElementType( thePlayer ) == "player" then -- if the attacker is a player local level = getElementData( thePlayer, "Level" ) local xp = getElementData( thePlayer, "xp" ) if xp >= 500 then -- if he kills 500 peds or more ( if there is a bug ^^) setElementData( thePlayer "xp", 0 ) -- go back to 0 setElementData( thePlayer, "Level", level+1 )-- We increase his level outputChatBox("You are now level "..getElementData( thePlayer, "Level" ).." !", thePlayer, 0, 180, 0 ) end end end Try to make your system now I tryed to make that: function checkKills() local players = getElementsByType ( "player" ) -- get a table of all the players in the server for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player local getKills = getElementData(thePlayer, "Kills") local getRank = getElementData(thePlayer, "Rank") local getRankNum = gettok ( getRank, 1, string.byte('Level ') ) if getKills % 500 == 0 then local rankToSet = getRankNum + 1 setElementData(thePlayer, "Rank", "Level "..tonumber(rankToSet)) end end end setTimer(checkKills, 100, -1) I need a thing like this... Errors: gettok = Bad Argument Line 7 = Can't do the operation... Link to comment
12p Posted March 12, 2011 Share Posted March 12, 2011 Okay... This is REALLY wrong, it's too much problem. There is an easy way to do that, that works client and server side. function checkKills ( pl ) if isElement ( pl ) and getElementType ( pl ) == "player" then --Check if "pl" is a player... local k1 = getElementData ( pl, "kills" ) --Now get the kills local a, b = math.modf ( k1 / 500 ) --math.modf returns INTEGER and DECIMAL... if b == 0 and k1 ~= 0 then --If the DECIMAL is 0 and the kills are different from 0 (prevent a possible bug...) setElementData ( pl, "rank", k1 / 500, true ) --Set the level (level is defined by the kills divided by 500: 500 = 1, 1,500 = 3, 500,000 = 1,000). end end end Then use some event handler attached to that. I don't know how you are supposed to set the element data that defines the kills but that is your problem PS. Remember to set the data to accounts, too, to save stats Link to comment
#Paper Posted March 12, 2011 Author Share Posted March 12, 2011 Okay... This is REALLY wrong, it's too much problem. There is an easy way to do that, that works client and server side. function checkKills ( pl ) if isElement ( pl ) and getElementType ( pl ) == "player" then --Check if "pl" is a player... local k1 = getElementData ( pl, "kills" ) --Now get the kills local a, b = math.modf ( k1 / 500 ) --math.modf returns INTEGER and DECIMAL... if b == 0 and k1 ~= 0 then --If the DECIMAL is 0 and the kills are different from 0 (prevent a possible bug...) setElementData ( pl, "rank", k1 / 500, true ) --Set the level (level is defined by the kills divided by 500: 500 = 1, 1,500 = 3, 500,000 = 1,000). end end end Then use some event handler attached to that. I don't know how you are supposed to set the element data that defines the kills but that is your problem PS. Remember to set the data to accounts, too, to save stats Can you fix it? function checkKills( ammo, thePlayer, weapon, bodypart ) local getKills = getElementData(thePlayer, "Kills") local getRank = getElementData(thePlayer, "Rank") local getRankNum = gettok ( getRank, 1, string.byte('Level ') ) if getKills % 500 == 0 then local rankToSet = getRankNum + 1 setElementData(thePlayer, "Rank", "Level "..tonumber(rankToSet)) end end addEventHandler("onPedWasted", getRootElement(), checkKills) Link to comment
Castillo Posted March 13, 2011 Share Posted March 13, 2011 Are you kidding us AcitanoX? you must use his code as he already said. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now