Jump to content

I have a problem w/ a script using a database.


TheDZetko

Recommended Posts

Hello all,

I have a problem with my script which is using a local SQLite database (internal.db file in MTA San Andreas 1.4\server\mods\deathmatch). The server.lua looks like this:

function onResourceStart() 
    executeSQLCreateTable("accounts", "id INTEGER, name TEXT, password TEXT, ip TEXT, serial TEXT, cash INTEGER") 
end 
addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), onResourceStart) 
  
function plrSetCash() 
    sourcename = getPlayerName (source) 
  
    result = executeSQLSelect ("accounts", "*", "name = '" .. sourcename .. "'" ) 
    outputChatBox ("Ok") 
    if (type(result) == "table" and result[1].cash == 0) or not result then 
        outputChatBox ("This is your first time here. You don't have any cash. Welcome " .. sourcename .. "!", source) 
    else 
        outputChatBox ("Welcome back " .. sourcename .. "!", source ) 
        executeSQLUpdate ( "accounts", "cash = cash + 100" ) 
    end 
  
    result = executeSQLSelect ("accounts", "id", "name", "password", "ip", "serial", "cash" ) 
    outputChatBox ("Your ammount of money is: " .. result[1].cash ) 
end 
addEventHandler ("onPlayerSpawn", getRootElement(), plrSetCash) 

Everytime I connect to my server, it says this error - ERROR: plrcashshowmsgonstart\server.lua:19: attempt to index field '?' (a nil value) - in the console.

The user is in the database, but the error above is still showing up.

Where is the problem?

And question #2 - Do I need a client.lua file for this type of script?

Please help.

Thank you all, TheDZetko

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