Jump to content

Element Data Setting


Karuzo

Recommended Posts

Posted
    function onQuit () 
        local data = getElementData(source,"LoggedIN") 
        outputDebugString ( tostring ( data ) ) 
        if ( data ) then 
            local money = getPlayerMoney ( source ) 
            local skin = getPedSkin ( source ) 
            local health = getElementHealth ( source ) 
            local int,dim = getElementInterior ( source ), getElementDimension ( source ) 
            local x,y,z = getElementPosition (source) 
            local inserting = dbExec ( connect, "INSERT INTO accounts ( money,skin,health,x,y,z,int,dim ) VALUES (?,?,?,?,?,?,?,? )", money, skin, healt, x, y, z, int, dim ) 
            if inserting then 
                outputDebugString("Inserting successfull") 
            else 
                outputDebugString("Inserting failed.") 
            end 
        end 
    end 
    addEventHandler ("onPlayerQuit", root, onQuit) 

Check this out.

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted (edited)

@pa3ck:

Yes i am .

As you can see on this picture:

sLxa962.png

@WhoAmI:

I get an Error in the console :

8l4a.png

Edited by Guest
Posted

I don't know much about SQLite browsers, but I can see a line there, 'username KRZO'. Try to update it instead of inserting and use WHERE.

Posted

WTF.

Now it outputted in the debug, INSERT SUCCESSFULL.

So i think you solved the problem WhoAmI :P

Thank you for that.

Another Question.

I have to specify a player , where he should insert the datas , right ?

Can i make it like this : INSER INTO accounts (.....) VALUES(.....) WHERE (username) ?

Posted

Oh, so

dbExec ( connect, "INSERT INTO accounts ( username, money,skin,health,x,y,z,int,dim ) VALUES (?,?,?,?,?,?,?,?,? )", username, money, skin, healt, x, y, z, int, dim ) 

Posted

Nah,

i mean lets say i have a guy who is registered and has now a Column with username and password.

And i want to insert those datas into this specific player.

How could i do that ?

Posted

Last Question,

how should i get the username ?

I know with triggering but can i trigger to a function where an event is already handled?

Like

  
triggerServerEvent("OnQuitPlayer", getLocalPlayer(),username) 

?

And than in Serverside:

  
        addEvent("OnQuitPlayer", true) 
        addEventHandler("OnQuitPlayer", root, onQuit) 

?

Posted

Well, I dont really know what you mean. You want get username from what? From database? You can get it in login function and saves into element data.

Posted

Well no i mean from the client-side .

i get the username like that :

local username = guiGetText(Username_edit)

and trigger it.

Posted

Yeah works everything thank you.

And what about getting the datas ?SELECT x, y,z, FROM accounts WHERE x=? AND y=? AND z=? ,...

Like this ?

Posted
SELECT * FROM accounts WHERE username=? 

And then dbPoll, then you can download all records.

How do you mean that downloading all records ?

Posted

I mean all records from columns. This '*' means everything. But it will download a records where username is some player's username.

Posted

Oh, so he is downloading everything from the specific player , right ?

And how can i use those datas to set them ?

like x=data.x ?

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