Can I create a conditional based on the mob's position?

  • Banlock
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
1 year 2 weeks ago #7039 by Banlock
I'm trying to write a greet and random tigger that does different things depending on the position of the mob. It seems like I ought to be using something like:
if %self.pos% == Sleeping || Resting || Sitting

But this always returns true, even on a mob where 'stat' says that it is standing. So looking at this section:
%asound% Mobile-Random-Triggered
if %self.pos% == Sleeping || Resting || Sitting
    * Things to do if not active (this guy shouldn't sleep)
    %asound% Sleeping-Resting-Sitting
    break
elseif %self.pos% == Standing
    * Things to do if in normal position
    ...

I always see:
Mobile-Random-Triggered
Sleeping-Resting-Sitting

Am I using this wrong?

Please Log in or Create an account to join the conversation.

  • Banlock
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
1 year 2 weeks ago #7041 by Banlock
Okay, I have to be doing something dumb, I'm just blind to it.

Here is the second version of the whole trigger, with all of the debugging stuff I added:
* Mobile Random - Little mouse droid actions and sounds, based on position
* Positions: Sleeping, Resting, Sitting, Fighting, Standing
%zoneecho% %self.vnum% MRT - The Mobile Random Trigger
%zoneecho% %self.vnum% MRT - My position is %self.pos%
if %self.pos(Standing)%
    * Things to do if in normal position
    %zoneecho% %self.vnum% MRT - Standing conditional
    switch %random.4%
        case 1
            %zoneecho% %self.vnum% MRT - Standing Case 1
            emote is rolling slowly backward, whistling something complicated.
        break
        case 2
            %zoneecho% %self.vnum% MRT - Standing Case 2
            emote is zipping around the room, as if looking for something.
        break
        case 3
            %zoneecho% %self.vnum% MRT - Standing Case 3
            emote is silently rolling across the room.
        break
        case 4
            %zoneecho% %self.vnum% MRT - Standing Case 4
            emote is beeping and whistling quietly as it rolls across the room.
        break
        default
            %zoneecho% %self.vnum% MRT - Standing Default
            emote is still and softly whistling and beeping.
        break
    done
elseif %self.pos(Fighting)%
    %zoneecho% %self.vnum% MRT - Fighting conditional
    switch %random.4%
        case 1
            %zoneecho% %self.vnum% MRT - Fighting Case 1
            emote is flicking it's tiny, sharp probe arm as it tries to attack.
        break
        case 2
            %zoneecho% %self.vnum% MRT - Fighting Case 2
            emote is whistling shrilly as it tries to defend itself.
        break
        case 3
            %zoneecho% %self.vnum% MRT - Fighting Case 3
            %zoneecho% %self.vnum% A droid alarm call bleets out. 
        break
        case 4
            %zoneecho% %self.vnum% MRT - Fighting Case 4
            * Do nothing 
        break
        default
            %zoneecho% %self.vnum% MRT - Fighting Default
            * Do nothing
        break
    done
else
    * Things to do if not active (this guy shouldn't sleep)
    %zoneecho% %self.vnum% MRT - default conditional
    break
end

At first, that seemed fine. Letting the mouse loose in the zone I saw the standing messages I expected like:
MRT - The Mobile Random Trigger
MRT - My position is Standing
MRT - Standing conditional
MRT - Standing Case 4

So I sent in a first level character to fight the droid, to test the fighting position messages, but I got this:
21H 100M 83V > kill mouse
The little mouse droid ducks under your fist as you try to hit it.

21H 100M 83V > 
The little mouse droid misses you with its sting!
You tickle the little mouse droid as you hit it.

21H 100M 83V > 
MRT - The Mobile Random Trigger
MRT - My position is Fighting
MRT - Standing conditional
MRT - Standing Case 1
The little mouse droid is rolling slowly backward, whistling something complicated.
The little mouse droid misses you with its sting!
You try to hit the little mouse droid who easily avoids the blow.

So obviously I'm doing something really dumb here that is fouling up my conditional statements, but I've gotten frustrated so it is hard to see what I've done.

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #7044 by thomas
if %self.pos% == Sleeping || Resting || Sitting
should be
if %self.pos% == Sleeping || %self.pos% == Resting || %self.pos% == Sitting

Please Log in or Create an account to join the conversation.

  • Banlock
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
1 year 2 weeks ago #7045 by Banlock
Thanks, I should have seen from the examples that wouldn't work.

If you don't mind, In the second version I posted, what is my construction of "if %self.pos(Standing)%" doing?

Please Log in or Create an account to join the conversation.

More
1 year 2 weeks ago #7050 by thomas
the subfield is used for setting the field, generally. Also in this case:
 /* Thanks to Christian Ejlertsen for this idea
             And to Ken Ray for speeding the implementation up :)*/
          if (!str_cmp(field, "pos")) {
            if (subfield && *subfield) {
              for (i = POS_SLEEPING; i <= POS_STANDING; i++) {
                /* allows : Sleeping, Resting, Sitting, Fighting, Standing */
                if (!strn_cmp(subfield, position_types[i], strlen(subfield))) {
                  GET_POS(c) = i;
                  break;
                }
              }
            }
            snprintf(str, slen, "%s", position_types[GET_POS(c)]);
          }
The following user(s) said Thank You: Banlock

Please Log in or Create an account to join the conversation.

Time to create page: 1.153 seconds