Verify NPC Target -- Useful for Event Handling

A forum for you to dump all the macros you create, allowing users to use, modify, and comment on your work.

Moderator: MacroQuest Developers

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Verify NPC Target -- Useful for Event Handling

Post by ml2517 » Sat Dec 27, 2003 1:09 am

I created this Sub to verify that my targets were were in fact the mobs that were generating event text.

For instance:
I am fighting a high level mob that enrages and when the mob casts I want to slam or bash it. There will be event text generated like so:

"Soandso begins to cast a spell."
"Soandso has become ENRAGED!"
"Soandso is no longer enraged."

If you tried to set up an event "begins to cast a spell" your script would react if any player or npc within range of you started casting.

With this it should narrow it down to the mob you are fighting, unless the mob is named something like "An orc pawn" and there are multiple mobs with "An" as the beginning of the name within the radius value that you provide.

It isn't perfect but it is about as good as it gets.

Anyways.. here is the code and with a few event examples. Please let me know how this works out for you and if there is anything I need to correct. (I tested this mostly against player characters so hopefully when I switched it to npc everything works out.)

Code: Select all

#Event Enraged "has become ENRAGED" 
#Event Offrage "is no longer enraged" 
#Event Bash "begins to cast a spell" 

Sub Main
:Loop
/delay 1
/doevents
/goto :Loop
/return

Sub Event_Enraged(OnRageText) 
    /if $target()=="TRUE" { 
        /call FindEvtNPC "@OnRageText" 150
        /if $return==FOUND {
            /varset EnrageVar 1 
            /attack off 
        }
    } 
/return 


Sub Event_Offrage(OffRageText) 
    /if $target()=="TRUE" { 
        /call FindEvtNPC "@OffRageText" 150
        /if $return==FOUND {
            /varset EnrageVar 0 
            /attack on 
        }
    } 
/return 

Sub Event_Bash(BashText)
    /if $target()=="TRUE" {
        /call FindEvtNPC "@BashText" 150
        /if $return==FOUND /doability "Slam"
    } 
/return 

Sub FindEvtNPC(MsgText,SrchRadius)
   /declare MobName local
   /declare MobID local
   /declare LastID local
   /varset MobName $arg(1,"@MsgText")
   /varset MobID 0
   /varset LastID 0
   /if $target()=="TRUE" {
       /varset MobID $searchspawn("@MobName",npc,radius:@SrchRadius)
       :GetID
       /if n @MobID!=0 {
           /varset LastID @MobID
           /if n $target(id)==@MobID {
               /return FOUND
               } else {
                   /varset MobID $searchspawn("@MobName",npc,id:@LastID,radius:@SrchRadius,next)
                   /if n @LastID==@MobID /return NOTFOUND
                   /goto :GetID                      
               }
          }
     } 
/return NOTFOUND

ml2517
a grimling bloodguard
a grimling bloodguard
Posts: 1216
Joined: Wed Nov 12, 2003 1:12 am

Post by ml2517 » Sat Dec 27, 2003 2:31 am

This one should should be a bit more accurate although you have to feed it the event text you are triggering off of in the /call.

Code: Select all


#Event Enraged "has become ENRAGED" 
#Event Offrage "is no longer enraged" 
#Event Bash "begins to cast a spell" 

Sub Main 
:Loop 
/delay 1 
/doevents 
/goto :Loop 
/return 

Sub Event_Enraged(OnRageText) 
    /if $target()==TRUE { 
        /call FindEvtNPC "@OnRageText" 200 "has become ENRAGED"
        /if $return==FOUND { 
            /attack off 
        } 
    } 
/return 


Sub Event_Offrage(OffRageText) 
    /if $target()==TRUE { 
        /call FindEvtNPC "@OffRageText" 200 "is no longer enraged"
        /if $return==FOUND { 
            /attack on 
        } 
    } 
/return 

Sub Event_Bash(BashText) 
    /if $target()==TRUE { 
        /call FindEvtNPC "@BashText" 200 "begins to cast a spell"
        /if $return==FOUND {
            /doability "Slam" 
        }
    } 
/return 

Sub FindEvtNPC(MsgText,SrchRadius,EvtText) 
   /declare MobName local 
   /declare MobID local 
   /declare LastID local 
   /declare PositionText local
   /varset PositionText $instr("@EvtText","@MsgText") 
   /varset MobName "$mid(0,@PositionText,"@MsgText")"
   /if "$right(1,"@MobName")"==" " /varset MobName "$left($calc($strlen("@MobName")-1),"@MobName")"
   /varset MobID 0 
   /varset LastID 0 
   /if $target()=="TRUE" { 
       /varset MobID $searchspawn("@MobName",npc,radius:@SrchRadius) 
       :GetID 
       /if n @MobID!=0 { 
           /varset LastID @MobID 
           /if n $target(id)==@MobID { 
               /return FOUND 
               } else { 
                   /varset MobID $searchspawn("@MobName",npc,id:@LastID,radius:@SrchRadius,next) 
                   /if n @LastID==@MobID /return NOTFOUND 
                   /goto :GetID                      
               } 
          } 
     } 
/return NOTFOUND