Jump to content

GetAccountData to client server


stefutz101

Recommended Posts

Hi i want to make a lvl-script on DayZ Mta , and i want to make on screen to show you current exp / exp to lvl up . But how i cant make go GetAccountData on client side ? The experience is saved in account data on server-side so i need a function to get "exp" frome server-side . Help , please ? :D Please :( :(

Link to comment

I already try with getElementData but it display 0 . http://iceimg.net/images/2015/08/28/mta ... -49-28.png

With getAccountData i try too , but i have error : attempting to concatenate a nil value .

Client-Side

local thePlayer= getLocalPlayer() 
local currentexp = GetAccontData(thePlayer,"exp") 
  

I looked in client function on wiki and getAccountData isn't , so i think is only server-side .

I will try with triggerServerEvent . It must be something like this ? : triggerServerEvent("onZombieGetsKilled" , thePlayer , "exp" ). It's good ?

Link to comment
local thePlayer = getLocalPlayer() 
addEventHandler("onClientResourceStart", resourceRoot, 
    function()     
    end 
) 
addEventHandler("onClientRender", root, 
    function() 
        triggerServerEvent(thePlayer,'onZombieGetsKilled',root, currentexp) 
        local currentlvl = getElementData(thePlayer, "lvl") or 1 
        dxDrawText(currentexp.."",   600,   104,  688, 128, tocolor(255, 255, 255, 255), 0.50, "bankgothic", "left", "top") 
        dxDrawText("/",   625,   104,  688, 128, tocolor(30, 247, 7, 255), 0.50, "bankgothic", "left", "top") 
        dxDrawText(""..levelExp[currentlvl],  650,104,796,123, tocolor(255, 255, 255, 255), 0.50, "bankgothic", "left", "top") 
          
         
    end 

This is Client-side , and btw i have defined levelExp . It work but for lvlExp[currentlvl] but now dont display nothing . :(

Ps : SetElementData ? You want to say GetElementData ?

Help , please :(

Link to comment

It's messed up. Why are you triggering the event from the server in the first place. (sorry for not pointing this out in the first reply)

You can just use setElementData server-side and getElementData client-side. While this is not the best approach, performance wise, it still the easiest one.

Link to comment

I do it but i have a problem , if player leave server when player he have lvl 0. And 0 exp

function login(source) 
        setElementData(source, "lvl", getElementData(source,"lvl")) 
        setElementData(source, "exp", getElementData(source,"exp")) 
end 
addEventHandler("onPlayerLogin", getRootElement(),login) 
  
  
function login(source) 
        local currentexp = getElementData(source, "exp") or 0 
        local currentlvl = getElementData(source, "lvl") or 1 
         
        setElementData(source, "lvl", tonumber(currentlvl)) 
        setElementData(source, "exp", tonumber(currentexp)) 
end 
addEventHandler("onPlayerQuit", getRootElement(),login) 

Link to comment

Element data are session based, when the player leaves the server it's reset. You need setAccountData to actually save the data.

On login you load the data using getAccountData, then you set it as element data for the player. On quit/logout you save it with setAccountData.

Link to comment

Solved , ty :D

But i have an bug : Example : if i have EXP : 95 / 100 and i kill a zombie and toad ( local toad= math.random(10, 15) and for example toad is 10 i will have 105/100 exp but at next zombie killed i will make lvl up and 5 / 115 . I can fix this ? It's not important bug but i ask if i can solve it.

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