Jump to content

[Help] SQL With Lua.


Perfect

Recommended Posts

Hello, Recently I decided to learn SQLITE as i was running from it for many months.

I don't know how to connect lua with SQLITE.

Please tell me how to connect lua with SQLITE.

And If you can Please provide a simple example like storing player money etc....

Link to comment

well, everything can be found here; https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery

here is a simple query to store money, not receiving it!

addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource() ), 
    function () 
        executeSQLQuery ( "CREATE TABLE IF NOT EXISTS players (id INT, name TEXT, money INT)") 
    end 
); 
  
addCommandHandler ( "givemehmuniess", 
    function ( thePlayer ) 
        givePlayerMoney ( 200 ); 
        executeSQLQuery ( "INSERT INTO `players`(`name`,`money`) VALUES(?,?)", getPlayerName ( thePlayer ), getPlayerMoney ( thePlayer ) ); 
    end 
); 
  

Link to comment

Oh well, Thank you, i guess i understand something but with little confusion.

Can you Please tell me Where the table will create ? or it will create file.db in same resource and create table there ? How to create file.db ?

and this will work ? if negative then why ?

addEventHandler ( "onPlayerQuit", root, 
function () 
executeSQLQuery("SELECT money FROM players WHERE name=?", source) 
local nmoney = setPlayerMoney(source,players.money+100) 
executeSQLQuery("UPDATE players SET 'money' =? WHERE 'name'=?",nmoney,source) 
end) 
  

Link to comment
You should learn the basics of SQL to start with mysql in lua.

B2T:

You need to have smth like a id/name in your database of your player to save the money to the specific player.

I'll write you smth when i got home.

Well, I mean i have learnt some basics of SQL and now wanna try them with lua.

Waiting for your post.

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