Jump to content

EXP System


Recommended Posts

Hello, can somebody help me here, if player is guest and not logged in his XP must be 0

And play sound when level up thanks for helping here is the script.

Server.lua

exports.scoreboard:scoreboardAddColumn("XP") 
exports.scoreboard:scoreboardAddColumn("Level") 
local levels = {[100] = 1, [300] = 2, [500] = 3, [700] = 4, [1000] = 5, [1800] = 6, [2900] = 7, [5000] = 8, [9999] = 9, [20000] = 10} 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "XP") 
        local S = getElementData(killer, "Level") 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "XP", tonumber(H)+math.random ( 5, 35 ) ) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "LV") or "0 ") 
    setElementData(source, "XP", getAccountData(account, "EXP") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function saveData(thePlayer, theAccount) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "LV", getElementData(thePlayer, "Level")) 
        setAccountData (theAccount, "EXP", getElementData(thePlayer, "XP")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 

Edited by Guest
Link to comment
function saveData(thePlayer, theAccount) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "LV", getElementData(thePlayer, "Level")) 
        setAccountData (theAccount, "EXP", getElementData(thePlayer, "XP")) 
    else  
        cancelEvent() 
    end 
end 

there you need to pun an "else", is not tested....

Link to comment

Not working, i tried making it myself but it show an error here is the code

local levels = {[100] = 1, [300] = 2, [500] = 3, [700] = 4, [1000] = 5, [1800] = 6, [2900] = 7, [5000] = 8, [9999] = 9, [20000] = 10} 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "XP") 
        local S = getElementData(killer, "Level") 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "XP", tonumber(H)+math.random ( 5, 35 ) ) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "LV") or "0") 
    setElementData(source, "XP", getAccountData(account, "EXP") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function onJoin (_,account) 
    if isGuestAccount ( account ) then 
        setElementData(source, "Level","0") 
        setElementData(source, "XP","0") 
    end 
end 
addEventHandler ("onPlayerJoin", root, onJoin) 
  
function saveData(thePlayer, theAccount) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "LV", getElementData(thePlayer, "Level")) 
        setAccountData (theAccount, "EXP", getElementData(thePlayer, "XP")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 

thats the error

  
experience/server.lua:25:Bad argument @ 'isGuestAccount' [Expected account at argument 1,got nil] 
  

Link to comment
local levels = {[100] = 1, [300] = 2, [500] = 3, [700] = 4, [1000] = 5, [1800] = 6, [2900] = 7, [5000] = 8, [9999] = 9, [20000] = 10} 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "XP") 
        local S = getElementData(killer, "Level") 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "XP", tonumber(H)+math.random ( 5, 35 ) ) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Level", "Lvl ".. tostring(levels[tonumber(H)]) .." !") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Level", getAccountData(account, "LV") or "0") 
    setElementData(source, "XP", getAccountData(account, "EXP") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function onJoin (_,account) 
    if isGuestAccount ( account ) then 
        setElementData(source, "Level","0") 
        setElementData(source, "XP","0") 
    end 
end 
addEventHandler ("onPlayerJoin", root, onJoin) 
  
function saveData(thePlayer, theAccount) 
local theAccount = getPlayerAccount(source) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "LV", getElementData(thePlayer, "Level")) 
        setAccountData (theAccount, "EXP", getElementData(thePlayer, "XP")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 

try it now, not tested :D

Link to comment

if you make

triggerClientEvent ( killer, "playSound", killer ) 

you need in client side a function with

playSound  
--or 
playSound3D  

if you want a sound ..

EDIT :

addEvent("playSound",true) 
addEventHandler("playSound", getRootElement(),  
function () 
local sound = playSound("SOUND")  
    setSoundVolume(sound, 0.5) -- set the sound volume to 50% 
end 

Link to comment

on MTA exist functions in client side and in server side , with

triggerClientEvent ( killer, "playSound", killer ) 

you transfer a information form server side in client side

:D

I do not know how to explain it better.

Wiki type : This function triggers an event previously registered on a client. This is the primary means of passing information between the server and the client. Clients have a similar triggerServerEvent function that can do the reverse. You can treat this function as if it was an asynchronous function call, using triggerServerEvent to pass back any returned information if necessary.

Almost any data types can be passed as expected, including elements and complex nested tables. Non-element MTA data types like xmlNodes or resource pointers will not be able to be passed as they do not necessarily have a valid representation on the client.

Events are sent reliably, so clients will receive them, but there may be (but shouldn't be) a significant delay before they are received. You should take this into account when using them.

Keep in mind the bandwidth issues when using events - don't pass a large list of arguments unless you really need to. It is marginally more efficient to pass one large event than two smaller ones.

Link to comment
--- SERVER SIDE 
 addEventHandler ( "onPlayerWasted", root, -- onPlayerWasted is a server side event, you can use it in client side and we want to do with this event something in client side, therefore we make a triggerClientEvent 
        function ( theKiller ) 
            triggerClientEvent(theKiller, "gret", getRootElement()) 
        end 
    ) 

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