=KoG=Rouche Posted May 6, 2014 Share Posted May 6, 2014 (edited) Hi all, I'm trying to save "lastSeen" in a mysql table called "DM". I got some issue. rootElement = getRootElement() ... function realTime() local lastSeen = getRealTime() -- It returns a tab end addEventHandler("onPlayerQuit",rootElement,realTime) -- Later in my code dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..time..":""','0','0','0','0','0','"..account.."')") ... It's not working :-/ How to save an answer from getRealTime() in my DB ? Edited May 7, 2014 by Guest Link to comment
Gallardo9944 Posted May 6, 2014 Share Posted May 6, 2014 You are not able to save mta tables into mysql. You should save that as a text (you might wanna use a JSON format tho) Link to comment
Karuzo Posted May 6, 2014 Share Posted May 6, 2014 (edited) Maybe like this? local hours,minutes rootElement = getRootElement() ... function realTime() local time = getRealTime() hours = time.hour minutes = time.minute end addEventHandler("onPlayerQuit",rootElement,realTime) -- Later in my code dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..hours..":"..minutes.."','0','0','0','0','0','"..account.."')") ... Edited May 6, 2014 by Guest Link to comment
MIKI785 Posted May 6, 2014 Share Posted May 6, 2014 Maybe like this? rootElement = getRootElement() ... function realTime() local time = getRealTime() local hours = time.hour local minutes = time.minute end addEventHandler("onPlayerQuit",rootElement,realTime) -- Later in my code dbExec(connect,"INSERT INTO DM (lastSeen,timePlayed,cash,moneyUse,moneyWon,timeJoin,toPlayer) VALUES ('"..hours..":"..minutes.."','0','0','0','0','0','"..account.."')") ... That wouldn't work because variables hours and minutes are local in realTime function. You would have to make the realTime function return those values. Link to comment
Karuzo Posted May 6, 2014 Share Posted May 6, 2014 Ah, sorry, wrote it fast and didn't noticed it actually. Link to comment
=KoG=Rouche Posted May 7, 2014 Author Share Posted May 7, 2014 (edited) Ok thanks. But now i try to set a variable with a string. rootElement = getRootElement() ------ Functions -------- -- Return the real time (TO BE TESTED) function realTime() local time = getRealTime() day = fromJSON(time.monthday) month = fromJSON(time.month) year = fromJSON(time.year + 100) hours = fromJSON(time.hour) minutes = fromJSON(time.minute) lastSeen = "Lastseen : "..toString(day).."/"..toString(month).."/"..toString(year).." - "..toString(hours)..":"..toString(minutes).."" end addEventHandler("onResourceStart",rootElement,realTime) outputDebugString(lastSeen) It doesn't work :-/ Edited May 7, 2014 by Guest Link to comment
Gallardo9944 Posted May 7, 2014 Share Posted May 7, 2014 Of course it will not work. onResourceStart (if we speak about current resource) runs AFTER everything outside it. So outputDebugString should be inside the realTime function. Link to comment
=KoG=Rouche Posted May 7, 2014 Author Share Posted May 7, 2014 Thanks for your help. -- Return the real time function realTime() local time = getRealTime() local day = time.monthday local month = time.month local year = time.year +1900 local hours = time.hour +1 local minutes = time.minute +1 local lastSeen = "Lastseen : "..day.."/"..month.."/"..year.." - "..hours..":"..minutes.."" return lastSeen end addEvent("onPlayerQuiUpdateLastSeen",true) addEventHandler("onPlayerQuitUpdateLastSeen",rootElement,realTime) 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