an4rei Posted January 7, 2015 Posted January 7, 2015 (edited) Hello , I need some help with next thing: Here is an example: function reward() --gets the player's serial and searches the mysql table for it --if the serial exists in mysql table , will outputchatbox something --if the serial doesn't exists in mysql table will do something like GivePlayerMoney + adds the serial in the mysql table addCommandHandler("gift" , reward) I hope you have understood what I want to make , 1 use command for each player. Thanks. Edited January 7, 2015 by Guest MTA:Rust Pre-Alpha Build v.0.1: https://forum.mtasa.com/viewtopic.php?f=114&t=97848
Gallardo9944 Posted January 7, 2015 Posted January 7, 2015 (edited) Untested, but should somewhat show you how it works function reward(player) --gets the player's serial and searches the mysql table for it local serial = getPlayerSerial(player) local query = dbQuery(handler,"SELECT serial FROM rewardtable WHERE serial=?",serial) -- handler is your mysql connection with dbConnect. Might be a bit different with your table local data = dbPoll(query,-1) -- query the results to get the actual serial dbFree(query) local info = data[1] -- get the first result if info and info["serial"] then -- if there is at least 1 result with this serial -- will outputchatbox something outputChatBox("Yo man! You already got the gift!",player,255,255,255,true) else --if the serial doesn't exists in mysql table will do something like GivePlayerMoney + adds the serial in the mysql table dbExec(handler,"INSERT INTO rewardtable (serial,playerName) VALUES (?,?)",serial,getPlayerName(player)) -- execute to insert into the table. The query can be a bit different depending on your database. Added playerName example in case you need it givePlayerMoney(player,10000) -- give the cash outputChatBox("Shut up and take my money!",player,255,255,255,true) end end addCommandHandler("gift",reward) Edited January 7, 2015 by Guest Code Debugger - Minimalistic MTA debug line replacement
Mizudori Posted January 7, 2015 Posted January 7, 2015 local cn = dbConnect ( string databaseType, string host [, string username = "", string password = "", string options = "" ] ) function give_r(pl ) local theSerial = getPlayerSerial(pl) local qh = dbQuery( cn, "SELECT * FROM users WHERE player_serial=?",theSerial ) local result, rows, last_insert_id = dbPoll ( qh, -1 ) if(result)then if(rows > 0)then --if the serial exists in mysql table , will outputchatbox something else dbExec(cn,"INSERT INTO users (player_serial) VALUES (?)",theSerial) --if the serial doesn't exists in mysql table will do something like GivePlayerMoney + adds the serial in the mysql table end end end addCommandHandler( "reward", give_r )
an4rei Posted January 7, 2015 Author Posted January 7, 2015 Thank you both , I've used first example and it worked. Untested, but should somewhat show you how it works function reward(player) --gets the player's serial and searches the mysql table for it local serial = getPlayerSerial(player) local query = dbQuery(handler,"SELECT serial FROM rewardtable WHERE serial=?",serial) -- handler is your mysql connection with dbConnect. Might be a bit different with your table local data = dbPoll(query,-1) -- query the results to get the actual serial dbFree(query) local info = data[1] -- get the first result if info and info["serial"] then -- if there is at least 1 result with this serial -- will outputchatbox something outputChatBox("Yo man! You already got the gift!",player,255,255,255,true) else --if the serial doesn't exists in mysql table will do something like GivePlayerMoney + adds the serial in the mysql table dbExec(handler,"INSERT INTO rewardtable (serial,playerName) VALUES (?,?)",serial,getPlayerName(player)) -- execute to insert into the table. The query can be a bit different depending on your database. Added playerName example in case you need it givePlayerMoney(player,10000) -- give the cash outputChatBox("Shut up and take my money!",player,255,255,255,true) end end addCommandHandler("gift",reward) MTA:Rust Pre-Alpha Build v.0.1: https://forum.mtasa.com/viewtopic.php?f=114&t=97848
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