Jump to content

Element Data Setting


Karuzo

Recommended Posts

  • Replies 77
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Yeah dbQuerys working fine.

  
dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?,int=?,dim=?,money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) 

The problem is , if i log in , i get killed. Wtf ?

Link to comment

Login:

  
function login_func ( player, username, password) 
    local query = dbQuery ( connect, "SELECT username, password FROM accounts WHERE username = ?", username ) 
    local checkdatas = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) 
    outputChatBox ( getElementType ( player ) ) 
    if ( query ) and (checkdatas) then 
        local data, rows = dbPoll ( query, -1 ) 
        local setdata = dbPoll ( checkdatas, -1 ) 
        if ( rows >= 1 ) then 
            if ( data [ 1 ].password == password ) then 
                local x, y, z = setdata.x, setdata.y, setdata.z 
                local money = setdata.money 
                local skin = setdata.skin 
                local health = setdata.health 
                local int = setdata.int 
                local dim = setdata.dim 
                setElementData(player, "LoggedIN",true) 
                --outputChatBox ( tostring ( getElementData ( player, "LoggedIN" ) ) ) 
                --outputChatBox(tostring(elementdata)) 
                outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) 
                outputChatBox("Willkommen zurück,  "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) 
                triggerClientEvent(player,"closeLoginPanel",player) 
                setPlayerMoney(player,tostring(setdata.money)) 
                setElementModel(player,tostring(setdata.skin)) 
                setElementHealth(player,tostring(setdata.health)) 
                setElementInterior(player,tostring(setdata.int)) 
                setElementDimension(player,tostring(setdata.dim)) 
                setElementPosition(player, tostring(setdata.x), tostring(setdata.y), tostring(setdata.z)) 
        else 
                outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) 
            end 
        end 
    end 
end 
addEvent("LoginRequest",true) 
addEventHandler("LoginRequest",getRootElement(),login_func) 

Quit:

  
function onQuit (username) 
                outputChatBox ( getElementType ( source ) ) 
            local data = getElementData(source,"LoggedIN") 
            outputChatBox ( tostring ( data ) ) 
            if ( data ) then 
                local money = getPlayerMoney ( source ) 
                local skin = getElementModel ( source ) 
                local health = getElementHealth ( source ) 
                local int,dim = getElementInterior ( source ), getElementDimension ( source ) 
                local x,y,z = getElementPosition (source) 
                local inserting = dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?,int=?,dim=?,money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) 
                if inserting then 
                    outputDebugString("Inserting successfull") 
                else 
                    outputDebugString("Inserting failed.") 
                end 
            end 
        end 
        addEventHandler ("onPlayerQuit", root, onQuit) 
        addEvent("OnQuitPlayer", true) 
        addEventHandler("OnQuitPlayer", root, onQuit) 
        addCommandHandler("test", onQuit) 

Screenshot:

LqGs95p.png

//Edit: I know what the problem for the 'database is locked' was. I had SQLite Browser open, as i quit.

So the accounts.db was used by SQlite Browser.

But i still get killed.

Link to comment
function login_func ( player, username, password) 
    local query = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) 
    if ( query ) then 
        local data, rows = dbPoll ( query, -1 ) 
        if ( rows > 0 ) then 
            if ( data.password == password ) then 
                local x, y, z = data.x or 0, data.y or 0, data.z or 0 
                local money = data.money or 0 
                local skin = data.skin or 0 
                local health = data.health or 100 
                local int = data.int or 0 
                local dim = data.dim or 0 
                setElementData(player, "LoggedIN",true) 
                outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) 
                outputChatBox("Willkommen zurück,  "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) 
                triggerClientEvent(player,"closeLoginPanel",player) 
                setPlayerMoney(player, money) 
                setElementModel(player, skin) 
                setElementHealth(player, health) 
                setElementInterior(player, int) 
                setElementDimension(player, dim) 
                setElementPosition(player, x, y, z) 
            else 
                outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) 
            end 
        end 
    end 
