Need some help creating a certain IF statement.

Help section from before the user variable changes that broke all macros

Moderator: MacroQuest Developers

skysurf
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Aug 15, 2003 1:54 am

Need some help creating a certain IF statement.

Post by skysurf » Sun Sep 28, 2003 2:46 pm

Could someone write me a line of code that checks to see if anyone is within a certain level range and what race they are?

I am on a PvP server and basically I am trying to write an IF statement that does something if MQ see's someone +- 4 levels from me and if they are a Dark Elf or a Troll.

So basically the pseudo code im looking for is............


If Troll or Dark Elf between levels 52-60 are within 300 feet of me {then ill put my action code in here}

Thanks in advance for any help. Constructing this has me pretty befuddled hehe.

Sky

skysurf
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Aug 15, 2003 1:54 am

Post by skysurf » Sun Sep 28, 2003 2:48 pm

Actually, if that is too complicated to make, a simple line that will detect ANYONE in zone that is 52 to 60 and then an action would do to.

Thanks :)
Sky

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Sun Sep 28, 2003 7:35 pm

You basically wrote the whole thing already just by writing the desire. Just break it down one step further and then look in the manual for the things you want.

This is one way to do it. It may not be the fastest ... it may not be the best, but it is one way.

Code: Select all

/varset $l0 0
/varset $l1 false

:loop
  |Are they higher than my minimum level?
  /if n $spawn($l0,level)>$calc($char(level)-4)

    | Are they lower than my maximum level?
    /if n $spawn($l0,level)<$calc($char(level)+4)

      | They are in the right level range ... are they the close enough?
      /if n $spawn($l0,distance)<=300

        | Are they the right race?
        /if "$spawn($l0,race)"~~"Troll" /varset $l1 true
        /if "$spawn($l0,race)"~~"Dark Elf" /varset $l1 true

        | They match all conditions ... do something.
        /if "$l1"=="true"
          | Do my special stuff
        /return
    /return
  /return

  /varset $l0 $spawn($l0,next)
/if $l0>0 /goto :loop

skysurf
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Aug 15, 2003 1:54 am

Post by skysurf » Sun Sep 28, 2003 11:39 pm

Fiend, first off thank you soooo much for taking the time to write that for me. I am trying to go through it and see what your doing so I can learn and get my script to do what I want it to do.

I see what you are doing, but I have some questions about $spawn.

This is all it has in the manual on $spawn.....................

$spawn(id,xxx)
Returns information on a spawn
xxx can be: name[clean], surname, id, x, y, z, heading, headingto, state, speed, distance[,nopredict|x|y|z], type, level, gm, class, race, gender, light, pet, master
state can return: STAND, SIT, DUCK, BIND, FEIGN, DEAD
$spawn(id,hp,xxx) returns the spawn's hp: cur, max, pct
$spawn(id,next/prev) returns the id of the next/previous spawn.
$spawn(id,held,xxx) returns the model name for a held slot
xxx can be: right, left, shield

So what I see in what you wrote is $spawn(0,level). I don't understand what the 0 is for.

Basically I only want to check the level of PC's in the zone. What I want to assume is that the 0 is to tell the $spawn command to only look at PC's. Am I right in that assumption or is the 0 for something else?

Thanks bunches :)

Sky

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Sun Sep 28, 2003 11:48 pm

The local variable, $l0, is used to hold the spawn id for the creature you are looking at in memory. When you call $spawn($l0,level), you are asking for Spawn xxx's (the number being held in $l0) level.

At the end of the loop, you are setting $l0 to the next spawn id after $l0. If you are at the end of the spawn list, it will loop back to the first spawn (0). So since you started checking the information with spawn 0, you know you have then completed a full cycle through the spawn table.

A word of caution. Looping through the spawn table like I've shown without any /doevents or /delays will cause your EQ session to freeze until it has finished the loop. In a zone with a large number of spawns, this can be quite some time.

skysurf
a lesser mummy
a lesser mummy
Posts: 52
Joined: Fri Aug 15, 2003 1:54 am

Post by skysurf » Mon Sep 29, 2003 12:28 pm

Ok let me make sure I understand this right. With what you have done in your code you basically just run through the entire spawn table for the zone looking for a match to a given set of parameters (I would assume that Player Character only would be one of those parameters so a level 56 in the zone wouldn't trigger the action), and in your code you just start at 0 and move up the spawn ID list.


Ok so in the $spawn list, all characters (pc's and npc's) are in it?

Is there any way to do a check against JUST the PC's in the zone?

Is there any sort of command to just parse a basic /w list in the zone? The zone I will need this in most hardly ever has more than about 5 people in it.

It would seem that simply parsing a /w list against a set of criteria for what your looking for would be the easiest way to do it, however I have no idea if anything like that exists in macroquest.

MacroFiend
a grimling bloodguard
a grimling bloodguard
Posts: 662
Joined: Mon Jul 28, 2003 2:47 am

Post by MacroFiend » Mon Sep 29, 2003 7:03 pm

The loop I wrote will rotate through all the spawns in the zone's spawn table starting at 0 and incrementing until the last spawn points it back to 0. PC, NPC, Trigger NPC etc. To my knowledge, there is no way to narrow the $spawn() list to just one type of responses. The way the macro variable is written, you are iterating through the real spawn table from memory. Since we are directly accessing the memory, our commands have to do all the filtering.

As for having a macro parse the super who command, I don't believe it has been tried due to having to deal with a stream of data. If there was a stream buffer that the super who could push data in to and then get parsed through like a file, then I could see something like that working. The issue there is that you wouldn't have access to all the data of the $spawn() variable, only the information that comes out of the who.

Plazmic
The One
The One
Posts: 800
Joined: Fri Jun 14, 2002 12:31 am
Contact:

Post by Plazmic » Tue Sep 30, 2003 1:30 am

So, would a $searchspawn(criteria) be a good thing?
criteria being similar to /target's collection?

Example:

Code: Select all

/varset l0 $searchspawn(pc,race:orge,range:50:55)
/if n $l0==0 /goto :NoPCOrges
:Loop
   | test $spawn($l0,xxx)...
   /varset l0 $searchspawn(pc,race:orge,range:50:55,next,id:$l0)
/if n $l0!=0 /goto :Loop
:NoPCOrges
| blah...
I'll submit this tomorrow since I want to test it a bit more (The /target function doesn't exist anymore in it's old format)
Created a SEARCHSPAWN struct
Broke the /target into separate functions for parsing (now "fill in SEARCHSPAWN") and the spawn list search part (now "find closest spawn that matches SEARCHSPAWN criteria")
Then I added $searchspawn(), with all of /target's parsing modified for a (npc,range:15:20,dervish) format.
Instead of "id" being the SpawnID you want to search for (kind of redundant), it is used as the 'current' spawn used by prev/next (your current target in /target's context)


The next thing I want to do is to merge SuperWho's and Target's parsing/search structures... (make /who use /target's parameters instead of it's current half-brew)
- Plazmic