Jump to content

[HELP] executeSQLQuery


1LoL1

Recommended Posts

Hello, i tried save and load with executeSQLQuery but idk why not work. :(

Errors / Warnings:

Warning: Bad argument @ 'getAccountName' [Expected account at argument 1, got player]

Error: Database query failed: no such column: false

addEventHandler("onPlayerQuit", getRootElement(), 
function () 
    if isGuestAccount(getPlayerAccount(source)) then return end 
    local account = getAccountName(getPlayerAccount(source)) 
    local TEST1 = (getElementData(source, "TEST1") or 0) 
    local TEST2 = (getElementData(source, "TEST2") or 0) 
    local TEST3 = (getElementData(source, "TEST3") or 0) 
    local searchForAPlayer = executeSQLQuery("SELECT TEST1, TEST2, TEST3 FROM Avengers WHERE Account = ?", account) 
    if #searchForAPlayer == 0 then 
        executeSQLQuery("INSERT INTO Avengers (Account, TEST1, TEST2, TEST3) VALUES (?, ?, ?, ?)", account, TEST1, TEST2, TEST13) 
        else 
        executeSQLQuery("UPDATE Avengers SET TEST1 = ?, TEST2 = ?, TEST3 = ? WHERE Account = ?", TEST1, TEST2, TEST3, account) 
    end 
end) 
  
addEventHandler ("onPlayerLogin", getRootElement(), 
function () 
    local account = getAccountName(source) 
    local searchForAPlayer = executeSQLQuery("SELECT TEST1, TEST2, TEST3 FROM Avengers WHERE Account = ?", account) 
    if #searchForAPlayer == 1 then 
        setElementData(source, "TEST1", searchForAPlayer["TEST1"]) 
        setElementData(source, "TEST2", searchForAPlayer["TEST2"]) 
        setElementData(source, "TEST3", searchForAPlayer["TEST3"]) 
    end 
end) 

Link to comment

Just use event parameter for get the account

addEventHandler ("onPlayerLogin", getRootElement(), 
function ( _, currentAccount ) 
    local account = getAccountName(currentAccount) 
    local searchForAPlayer = executeSQLQuery("SELECT TEST1, TEST2, TEST3 FROM Avengers WHERE Account = ?", account) 
    if #searchForAPlayer == 1 then 
        setElementData(source, "TEST1", searchForAPlayer["TEST1"]) 
        setElementData(source, "TEST2", searchForAPlayer["TEST2"]) 
        setElementData(source, "TEST3", searchForAPlayer["TEST3"]) 
    end 
end) 

Link to comment
Just use event parameter for get the account
addEventHandler ("onPlayerLogin", getRootElement(), 
function ( _, currentAccount ) 
    local account = getAccountName(currentAccount) 
    local searchForAPlayer = executeSQLQuery("SELECT TEST1, TEST2, TEST3 FROM Avengers WHERE Account = ?", account) 
    if #searchForAPlayer == 1 then 
        setElementData(source, "TEST1", searchForAPlayer["TEST1"]) 
        setElementData(source, "TEST2", searchForAPlayer["TEST2"]) 
        setElementData(source, "TEST3", searchForAPlayer["TEST3"]) 
    end 
end) 

i used this too but save or load not work :(

Link to comment
You first have to get the account with getPlayerAccount. Then use getAccountName to get the account name from the account you got with getPlayerAccount.

You can't use getAccountName with the player element because an account is required in that function.

Where?

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