end 
addEvent("LoginRequest",true) 
addEventHandler("LoginRequest",getRootElement(),login_func) 

Try this out.

Edited by Guest
Link to comment

I'm triggering it from the ClientSide.

  
    addEventHandler("onClientGUIClick", loginsend, 
        function() 
            outputChatBox("button") 
            local username = useredit:setText() 
            local password = passedit:setText() 
            if username == "" or password == "" then 
                outputChatBox("Bitte trage deine Daten ein! Wenn du keinen Account hast melde dich auf ... an!", 125,0,0) 
            else 
                triggerServerEvent("LoginRequest",getLocalPlayer(),getLocalPlayer(),username,password) 
                triggerServerEvent("OnQuitPlayer", getLocalPlayer(),username) 
                setCameraTarget(localPlayer) 
            end 
        end) 

Link to comment

That has no sense.

    addEventHandler("onClientGUIClick", loginsend, 
        function() 
            outputChatBox("button") 
            local username = useredit:setText() 
            local password = passedit:setText() 
            if username == "" or password == "" then 
                outputChatBox("Bitte trage deine Daten ein! Wenn du keinen Account hast melde dich auf ... an!", 125,0,0) 
            else 
                triggerServerEvent("LoginRequest", localPlayer, localPlayer, username,password) 
                setCameraTarget(localPlayer) 
            end 
        end) 

Server:

function onQuit () 
    outputChatBox ( getElementType ( source ) ) 
    local data = getElementData(source,"LoggedIN") 
    local username = getElementData ( source, "username" ) 
    outputChatBox ( tostring ( data ) ) 
    if ( data ) then 
        local money = getPlayerMoney ( source ) 
        local skin = getElementModel ( source ) 
        local health = getElementHealth ( source ) 
        local int, dim = getElementInterior ( source ), getElementDimension ( source ) 
        local x, y, z = getElementPosition ( source ) 
        local inserting = dbExec(connect, "UPDATE accounts SET x=?, y=?, z=?, skin=?, health=?, int=?, dim=?, money=? WHERE username=?", x, y, z, skin,health,int,dim,money, username ) 
        if inserting then 
            outputDebugString("Inserting successfull") 
        else 
            outputDebugString("Inserting failed.") 
        end 
    end 
end 
addEventHandler ("onPlayerQuit", root, onQuit) 
addCommandHandler("test", onQuit) 
  
    function login_func ( player, username, password) 
        local query = dbQuery (connect, "SELECT * FROM accounts WHERE username=?", username ) 
        if ( query ) then 
            local data, rows = dbPoll ( query, -1 ) 
            if ( rows > 0 ) then 
                if ( tostring ( data[1].password ) == tostring ( password ) ) then 
                    local x, y, z = data.x or 0, data.y or 0, data.z or 0 
                    local money = data.money or 0 
                    local skin = data.skin or 0 
                    local health = data.health or 100 
                    local int = data.int or 0 
                    local dim = data.dim or 0 
                    setElementData(player, "LoggedIN",true) 
                    outputChatBox("Du hast dich erfolgreich eingeloggt!",player,0,125,0) 
                    outputChatBox("Willkommen zurück,  "..string.gsub ( getPlayerName ( player ), '#%x%x%x%x%x%x', '' ),player,0,125,0) 
                    triggerClientEvent(player,"closeLoginPanel",player) 
                    setPlayerMoney(player, money) 
                    setElementModel(player, skin) 
                    setElementHealth(player, health) 
                    setElementInterior(player, int) 
                    setElementDimension(player, dim) 
                    setElementPosition(player, x, y, z) 
                    setElementData ( source, "username", username ) 
                else 
                    outputChatBox("Error 404 : Dein Benutzername oder dein Passwort ist falsch!",player,125,0,0) 
                end 
            end 
        end 
    end 
    addEvent("LoginRequest",true) 
    addEventHandler("LoginRequest",getRootElement(),login_func) 

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