Page 1 of 1

Countdown

Posted: Tue Nov 01, 2011 1:09 am
by Huezzer
Hey, do anyone know if it's possible to add a "count down" to each thing, like it's only possible to accept a quest every 15min. etc?

*Cooldown

Example 2: If you go into the "Inn" it restores all your health but it's only possible to visit the inn to get full health every hour.. etc.

Anyone know?, Please tell me
That also include if it's possible to make the system update every 10 sec. or something.

Thank you,

Huezzer

Re: Countdown

Posted: Tue Nov 01, 2011 6:02 am
by Gustava
You can save a time stamp for when the action occurred and then compare it to the current time stamp when they try again - if it's after the allotted time then let them do whatever, etc.

Believe hall's has a game with something like this..urban realms?


Are you wanting the system to update every 10 seconds for the count down timer? If that, using a time stamp check on say when they visit the inn page would be a lot more efficient like I described up top. But you could have it update 10 seconds if needed, but usually more simple and better ways to solve things 8-)

Re: Countdown

Posted: Tue Nov 01, 2011 5:07 pm
by Ark
Well I think you could use cronjobs to run a script every x mins. I think halls made a video showing how to use them. But I guess it got a limit for 10min minimum.

Re: Countdown

Posted: Tue Nov 01, 2011 5:28 pm
by Chris
http://php.net/time

Code: Select all

function doAction()
{
    // done action
    echo "Did action at " . time();
    // update player action time
    mysql_query("UPDATE `users` SET `action_timestamp` = '" . time() .  "'");
}

function allowedToDoAction()
{
    global $userArray;
    $seconds = 60; // 1 minute
    $actionAllowedTime = $userArray['action_timestamp'] + $seconds; // 1 minute

    return $actionAllowedTime < time();
}

$userQuery = mysql_query("SELECT * FROM `users` WHERE `id` = '" . (int)$_SESSION['user_id'] . "'");
$userArray = mysql_fetch_assoc($userQuery);

if( allowedToDoAction() )
{
    doAction();
}
else
{
    echo "Not allowed to do action";
}
 

Re: Countdown

Posted: Thu Nov 03, 2011 8:19 pm
by hallsofvallhalla
Chris rocks....Plain and simple.

Re: Countdown

Posted: Fri Nov 04, 2011 5:25 pm
by Andrew
Hey, Thank you! But I only got one question about this code:

Code: Select all

function doAction()
{
    // done action
    echo "Did action at " . time();
    // update player action time
    mysql_query("UPDATE `users` SET `action_timestamp` = '" . time() .  "'");
}

function allowedToDoAction()
{
    global $userArray;
    $seconds = 60; // 1 minute
    $actionAllowedTime = $userArray['action_timestamp'] + $seconds; // 1 minute

    return $actionAllowedTime < time();
}

$userQuery = mysql_query("SELECT * FROM `users` WHERE `id` = '" . (int)$_SESSION['user_id'] . "'");
$userArray = mysql_fetch_assoc($userQuery);

if( allowedToDoAction() )
{
    doAction();
}
else
{
    echo "Not allowed to do action";
}
 
How do I know how to use it?, I mean where I need to put it in?, in a code like Inn.php

Don't know if you know what I mean but I mean when I want the "countdown" to be when I go into the inn.php in-game, like 3h countdown to next time until I can "rest" their again.

By the way: I've got players, and id, how can I change the it to halls settings?

Thanks, Andrew