Page 1 of 1

Sleep and no script...

Posted: Tue Jun 27, 2006 12:39 pm
by Poi
Ok im making a barter script, but i dont want people spamming non stop, and i tried putting in a sleepms(60000); at the end, but it doesnt work, how do you make it so it waits a certain amount of time befor they can run that script again?

Posted: Tue Jun 27, 2006 2:07 pm
by tekproxy
That sleep statement will just cause it to sleep before ending the script, but it will not prevent someone from starting a new instance of the script.

One way to prevent them from doing it again would be to set a cprop on them storing the last time they ran the script and check/compare the stored cprop on the player with the current time. So, for example:

Code: Select all

use uo;
use os;

CONST WAIT_TIME := 60; // must wait 60 seconds

program Barter(mobile)
	var last_barter := CInt(GetObjProperty(mobile, "#LastBarter"));
	
	// If last_barter was set, and the difference between then and now is less than WAIT_TIME, fail with a message
	if ( last_barter  && (Polcore().systime - last_barter) < WAIT_TIME )
		SendSysMessage(mobile, "You must wait at least "+WAIT_TIME+" seconds before bartering again.");
		return 0;
	else
		// Set #LastBarter prop on moible
		// the "#" will tell POL to not save this prop
		// when the server restarts, the prop is gone
		SetObjProperty(mobile, "#LastBarter", Polcore().systime);
	endif
	
	// Do barter stuff here
endprogram
Something like that...

Posted: Tue Jun 27, 2006 5:05 pm
by Poi
Thanks ill try