Jump to content

Stopping a query for 5 seconds.


seany123

Recommended Posts

im currently developing a text based game but ive hit a bit of a problem.

 

when players mug eachother they can just keep hitting F5 and mug (until they run out of energy etc)

 

but instead i would like it so after they mugged they then cant mug again for 5 seconds!

 

is there anyway this could be easily done?

 

an idea of how i could do it was maybe creating a value in their player table called last mug and it would be a time.... then i could try summert like if last mug <= 5 seconds from now then blah.... but im not too sure.

Link to comment
https://forums.phpfreaks.com/topic/190148-stopping-a-query-for-5-seconds/
Share on other sites

an easier method would be to use a SESSION variable containing the timestamp of their last mugging. then check the current time against that value before processing anything on the page:

 

if (!isset($_SESSION['last_mugging']) || time() - $_SESSION['last_mugging'] > 5)
{
  // do the mugging stuff
  $_SESSION['last_mugging'] = time();
}

 

using the table is unnecessary for such a short timeframe. if we were talking hours, then it would make sense (as the user could simply close their browser and establish a new session), but it would take them longer than 5 seconds to do it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.