Making guards kick the right people out

For builders to discuss and ask building questions.
Post Reply
User avatar
Kregor
Sword Grand Master
Sword Grand Master
Posts: 1474
Joined: Sun Jul 11, 2004 6:14 am
Location: Baldur's Gate

Making guards kick the right people out

Post by Kregor » Wed Aug 17, 2005 5:31 am

My design for tangled trees, is that my roaming guards, in addition to serving out justice, would throw out "outsiders", meaning anyone who is not a forest folk. This is modified by a qbit for a quest that, if successfully completed, would allow others outside this group to stay within. Basically, I have the prog set up like this:

Code: Select all

>rand_prog 15~
if ispc($r)
  if quest(7,5,$r) == 0
    if race($r) != Elf
    or race($r) != Forest gnome
    or race($r) != Centaur
    or race($r) != Halfelf
    or guild($r) != Rangers
    or deity($r) != Mielikki
    or deity($r) != Chauntea
      sayto $r You are an outsider, you do not belong here.
      mpechoat $r $I grabs you, and takes you out of the clanholds.
      mpechoaround $n $I grabs $R, and takes $K out of the clanholds.
      yell I have found $R intruding in the the Forest! I have removed $K.
      mptransfer $r 56442 pet
    endif
  endif
endif
~
As it is, this code is not working properly, it ignores a person based on the qbit fine, but it throws people out otherwise, *even* if they are one of the races, or dieties that is supposed to be allowed running around as indicated.

What did I do wrong? And how to reword it?
"There is no safety for honest men except by believing all possible evil of evil men."

Kregor - Ranger of Tangled Trees
Rozor - Lady Luck's Duelist
Tygen - Ranger-Bard of Mielikki
Jharthyne
Sword Apprentice
Sword Apprentice
Posts: 60
Joined: Tue Sep 16, 2003 7:36 am
Location: Waterdeep
Contact:

Post by Jharthyne » Wed Aug 17, 2005 9:41 am

Pardon me, I could be wrong, but I think $r will return a random character each time it is used, which means the first character it checks may not be the same one that it throws out. Don't know for sure. (You may want to change back to $r if I am wrong.) The use of OR is not exactly what you intended too.

Maybe rewrite it to:

Code: Select all

>greet_prog 15~
if ispc($n)
  if quest(7,5,$n) == 0
    if race($n) == Elf
    or race($n) == Forest gnome
    or race($n) == Centaur
    or race($n) == Halfelf
    or guild($n) == Rangers
    or deity($n) == Mielikki
    or deity($n) == Chauntea
    else
      sayto $n You are an outsider, you do not belong here.
      mpechoat $n $I grabs you, and takes you out of the clanholds.
      mpechoaround $n $I grabs $R, and takes $K out of the clanholds.
      yell I have found $N intruding in the the Forest! I have removed $K.
      mptransfer $n 56442 pet
    endif
  endif
endif
~ 
|
The original logic (in terms of OR and AND) is wrong, since the PC just has to NOT satisfy one of the conditions for him to be thrown out. Which means the PC is thrown out unless he is an elf, forest gnome, centaur, ranger, and worships both Mielikki and Chautea all at the same time!
User avatar
Kregor
Sword Grand Master
Sword Grand Master
Posts: 1474
Joined: Sun Jul 11, 2004 6:14 am
Location: Baldur's Gate

Post by Kregor » Wed Aug 17, 2005 10:43 am

OH!

Now that you explain the reverse logic, it makes sense, only one criterium in a list of ORs has to be correct, so I'm setting everyone up for failure this way.

So, if using "==", I can leave the actions before the "else" blank, and it will just do nothing if the people are of the right group of people.

I think the $r bit is correct, because in a rand check, it refers to the one who triggered the rand. This way the guard may or may not notice the char, and it will work if the guard walks in the room with $r, not just vice versa.

The issue with != makes perfect mathematical sense. Thanks.
"There is no safety for honest men except by believing all possible evil of evil men."

Kregor - Ranger of Tangled Trees
Rozor - Lady Luck's Duelist
Tygen - Ranger-Bard of Mielikki
Caius
Sword Novice
Sword Novice
Posts: 31
Joined: Mon Aug 04, 2003 5:53 pm
Location: Waterdeep
Contact:

Post by Caius » Thu Aug 18, 2005 12:03 pm

You could just change all the uses of OR into AND in your first post. Then you don't need the else statement.
"Beer is proof that God loves us and wants us to be happy." -- Benjamin Franklin
User avatar
Argentia
Sword Grand Master
Sword Grand Master
Posts: 357
Joined: Fri Jul 23, 2004 4:31 am
Location: The City of Splendors
Contact:

Post by Argentia » Thu Aug 18, 2005 12:20 pm

I believe that would result in the opposite effect and throw out no one instead of everyone; a PC would have to meet all the AND requirements in order to be thrown out, which is impossible.
Do not meddle in the affairs of dragons, for you are crunchy and go well with ketchup.
Caius
Sword Novice
Sword Novice
Posts: 31
Joined: Mon Aug 04, 2003 5:53 pm
Location: Waterdeep
Contact:

Post by Caius » Fri Aug 19, 2005 2:08 am

Argentia wrote:I believe that would result in the opposite effect and throw out no one instead of everyone; a PC would have to meet all the AND requirements in order to be thrown out, which is impossible.
No. His original post threw everyone out. Letting everyone in would be the opposite. AND is not the opposite of OR, that would be NOR (not or). Letting everyone in would be an else statement to his original post.

Let me give a simple example: if race != Elf AND race != Halfelf then kick them out.

An elf would be: false AND true which evaluates to false. So they don't get kicked out.

A human would be: true AND true which evaluates to true. So they get kicked out.

So his code should be:

Code: Select all

>rand_prog 15~
if ispc($r)
  if quest(7,5,$r) == 0
    if race($r) != Elf
    and race($r) != Forest gnome
    and race($r) != Centaur
    and race($r) != Halfelf
    and guild($r) != Rangers
    and deity($r) != Mielikki
    and deity($r) != Chauntea
      sayto $r You are an outsider, you do not belong here.
      mpechoat $r $I grabs you, and takes you out of the clanholds.
      mpechoaround $n $I grabs $R, and takes $K out of the clanholds.
      yell I have found $R intruding in the the Forest! I have removed $K.
      mptransfer $r 56442 pet
    endif
  endif
endif
~ 
This way you don't need to use an else statement.
"Beer is proof that God loves us and wants us to be happy." -- Benjamin Franklin
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

Post by Dalvyn » Fri Aug 19, 2005 10:05 pm

Been whining for it for 3 years... but no, there is no "and" connector.

Note that it's always possible to replace "and" with a correct combination of "or" and "not" (as long as you do not reach max program length), but as the example above shows, this is prone to error.
Image
Post Reply