|
omniwing Beginner
Joined: 02 Jun 2006 Posts: 19
|
Posted: Thu Apr 10, 2008 11:09 pm
How do I say 'If not, then do this' |
I am new to coding, and am trying to write scripts for my mud that I play. Eventually I would like to write a combat bot for it. Something I am having trouble with is how how to say 'check this. If something isn't present, do this'.
so, I know how to do the opposite...a trigger! For instance, if I type AFF, it shows my affects. So I could set up a trigger that did something when it saw 'sanctuary' after I type AFF. However, how do I make a trigger, that when it types AFF and it doesn't see sanctuary, to cast it?
Also, if I wanted a script that would run to a monster, look at the monster, and if the monster wasn't wearing anything, it would recall...I obviously know how to make a trigger that when it sees an item, to stop a script and alert me.
So, basically, how do I check for states of something that have no value? I suppose maybe something like 'For 2 seconds after you type AFF if you don't see the word sanctuary, then do this". But that seems very roundabout and incorrect.
Thank you for your time.
Omniwing |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Apr 10, 2008 11:32 pm |
Without example text, it's difficult to give you something that'll work out of the box. But here's the technique I use. I'll assume that your text looks like this:
Quote: |
aff
You are affected by the following:
sanctuary, 500 minutes
protection from evil, 30 minutes
brian blessed impressions, 999999999 minutes
You are affected by 3 spells. |
To capture this, you first need to know when the list of affects begins and ends. That's pretty easy:
#trig {You are affected by the following:} {}
#cond {You are affected by %d spells.} {}
You need a variable to keep your affects in, and you need to set it to blank when the list begins:
#trig {You are affected by the following:} {MyAffs=""}
#cond {You are affected by %d spells.} {}
Now you need a separate trigger that you turn on when the list starts and turn off again when it ends, to capture your affects.
#trig {You are affected by the following:} {MyAffs="";#t+ AffCap}
#cond {You are affected by %d spells.} {#t- Affcap}
#trig "AffCap" {^([%w ]), %d minutes} {} "" {disable}
The AffCap trigger needs to add your affects to a list so you know which affects you've got:
#trig "AffCap" {^([%w ]), %d minutes} {#additem MyAffs %1} "" {disable}
Finally, when your list finishes, you can check to see if something's part of the list with %ismember. Your final script will look something like this:
#trig {You are affected by the following:} {MyAffs="";#t+ AffCap}
#cond {You are affected by %d spells.} {#t- Affcap;#if (!%ismember("sanctuary",@MyAffs)) {cast sanctuary}}
#trig "AffCap" {^([%w ]), %d minutes} {#additem MyAffs %1} "" {disable}
You can add more checks very easily:
#trig {You are affected by the following:} {MyAffs="";#t+ AffCap}
#cond {You are affected by %d spells.} {#t- Affcap;#if (!%ismember("sanctuary",@MyAffs)) {cast sanctuary};#if (%ismember("brian blessed impressions",@MyAffs)) {shout Gordon's Alive!?}}
#trig "AffCap" {^([%w ]), %d minutes} {#additem MyAffs %1} "" {disable}
but remember that you can't always use a spell immediately after using another one. If you didn't have sanctuary but did have brian blessed impressions, you'd perform both actions when you typed AFF. |
|
|
|
omniwing Beginner
Joined: 02 Jun 2006 Posts: 19
|
Posted: Fri Apr 11, 2008 12:21 am |
Thank you so much, Fang. I will study this! This is exactly what I needed to help me learn how to write code myself.
Much obliged sir!
Omni |
|
|
|
|
|
|
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
|
|