Lukkaz Posted January 14, 2011 Share Posted January 14, 2011 (edited) Hi everyone I'm sorry I have been posting a lot of questions lately mostly things with stupid quick fixes that I over look but this will be my final question, I have created a jail script where time is saved in mySQL, however how can I get the time in mySQL to count down until the persons time is up? function update(player) local characterID = exports.players:getCharacterID( player ) if characterID then local result = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID ="..characterID ) for key, value in ipairs( result ) do local time = value.jailTime if (time>=1) then exports.sql:query_insertid( "INSERT INTO characters (jailTime) VALUES (" ..time .. ")") end end end end function onResourceStart(thisResource) setTimer ( update, 600, 0 ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStart ) local root = getRootElement() addEventHandler("onPlayerLogin", root, function() local characterID = exports.players:getCharacterID( source ) if characterID then local time = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) if ( time ) and type( time ) == "number" then if ( time>=1 ) then local time = tonumber(time) setTimer(timers, time*60000, 1, source) end else outputDebugString("time isn;t a number?") end outputDebugString("cant find characterid") end end ) addCommandHandler( "jailtime", function ( player, commandName ) if exports.players:isLoggedIn( player ) then local characterID = exports.players:getCharacterID( player ) if characterID then local result = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) for key, value in ipairs( result ) do local time = value.jailTime if ( time >=1 ) then outputChatBox ( "Your jailtime is "..time.." minute(s).", player, 0, 255, 0 ) setTimer ( update, 600, 0, player ) else outputDebugString("its not working it cant be compared") end end else end end end ) function timers(other) local characterID = exports.players:getCharacterID( other ) if characterID then local result = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) for key, value in ipairs( result ) do local time = value.jailTime if ( time == 0 ) then setElementPosition(other, 2290, 2423.4, 10.8 ) setElementInterior (other, 0 ) outputChatBox( "Your time has been served, stay out of trouble.", other, 0, 255, 0 ) setElementDimension(other, 0 ) end end end end What's the best way to do this I will do whatever for the person who can help me out me and my team are stumped Edited January 14, 2011 by Guest Link to comment
12p Posted January 14, 2011 Share Posted January 14, 2011 setTimer (unjailFunction, theSQLTime,1 ) Link to comment
12p Posted January 14, 2011 Share Posted January 14, 2011 When you jail it, you must run that line. If the player leaves, use getTimerDetails Store the first value in SQL. When the player enters, check the name, jail him if needed, then use again the setTimer function. Link to comment
Lukkaz Posted January 14, 2011 Author Share Posted January 14, 2011 sooo this would work? setTimer (timers, ..time..,1,other? ) Link to comment
12p Posted January 14, 2011 Share Posted January 14, 2011 if "timers" means the unjailing function then yes. Link to comment
Lukkaz Posted January 14, 2011 Author Share Posted January 14, 2011 okay bare with me I am unable to test atm but local root = getRootElement() addEventHandler("onPlayerLogin", root, function() local characterID = exports.players:getCharacterID( source ) if characterID then local time = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) if ( time ) and type( time ) == "number" then if ( time>=1 ) then local time = tonumber(time) setTimer(timers, time*60000, 1, source) ----I set timer for the unjail script but how does it go into mysql end else outputDebugString("time isn;t a number?") end outputDebugString("cant find characterid") end end ) addCommandHandler( "jailtime", function ( player, commandName ) if exports.players:isLoggedIn( player ) then local characterID = exports.players:getCharacterID( player ) if characterID then local result = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) for key, value in ipairs( result ) do local time = value.jailTime if ( time >=1 ) then getTimerDetails(timers) ---------get the details of the unjail script outputChatBox ( "Your jailtime is "..time.." minute(s).", player, 0, 255, 0 ) ----but how do I log it into mysql? else end end else end end end ) function timers(other) -----unjail script local characterID = exports.players:getCharacterID( other ) if characterID then local result = exports.sql:query_assoc( "SELECT jailTime FROM characters WHERE characterID = "..characterID ) for key, value in ipairs( result ) do local time = value.jailTime if ( time == 0 ) then -----if the timer countde down to 0 then release the player setElementPosition(other, 2290, 2423.4, 10.8 ) setElementInterior (other, 0 ) outputChatBox( "Your time has been served, stay out of trouble.", other, 0, 255, 0 ) setElementDimension(other, 0 ) end end end end Link to comment
Castillo Posted January 14, 2011 Share Posted January 14, 2011 You just wait 1 hour and think someone will answer? Be patient!! Link to comment
Lukkaz Posted January 14, 2011 Author Share Posted January 14, 2011 lol sorry I only have so much time Link to comment
SDK Posted January 15, 2011 Share Posted January 15, 2011 I did not check your code very well but this is what you should do. After jailing/logging in you put up a timer that runs a function each second. That function will do two things: if the jailtime is higher then 0, you update in sql the time value minus 1 second and the timer continues if the jailtime is lower then 1, you unjail the player and stop the timer Link to comment
Lukkaz Posted January 15, 2011 Author Share Posted January 15, 2011 Yeah that's what my code is attempting to do...lol but how do I go about doing it?? Link to comment
Scooby Posted January 16, 2011 Share Posted January 16, 2011 might sound an odd question but why do u want to store the jail time remainding in an sql table? is there some reason why u dont use a variable? Link to comment
Lukkaz Posted January 16, 2011 Author Share Posted January 16, 2011 well that's what I originally had but when people get jailed they log out and log back in and when they do the timers lost so they will sit there until someone remembers to release them just a lot easier if I can save it so when they disconnect it pauses the timer and when they come back it'll pick up where it left off Link to comment
Scooby Posted January 16, 2011 Share Posted January 16, 2011 Dont clear the timer as they leave then. Theres a few ways you can do it where the timer doesnt clear as they leave, using their name or ip. I think the max jail time on my server is 60 seconds, that seems a very long time when ur stuck in a jail cell with nothing to do. Link to comment
Lukkaz Posted January 16, 2011 Author Share Posted January 16, 2011 I try but the bug I'm trying to squash is it'll say you have 1 minute left but the timers frozen and won't count down that last minute if you could read my code and help me pick out what's sketchy and could cause it not to work I'd hiiiighly appreciate it I been at it for days rearranging how to save the time and then start it when they connect Link to comment
Lukkaz Posted January 19, 2011 Author Share Posted January 19, 2011 bump come on guys this is the last thing I am struggling on 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