Jump to content

[OK] MySQL - Read Datas


Recommended Posts

Hi all,

Here is a part of my "Userpanel" script.

I try to retrieve player's datas into variables.

Is it better to keep these variables clientside (what i did) or keep this in a table serverside ?

I mean ... most of the variables can be edited when server is running.

Last question : when must i save the datas to mysql ? When a player quit or with a timer ?

Serverside :

  
    -- Retrieve Datas from Player table 
    dataQuery = dbQuery(connect, "SELECT * FROM Player WHERE nickname = '"..account.."'") 
    resultPlayer = dbPoll(dataQuery, -1) 
    playerDatas = resultPlayer[1] 
    triggerClientEvent("onReadData",rootElement,playerDatas) 
  

Clientside :

  
function calledByReadData(datas) 
    local account = datas.nickname 
    local password = datas.password 
    local mail = datas.mail 
    local day = datas.day 
    local month = datas.month 
    local year = datas.year 
    local level = datas.level 
    local VIP = datas.VIP 
    local welcomeText = datas.welcomeText 
    outputDebugString("Test pseudo = "..account.." !") 
    --like : 
    -- local money = datas.money or 0 
    -- local playtime = datas.playtime or 0 --for example. 
end 
addEvent("onReadData",true) 
addEventHandler("onReadData",calledByReadData) 
  

Edited by Guest
Link to comment
addEventHandler("onReadData",calledByReadData) 

Should be:

addEventHandler("onReadData", root, calledByReadData) 

And here you must use sendTo argument or it will be root by default which mean it will send the data to all clients.

triggerClientEvent("onReadData",rootElement,playerDatas) 

I'll assume that the player you want send to him the data is source:

triggerClientEvent(source, "onReadData", root, playerDatas) 

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