Jump to content

GetAccountData to client server


stefutz101

Recommended Posts

Posted

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

560x95_FFFFFF_B7FF00_000000_000000.png
Posted
triggerServerEvent 
triggerClientEvent 

It's actually not that hard, you'll just call the server with the relevant arguments then let it pass them back to the client.

function be_remove() {

        printf("Too much gaming and too little sleep makes Olle wanna kill...");

        be_remove();

}

Posted (edited)

As Overkillz and Olle Risk said,

for an exp system, you can use

setElementData 
getElementData 

and then save the data using

getAccountData 
setAccountData 

Edited by Guest

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted
setElementData can already sync the data between server-side and client-side.

Oh yeah, my bad, i'll remove the triggerServerEvent.

"When i'll grow older, i'll be stronger, they'll call me freedom, just like a waving flag"

"Have confidence in yourself, no problem is impossible in life"

Posted

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 ?

560x95_FFFFFF_B7FF00_000000_000000.png
Posted
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 :(

560x95_FFFFFF_B7FF00_000000_000000.png
Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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) 

560x95_FFFFFF_B7FF00_000000_000000.png
Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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.

560x95_FFFFFF_B7FF00_000000_000000.png

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