Worlds of Carnage
It is currently Tue Apr 16, 2024 1:12:10am

All times are UTC-04:00




Post new topic  Reply to topic  [ 6 posts ] 


 Post subject: Constricting mob "hello" to only one.
PostPosted: Sun Jul 17, 2005 8:17:54pm 
User avatar
Implementor
Joined: Fri Oct 06, 2000 5:32:29pm
Posts: 288
Website: http://www.wocmud.org
Location: Ottawa, Canada
Offline
Let's say you want a guard to say hello everytime someone enters the room. But you have 3 guards with the same vnum, and a group of 4 players just walked in... that's 12 "hello"s. which is probably 11 more than you want. Ever wonder how to make it only happen once? Check out the following code:
Code:
Trigger type: catch_entry_act protect { static @alreadyRunning if( %contextIsValid( @alreadyRunning ) ) { // // This script is already running. // return } endif #@alreadyRunning = %contextGetId() wait 0 secs say Welcome... TO YOUR DOOM! hit @n }
How it works... A static var is shared by all instances of the script and is never deleted. So everytime the script is run the variable @alreadyRunning contains the last assigned value. In this case we assign the value of %contextGetId(). This is a unique ID assigned to a script when it is started. Using %contextIsValid() we can determine if a context ID is valid (the script is currently running). If it is valid then we know another script is already handling the "hello" and so we just exit the script since there's nothing to do. The "wait 0" line is also very important, because our script is encased in "protect/endprotect" then the script is guaranteed to run till it hits the endprotect statement without any other script running, however, if that happens then the script will finish and the next script will find that there is no valid running script, so wait 0 says, pass control back to the script engine for now, and that will allow all the other scripts trying to run to see that a script is already handling "hello".


Last edited by Blobbie on Mon Jul 18, 2005 12:36:58pm, edited 1 time in total.

Top
   

 Post subject:
PostPosted: Sun Jul 17, 2005 8:35:44pm 
Joined: Sun Apr 16, 2006 9:12:10pm
Posts: 2
Offline
That's neat Blobbie.

What's frightening is that I actually understand all of that.


Top
   

 Post subject:
PostPosted: Sun Jul 17, 2005 11:20:44pm 
User avatar
Joined: Sat Dec 25, 2004 1:14:21pm
Posts: 157
Website: http://photobucket.com/albums/y216/Kinara/
Offline
glad someone does :wink: Imma have to learn how to decipher that arent I???? :?


Top
   

 Post subject:
PostPosted: Sun Jul 17, 2005 11:58:05pm 
User avatar
Implementor
Joined: Fri Oct 06, 2000 5:32:29pm
Posts: 288
Website: http://www.wocmud.org
Location: Ottawa, Canada
Offline
Quote:
glad someone does :wink: Imma have to learn how to decipher that arent I???? :?
Nah not really, it's not something many builders need. Areas can be done that conform to the very simplest of scripted mechanics. But once you start wanting "special" or "cool" features, then you often start wandering into the complexity mess :)


Top
   

 Post subject:
PostPosted: Mon Jul 18, 2005 7:04:25am 
User avatar
Joined: Sat Dec 25, 2004 1:14:21pm
Posts: 157
Website: http://photobucket.com/albums/y216/Kinara/
Offline
Something to look foward to then =)

cheers


Top
   

 Post subject:
PostPosted: Mon Jul 18, 2005 7:51:30am 
Joined: Sun Apr 16, 2006 9:12:10pm
Posts: 2
Offline
Quote:
Something to look foward to then =)

cheers
I've found that if I can dream it up, the functionality in BlobbieScript is either there already, or Blobbie can make it happen.

Dream away, and it can happen.


Top
   

Display posts from previous:  Sort by  

Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC-04:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group