Jump to content

problem sql


WASSIm.

Recommended Posts

Posted

hi guys i have problem

why it not working ?

addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),function() 
    executeSQLQuery("CREATE TABLE IF NOT EXISTS Save_Money_Account (Account,Money)") 
    outputDebugString("Sql Save Money loaded .",3) 
end) 
  
  
addEventHandler("onPlayerQuit",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Account SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Account(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
end) 
  
addEventHandler("onPlayerLogout",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Account SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Account(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
    setPlayerMoney(source,0) 
end) 
  
addEventHandler("onPlayerLogin",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        RowAccount = RowAccount[1]["Money"] 
        setPlayerMoney(source,tonumber(RowAccount)) 
    else 
        return false 
    end 
end) 

Omerta Roleplay

Posted

It's hassan.k.s.a code,

تقدر تستخدم xml

لاكن هذا مثال على

sql حفظ الفلوس بـ

addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),function() 
    executeSQLQuery("CREATE TABLE IF NOT EXISTS Save_Money_Hassan (Account,Money)") 
end) 
  
addEventHandler("onPlayerQuit",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Hassan SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Hassan(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
end) 
  
addEventHandler("onPlayerLogout",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Hassan SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Hassan(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
    setPlayerMoney(source,0) 
end) 
  
addEventHandler("onPlayerLogin",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        local RowAccount = RowAccount[1]["Money"] 
        setPlayerMoney(source,tonumber(RowAccount)) 
    end 
end) 

and it's wrong lol :lol: .

Sha67 سابقاً

Posted
It's hassan.k.s.a code,
تقدر تستخدم xml

لاكن هذا مثال على

sql حفظ الفلوس بـ

addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),function() 
    executeSQLQuery("CREATE TABLE IF NOT EXISTS Save_Money_Hassan (Account,Money)") 
end) 
  
addEventHandler("onPlayerQuit",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Hassan SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Hassan(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
end) 
  
addEventHandler("onPlayerLogout",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        executeSQLQuery("UPDATE Save_Money_Hassan SET Money=? WHERE Account=?",tostring(Money),tostring(Account)) 
    else 
        executeSQLQuery("INSERT INTO Save_Money_Hassan(Account,Money) VALUES(?,?)",tostring(Account),tostring(Money)) 
    end 
    setPlayerMoney(source,0) 
end) 
  
addEventHandler("onPlayerLogin",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Hassan WHERE Account = '"..tostring(Account).."'") 
    if not  ( #RowAccount == 0 )   then 
        local RowAccount = RowAccount[1]["Money"] 
        setPlayerMoney(source,tonumber(RowAccount)) 
    end 
end) 

and it's wrong lol :lol: .

yeah he is give me it

Omerta Roleplay

  • Moderators
Posted

no proof needed, he is a known stealer.

Wasted my time a several times,

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

it's wrong lol :lol: .

it's not wrong , it's working .

but the problem with server WASSIm., not the problem of the code .

but test this :

    addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),function() 
        executeSQLQuery("CREATE TABLE IF NOT EXISTS Save_Money_Account (Account,Money)") 
        outputDebugString("Sql Save Money loaded .",3) 
    end) 
      
      
addEventHandler("onPlayerQuit",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if ( type(RowAccount) == "table" and #RowAccount == 0 or not RowAccount) then 
        executeSQLQuery("INSERT INTO Save_Money_Account(Account,Money) VALUES(?,?)",tostring(Account),tonumber(Money)) 
    else 
        executeSQLQuery("UPDATE Save_Money_Account SET Money=? WHERE Account=?",tonumber(Money),tostring(Account)) 
    end 
end) 
      
addEventHandler("onPlayerLogout",getRootElement(),function() 
    local Account = getAccountName(getPlayerAccount(source)) 
    local Money = getPlayerMoney(source) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if ( type(RowAccount) == "table" and #RowAccount == 0 or not RowAccount ) then 
        executeSQLQuery("INSERT INTO Save_Money_Account(Account,Money) VALUES(?,?)",tostring(Account),tonumber(Money)) 
    else 
        executeSQLQuery("UPDATE Save_Money_Account SET Money=? WHERE Account=?",tonumber(Money),tostring(Account)) 
    end 
    setPlayerMoney(source,0) 
end) 
      
addEventHandler("onPlayerLogin",getRootElement(),function(_,acc) 
    local Account = getAccountName(acc) 
    local RowAccount = executeSQLQuery("SELECT * FROM Save_Money_Account WHERE Account = '"..tostring(Account).."'") 
    if ( type(RowAccount) == "table" and #RowAccount == 0 or not RowAccount ) then 
        return 
    end 
    setPlayerMoney(source,tonumber(RowAccount[1]["Money"])) 
end) 

Posted

Means that the table is not being created.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

i edite it but not working

   addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()),function() 
        executeSQLQuery("CREATE TABLE IF NOT EXISTS Save_Money_Account (Account TEXT,Money TEXT)") 
        outputDebugString("Sql Save Money loaded .",3) 
    end) 

Omerta Roleplay

Posted
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        local result = executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Save_Money_Account (Account TEXT,Money TEXT)" ) 
        outputChatBox ( "QUERY RESULT: ".. tostring ( result ) ) 
        outputDebugString ( "Sql Save Money loaded .", 3 ) 
    end 
) 

Try that and see what it outputs to chatbox.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I've tested the code and the table was created.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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