Countdown

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
Huezzer
Posts: 72
Joined: Mon Jan 31, 2011 7:47 pm

Countdown

Post 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
Gustava
Posts: 66
Joined: Tue Dec 29, 2009 5:49 am

Re: Countdown

Post 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-)
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Countdown

Post 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.
Orgullo Catracho
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Countdown

Post 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";
}
 
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Countdown

Post by hallsofvallhalla »

Chris rocks....Plain and simple.
Andrew
Posts: 16
Joined: Mon Aug 15, 2011 12:57 pm

Re: Countdown

Post 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
Post Reply

Return to “Advanced Help and Support”