Jump to content

Time: Check If Person Took Too Long


Chewett

Recommended Posts

  • Root Admin

[code]// first object

@vd = time();
// gets time in seconds and sets it to a variable
store(@vd);
// stores the variable into whever

-------------

// object two

retrieve(@vd);
// Gets the time we stored in object one
if((@vd + 10 * 60) < time() ){
// first it gets the first time, and adds 10 * 60 onto it (which is 10 minutes) then
// compares it with current time. If current time is bigger than the sum you calculated
// then it will be over the 10 minutes and it displays the apropiate text
echo "sorry you are too slow";
}else{
echo "you win the game!";
}[/code]

time() will retrive the current time (for more techincal people its actually a unix timestamp) Basicly in seconds from a certain event.
This is not easily readable by people as its returned in seconds but for this example its great.

NOTE: i dont have mdscript, nor will i ever since i dont quest, so this is all vague guessings from documentation and my knowledge of php.
I know php, so techincally it should work...

Any questions or if someone wants to test it, Go ahead

This is just an example, You will need to make sure that @vd is set already from the first object but i left that out as it clouds the example

Edited by Chewett
Link to comment
Share on other sites

uhmm... i know i'm not supposed to post here, but you have a little mistake there, you have @vh once where it should be @vd [at least i think so O_o]

and, i have a question there, too:
will that piece of code work for several players who are attempting at once?
or would the dead-line expire ten minutes after the first person activated the timer, and stay dead until i manually reset the timer?

i'm not much of a coder, so you'll have to put up with such newbish questions for some time... XD

Link to comment
Share on other sites

Nice code Chewett, but I think you mean @vh [b]+[/b] 10 * 60
Otherwise it would be checked in the next 6000 years or so :)

Burns, regarding the scope of the storage. It will work for each user seperately, we are waiting for multiple types to be supported. Also you're right about the @vh needing to be @vd.



This example performs the same logic checks as above and shows how to calculate the remaining time.
It gives the user 14 hours to save the world.

Object1:
[code]
@vz = "rendrilrevant-";//define key prefix
retrieve(@vt);//get timer data
//check if the player started the timer already
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
@vd = floor((@vt - time())/60 / 60);//get remaining time by subtracting current tiem from given time length
echo "You only have " . @vd . " hours to sa"."ve the earth!";
}
else
{
//calculate given tiem by adding 14 hours (50400 seconds) to current time
@vt = time() + (14 * 60 * 60);
//flag that timer has started
mds_give_rpcq_keys(@vz . "timer-started");
//store time value
store(@vt);
echo "You have 14 hours to sa"."ve the earth!<br />Run! Run like the wind!";
}
[/code]


Object2
[code]
@vz = "rendrilrevant-";//define key prefix
//check if timer was started yet
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
retrieve(@vt);////get timer data
//check if current time is less than or equal allowed time
if(time() <= (@vt))
{
//perform actions if successful
mds_give_rpcq_keys(@vz . "world-sav"."ed");
echo "Well done you sav"."ed the earth!<br />Now go to something con"."structive.";
}
else
{
//perform actions if not successful
mds_give_rpcq_keys(@vz . "world-not-sa"."ved");
echo "You were unable to sa"."ve the earth =(";
}
//clean up the timer key
mds_take_rpcq_keys(@vz . "timer-started");
}
[/code]

Edited by Rendril
Link to comment
Share on other sites

Strange, I just tested it and it works fine.
Here it is without comments, see if that helps:
[code]
@vz = "rendrilrevant-";
retrieve(@vt);
if(mds_has_rpcq_keys(@vz . "timer-started"))
{
@vd = floor((@vt - time())/60 / 60);
echo "You only have " . @vd . " hours to sa"."ve the earth!";
}
else
{
@vt = time() + (14 * 60 * 60);
mds_give_rpcq_keys(@vz . "timer-started");
store(@vt);
echo "You have 14 hours to sa"."ve the earth!<br />Run! Run like the wind!";
}
[/code]

Link to comment
Share on other sites

  • Root Admin

[quote name='Burns' date='29 October 2009 - 04:03 PM' timestamp='1256832209' post='46069']
uhmm... i know i'm not supposed to post here, but you have a little mistake there, you have @vh once where it should be @vd [at least i think so O_o]
[/quote]

Thanks Burns, i changed that

[quote name='Rendril' date='29 October 2009 - 04:16 PM' timestamp='1256833008' post='46070']
Nice code Chewett, but I think you mean @vh [b]+[/b] 10 * 60
Otherwise it would be checked in the next 6000 years or so :D
[/quote]

and perhaps i might want it to be checked within the next 6000 years :)

changed also, thanks

Did anyone test it? since i cant actually check as i have no access...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Forum Statistics

    17.5k
    Total Topics
    182.5k
    Total Posts
  • Recently Browsing

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
  • Recent Event Reviews

×
×
  • Create New...