|
geosmith Wanderer
Joined: 23 Apr 2005 Posts: 57
|
Posted: Fri Dec 29, 2006 11:51 am
Preventing multiple instances of a script. |
I'm mudding on Imperian at the moment, which, like other Iron Realms MUDs (Achaea, Aetolia, Lusternia), uses a system of afflictions, cures and balances for combat. An example of this would be drinking an elixir of health... this can only be done intermittently (approximately every five seconds), and there are numerous afflictions which prevent this from happening (being stunned, for example).
With this in mind, I've tried out a number of scripts to automate the various forms of curing, each with varying degrees of success. For example, here is my current healing script (triggered from the prompt whenever my character's health drops below a certain point):
#FO @preventhealth {#IF %ismember(%i,@currentafflictions) {#ABORT 1}}
#IF (@healthbalance=1 and @healthsips>0) {drink health}
In the above, the variable 'preventhealth' is a string list of afflictions which would prevent drinking health elixir, whilst 'healthbalance' keeps track of the delay in being able to do so, and 'healthsips' is simply a measure of the amount of elixir remaining.
For the most part, this works fine... however, I find myself running into problems when two or more instances of such scripts are triggered to run either in extremely rapid succession, or at exactly the same time (less likely in the above, but certainly possible when two or more afflictions are gained at the same time).
I'd appreciate suggestions as to any ways I might improve the above, and in particular I'm looking for a way to ensure that only one instance of a script can run at one time, even when two triggers for this script are received at the same time. |
|
|
|
Boes Newbie
Joined: 26 Dec 2006 Posts: 5
|
Posted: Fri Dec 29, 2006 2:43 pm |
what you can do is put all the scripts that could trigger off of a given set of afflicitions in a subclass, then
Whatever the trigger needs to send here;#T- YourSubClass;#alarm "AfflictionTimer" +0:0:3 {#T+ YourSubclass}
that will turn the trigger off so it can't double fire, then turn it back on. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Fri Dec 29, 2006 11:48 pm |
First you are going to have to get rid of the use of #ABORT 1 and the use of #FORALL. I would suggest using an #IF with either the %regex or %match functions. Something along the lines of:
#IF (%match(@currentafflictions,@preventhealth)=0) {
#IF (@healthbalance=1 and @healthsips>0) {drink health}
}
This would involve a small change in your preventhealth variable in order to make it into a proper pattern. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
geosmith Wanderer
Joined: 23 Apr 2005 Posts: 57
|
Posted: Sat Dec 30, 2006 5:56 am |
Vijilante wrote: |
First you are going to have to get rid of the use of #ABORT 1 and the use of #FORALL. I would suggest using an #IF with either the %regex or %match functions. Something along the lines of:
#IF (%match(@currentafflictions,@preventhealth)=0) {
#IF (@healthbalance=1 and @healthsips>0) {drink health}
} |
This looks closer to what I have in mind, however I've run into a few problems with the above. You see, I need the script not to run if ANY of the items in @currentafflictions matches ANY of those in @preventhealth (even when there are addition items in either which are not matched).
Let's say for example that @preventhealth contained the values 'asleep' and 'stunned', and @currentafflictions contained any number of values (or none), which might or might not include one or both of those.
As far as I can tell, the above will only prevent the script from running when @currentafflictions contains everything listed in @preventhealth, which is close to but not exactly what I need. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Dec 30, 2006 12:09 pm |
If you don't want to adjust the variable to include the braces just use a %concat in the %match.
%match(@currentafflictions,%concat("{",@preventhealth,"}")) |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
geosmith Wanderer
Joined: 23 Apr 2005 Posts: 57
|
Posted: Sat Dec 30, 2006 4:10 pm |
Vijilante wrote: |
If you don't want to adjust the variable to include the braces just use a %concat in the %match.
%match(@currentafflictions,%concat("{",@preventhealth,"}")) |
Vijilante, I can't pretend to understand how that works, but it does and you're a genius. Thank you! |
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Sat Dec 30, 2006 4:16 pm |
To explain what Vij did, by forcing the %concat you're matching {@preventhealth}
which is the same as when you match a trigger to a variable using {@variable} syntax - so it matches any member of the variable rather than the entire variable.
Very clever nonetheless, something I'd not have thought of ;) |
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
|
|
|