Perfect Posted April 25, 2014 Share Posted April 25, 2014 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
tosfera Posted April 25, 2014 Share Posted April 25, 2014 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
Perfect Posted April 25, 2014 Author Share Posted April 25, 2014 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
Karuzo Posted April 25, 2014 Share Posted April 25, 2014 dbConnect("sqlite",file.db") This will create a file called file.db if it doesn'te xist. And what are you trying to do with that code? Link to comment
Perfect Posted April 25, 2014 Author Share Posted April 25, 2014 Well, I wanted give player money from table named 'players' and then save back again in table players in column named 'money'. Link to comment
Perfect Posted April 25, 2014 Author Share Posted April 25, 2014 This might help. SQL With Lua Link to comment
Karuzo Posted April 25, 2014 Share Posted April 25, 2014 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. Link to comment
Perfect Posted April 25, 2014 Author Share Posted April 25, 2014 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
TAPL Posted April 25, 2014 Share Posted April 25, 2014 https://forum.multitheftauto.com/viewtopic.php?f=148&t=38203#p393074 You can find some code here: https://forum.multitheftauto.com/viewtopic.php?f=91&t=74479 Link to comment
Perfect Posted April 25, 2014 Author Share Posted April 25, 2014 https://forum.multitheftauto.com/viewtopic.php?f=148&t=38203#p393074You can find some code here: https://forum.multitheftauto.com/viewtopic.php?f=91&t=74479 I already read JR10 Post but it didn't solve all my confusion, thats why i came here. But your second thread did a good job, Thank You So Much. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now