Root Admin Chewett Posted October 29, 2009 Root Admin Report Posted October 29, 2009 (edited) [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 October 29, 2009 by Chewett Muratus del Mur 1 Quote
Burns Posted October 29, 2009 Report Posted October 29, 2009 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 Quote
Rendril Posted October 29, 2009 Report Posted October 29, 2009 (edited) 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 October 29, 2009 by Rendril Brulant and Muratus del Mur 1 1 Quote
I am Bored Posted October 29, 2009 Report Posted October 29, 2009 hmmmm... could you also post a version of it ready to go into the items? because currently rendril i can't get the first code to work.... i removed the comments.... and it says unexpected end on line 15, which is this: echo "You have 14 hours to sa"."ve the earth!<br />Run Quote
Rendril Posted October 29, 2009 Report Posted October 29, 2009 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] Quote
Root Admin Chewett Posted October 29, 2009 Author Root Admin Report Posted October 29, 2009 [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 [/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... Quote
I am Bored Posted October 30, 2009 Report Posted October 30, 2009 here i'll test it, i will edit this when i have...... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.