Worlds of Carnage
https://www.wocmud.org/forum/

Constricting mob "hello" to only one.
https://www.wocmud.org/forum/viewtopic.php?f=23&t=120
Page 1 of 1

Author:  Blobbie [ Sun Jul 17, 2005 8:17:54pm ]
Post subject:  Constricting mob "hello" to only one.

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".

Author:  Grael [ Sun Jul 17, 2005 8:35:44pm ]
Post subject: 

That's neat Blobbie.

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

Author:  Kayenta [ Sun Jul 17, 2005 11:20:44pm ]
Post subject: 

glad someone does :wink: Imma have to learn how to decipher that arent I???? :?

Author:  Blobbie [ Sun Jul 17, 2005 11:58:05pm ]
Post subject: 

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 :)

Author:  Kayenta [ Mon Jul 18, 2005 7:04:25am ]
Post subject: 

Something to look foward to then =)

cheers

Author:  Grael [ Mon Jul 18, 2005 7:51:30am ]
Post subject: 

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.

Page 1 of 1 All times are UTC-04:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/