Jump to content

[REQUEST]Creating a LvL System.


capitanazop

Recommended Posts

Posted

hi when im triying to create a LvL system example: you kills 5 players and level up to lvl 2 and if you are lvl 2 you hp is now 75 and you armor 15.

here is a part of the code, the idea is colaborate and complement the code, and i thinks that script have problem.

function cdm_playerWasted( totalAmmo, killer ) 
    setPlayerTeam ( source, nil ) 
    if ( killer) then 
        if ( killer ~= source ) then 
            setElementData( killer, "Kills", getElementData( killer, "Kills" ) + 1 ) 
            setElementData( source, "Deaths", getElementData( source, "Deaths") + 1 ) 
        else 
             
            setElementData( source, "Deaths", getElementData( source, "Deaths") + 1 ) 
        end 
  
        local kills = getElementData( killer, "Kills") 
        local maton = getClientName(killer) 
        if (kills == 2 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 2!", killer) 
        elseif (kills == 3 ) then 
            outputChatBox(""..maton.."Level Up! now you´re LvL 3!", killer) 
        elseif (kills == 5 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 4!", killer) 
        elseif (kills == 10 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 5!", killer) 
        elseif (kills == 15 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 6!", killer) 
        elseif (kills == 20 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 7!", killer) 
        elseif (kills == 25 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 8!", killer) 
        elseif (kills == 50 ) then 
            outputChatBox(""..maton.." Level Up! now you´re LvL 9!", killer) 
        end 
         
    else 
        setElementData( source, "Kills", getElementData( source, "Kills" ) - 1 ) 
        setElementData( source, "Deaths", getElementData( source, "Deaths") + 1 ) 
         
     

and for save that.

function onPlayerQuit ( ) 
  
      -- when a player leaves, store his current Score amount in his account data 
      local playeraccount = getClientAccount ( source ) 
      if ( playeraccount ) then 
            local playerScore = getPlayerScore ( source ) 
            setAccountData ( playeraccount, "exp.lvl", playerScore ) 
      end 
end 
  
function onPlayerJoin ( ) 
      -- when a player joins, retrieve his Score amount from his account data and set it 
      local playeraccount = getClientAccount ( source ) 
      if ( playeraccount ) then 
            local playerScore = getAccountData ( playeraccount, "exp.lvl" ) 
            -- make sure there was actually a value saved under this key (check if playerScore is not false). 
            -- this will for example not be the case when a player plays the gametype for the first time 
            if ( playerScore ) then 
                  setPlayerScore ( source, playerScore ) 
            end 
      end 
end 
  
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 

if you find errors or u wanna add stuff,utils etc... to the script post it ;D.

bye n sorry for ma english

Posted

Nice, and if you made something with attack damage, that would show unique features of MTA :) And you could make some sequence for this to make infinite levels :)

Posted

1. You use setAccountData(), don't use it untill DP3.

2. You getClientAccount() when he joins, his account is guest account until he logs in (I'm not sure if it would work if auto-login is enabled).

Posted
1. You use setAccountData(), don't use it untill DP3.

You can safely use setAccountData, just check if user is logged in

Oh sh1t, lil Toady posted in the forum! :shock:

So what you're saying is, it only freaks out and wipes all account data if the user's not logged in?

And it's XML-based, isn't it?

Posted
1. You use setAccountData(), don't use it untill DP3.

You can safely use setAccountData, just check if user is logged in

I don't know how many times I have to say that.. but why don't you check first (or second) version of my bank resource and see that people were complaining... I didn't want "not logged in" users to save their money so I had to check if they are logged in first. I will always tell people not to use setAccountData in DP2 because my "well known" bank resource was built with this and failed at the beginning.

1. You use setAccountData(), don't use it untill DP3.

You can safely use setAccountData, just check if user is logged in

Hmm that might explain why i never had problems with that in the beginning.

You must be one of those lucky guys. Maybe OS has got something to do with this, I don't know because I never had Linux, UNIX, etc. servers, so people be aware of accounts being wiped after setAccountData been used.

Posted

It works perfect to me too, but also had that problem.

When registering a player i was setting the email before login and it deleted the account's data, just moving a line within a if and it works now perfect. Btw im using a lot of variables inside account data.

  • 3 weeks later...
Posted

why dont you optamize the code by makeing the "

you leveled up to level 2

change to something like

you leveled up to level [current level+ 1]

then you have unlimited levels, and just set a max level....

you could allso translate it to a percentage bar, eg

50/125 xp

Posted

Slightly off-topic here, but coding in non-english is incredibly bad practice, especially if you want help with your script.

  • 10 months later...

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