Jump to content

Algorithm


#Paper

Recommended Posts

  • Moderators

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

Link to comment
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 :wink:

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

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

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