|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: Sat Feb 20, 2010 3:09 pm
@Var.contains |
How can I check if a string var contains what I need and make it return true?
#var test1 {aaa|bbb|ccc|ddd|eee fff|ggg hhh}
#IF %contains(@test1,"eee") {do1} {do2}
I found no function that does that, does it exist? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Feb 20, 2010 5:22 pm |
%ismember("eee",@test1)
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: Sat Feb 20, 2010 6:52 pm |
Thanks a lot!
#unvar spells
affects
#wait 2000
#if (%ismember("dodge",@spells)) {} {dodge}
#if (%ismember("martial arts ",@spells)) {} {martial}
#if (%ismember("bladedance",@spells)) {} {bladedance}
#if (%ismember("phase",@spells)) {} {phase}
#if (%ismember("sneak",@spells)) {} {sneak}
#if (%ismember("sanctuary",@spells)) {} {#echo Missing, sanctuary}
#if (%ismember("shield ",@spells)) {} {#echo Missing, shield;#CR}
This is the result of what you helped me achieve, just in case you were curious. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Feb 21, 2010 2:50 am |
Code: |
#unvar spells
affects
#wait 2000
#if (%ismember("dodge",@spells)) {} {dodge}
#if (%ismember("martial arts ",@spells)) {} {martial}
#if (%ismember("bladedance",@spells)) {} {bladedance}
#if (%ismember("phase",@spells)) {} {phase}
#if (%ismember("sneak",@spells)) {} {sneak}
#if (%ismember("sanctuary",@spells)) {} {#echo Missing, sanctuary}
#if (%ismember("shield ",@spells)) {} {#echo Missing, shield;#CR} |
Can you do all of these at the same time? I'm guessing you can't since they look like skill abilities that probably use some sort of balance. If not, I wouldn't do your script this way because you are checking and trying to execute each line of code every time you run this script. Unless you can use every one of those skills at the same time you are sending wasted commands.
Also I would not be using #unvar either because you are deleting and recreating the variable spells constantly. Use spells = "" or spells = %null to clear the list and set spells variable to use default.
Finally, instead of doing #if (%ismember("blah",@spells)) {} {do stuff} it should be #if (!%ismember("blah",@spells)) {do stuff}.
I'm guessing these are skills and you are checking them with affects. You would be better off running the part after #wait off of a trigger that would fire at the end of checking your list instead of using #wait. If each of those abilities use equilibrium for example, then you could create an Event handler that would fire each time you recovered equilibrium. When you have completed them all, just cause it to disable.
Example:
Code: |
#if (!%ismember("dodge",@spells)) {dodge} {
#if (!%ismember("martial arts ",@spells)) {martial} {
#if (!%ismember("bladedance",@spells)) {bladedance} {
#if (!%ismember("phase",@spells)) {phase} {
#if (!%ismember("sneak",@spells)) {sneak} {
#if (!%ismember("sanctuary",@spells)) {#print Missing, sanctuary}
#if (!%ismember("shield ",@spells)) {#print Missing, shield}
#T- doAffects
}
}
}
}
}
|
If you can do all at the same time, then it would look like the following:
Code: |
spells = ""
affects
#wait 2000
#if (!%ismember("dodge",@spells)) {dodge}
#if (!%ismember("martial arts ",@spells)) {martial}
#if (!%ismember("bladedance",@spells)) {bladedance}
#if (!%ismember("phase",@spells)) {phase}
#if (!%ismember("sneak",@spells)) {sneak}
#if (!%ismember("sanctuary",@spells)) {#print Missing, sanctuary}
#if (!%ismember("shield ",@spells)) {#print Missing, shield} |
You can do whatever you want of course. :-) |
|
|
|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: Sun Feb 21, 2010 1:22 pm |
My mud doesn't have any equilibrium code, and there's no way I can trigger the end of the affects. Thank you though for your suggestions, especially the spells = "" suggestion, I was unhappy myself of continually deleting and recreating a var.
Why do you use #print instead of #echo? Isn't the same thing? I won't concatenate the trigger as mentioned in your first example, because that'll make it use just one ability at a time and force me to activate the check alias more than once. It seems I can use all my abilities at once without losing equilibrium for now.
I will post the final script with your added modifications and the result, just to prove how much I've appreciated your help. Thanks a lot!
Part of the whole script modified with your suggestions
Code: |
#T+ tspell
spells = ""
affects
#wait 2000
#if (!%ismember("dodge",@spells)) {dodge}
#if (!%ismember("martial arts ",@spells)) {martial}
#if (!%ismember("bladedance",@spells)) {bladedance}
#if (!%ismember("phase",@spells)) {phase}
#if (!%ismember("sneak",@spells)) {sneak}
#cr
#print "Missing SPELLS:"
#if (!%ismember("sanctuary",@spells)) {#print SANCTUARY}
#if (!%ismember("shield ",@spells)) {#print SHIELD}
#T- tspell
|
Whole script, is in XML since I don't know how to export a script in zScript format
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="check" copy="yes">
<value>#T+ tspell
spells = ""
affects
#wait 2000
#if (!%ismember("dodge",@spells)) {dodge}
#if (!%ismember("martial arts ",@spells)) {martial}
#if (!%ismember("bladedance",@spells)) {bladedance}
#if (!%ismember("phase",@spells)) {phase}
#if (!%ismember("sneak",@spells)) {sneak}
#cr
#print "Missing SPELLS:"
#if (!%ismember("sanctuary",@spells)) {#print SANCTUARY}
#if (!%ismember("shield ",@spells)) {#print SHIELD}
#T- tspell</value>
</alias>
<trigger name="tspell" priority="290" copy="yes">
<pattern>SPL: ~(*~)(%s)(&spl) (%s)</pattern>
<value>#var spl %replace(@spl," ")
#var spells %additem(@spl,@spells)</value>
</trigger>
</cmud>
|
Result in the mud output
Code: |
I typed: CHECK
|(247%/47)](100%[3756/3756])(100%)(100%)[0/0]> affects
SPL: ( innate ) bless +35 to Move-regen
SPL: ( innate ) bless +5 to Hitroll
SPL: ( innate ) infravision sets INFRA
SPL: ( innate ) detect invisibility sets DET-INVIS
SPL: ( innate ) dodge sets DODGE
SPL: (1 min) martial arts sets MARTIAL-ARTS
SPL: ( innate ) phase sets PHASE
SPL: (42 min) sneak sets SNEAK
|(247%/47)](100%[3756/3756])(100%)(100%)[0/0]> bladedance
Missing SPELLS:
SANCTUARY
SHIELD
You spin your weapons around in your fingers.
|(247%/47)](100%[3756/3756])(100%)(99%)[0/0]>
|
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Wed Feb 24, 2010 4:35 pm |
Quote: |
I won't concatenate the trigger as mentioned in your first example, because that'll make it use just one ability at a time and force me to activate the check alias more than once. |
I have no idea what you mean here. As far as #PRINT goes it isn't checked against triggers.
Anyway, since they don't use any sort of balance you are fine. |
|
|
|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: Wed Feb 24, 2010 5:38 pm |
Then I've probably not understand why you've done concatenating the IF's if you have no idea what I meant.
There's a chance you could explain that concept again?
Code: |
#IF (a > b) {do} {
#IF (a > b) {do} {
#IF (a > b) {do} {
}
}
} |
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Feb 24, 2010 9:45 pm |
That's not concatenation, that's nesting. Each subsequent level of your example is only evaluated if the preceding one returns false.
Concatenation is a string term that means "connect these strings together to form one string". The entire string is then sent to whatever source it was called by. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
leonardofaoro Novice
Joined: 07 Feb 2008 Posts: 40 Location: Italy
|
Posted: Wed Feb 24, 2010 10:35 pm |
Thanks
|
|
|
|
|
|
|
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 vote in polls in this forum
|
|