checkspawns.inc

A forum for macro code snippets to be used in writing other macros. Post routines or .inc files here only, completed macros go to the Macro Depot.

Moderator: MacroQuest Developers

lestor
orc pawn
orc pawn
Posts: 16
Joined: Sat Jan 10, 2004 6:31 am

checkspawns.inc

Post by lestor » Sat Feb 07, 2004 6:26 am

This include uses the same INI file as my checkspawns.mac, also uses similar commands.

You'll need to include a /call for the sub CheckSpawns in the main loop of your macro.

When a mob spawns, the sub will return the ID of that mob. It will only return an ID once when the mob spawns.. not repeatedly.

Anyway, here's the code:

checkspawns.inc

Code: Select all

| - CheckSpawns macro by Lestor
|   
|   You will need to add the following line into the main loop of your macro:
|
|	/call CheckSpawns
|
|   If you already have a 'spawnlist' or 'spawnnum' global in your macro you may 
|   want to change the 'spawnlistarray' and 'spawnnumglobal' variable names via
|   the handy #defines near the top.  Also, be sure to specify your spawns.ini file.
|
|  Commands:
|    /echo cs help                + Diplays commands.
|    /echo cs add <spawnname>     + Adds a spawn name to the list in the INI file.
|    /echo cs beep [ONCE/ON/OFF]  + Turns beeping on or off.  Or only beep once.
|    /echo cs log [ON/OFF]        + Turns logging on or off.
|


#turbo

#define SPAWNS_INIFILE spawns.ini
#define SPAWNLISTARRAY spawnlist
#define SPAWNNUMGLOBAL spawnnum

#event CSCommand "[MQ2] cs"

Sub CheckSpawns
	/if $defined(SPAWNNUMGLOBAL)==FALSE /declare SPAWNNUMGLOBAL global
	/if "@SPAWNNUMGLOBAL"=="UNDEFINED-GLOBAL" /varset SPAWNNUMGLOBAL 0
	/if $defined(SPAWNLISTARRAY)==FALSE /declare SPAWNLISTARRAY array
	/call GetINIList
	/doevents
	/if "$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@SPAWNNUMGLOBAL))"==NOTFOUND {
		/varset SPAWNNUMGLOBAL 0
		/return
		}
	/if n $searchspawn("$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@SPAWNNUMGLOBAL))")==0 /if "@SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL))"!="UNDEFINED-ARRAY-ELEMENT" /call ReportTime "DESPAWNED" "@id"
	/if n $searchspawn("$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@SPAWNNUMGLOBAL))")>0 /call Alarm $searchspawn("$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@SPAWNNUMGLOBAL))")
	/varadd SPAWNNUMGLOBAL 1
	/doevents
	/if n $return>0 /return $return
/return

Sub Alarm(id)
	/call ReportTime "SPAWNED" "@id"
	/doevents
	/if $ini(SPAWNS_INIFILE,Settings,Beep)==ON /beep
	/if n $return>0 {
		/delay 5
		/return @id
		}
	/if $ini(SPAWNS_INIFILE,Settings,Beep)==OFF /return
	/if $ini(SPAWNS_INIFILE,Settings,Beep)==ONCE /return
	/delay 20
/return 

Sub ReportTime(action,id)
	/if "@SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL))"!="UNDEFINED-ARRAY-ELEMENT" /goto :Despawned
	/if @action==SPAWNED {
		/if $ini(SPAWNS_INIFILE,Settings,Beep)==ONCE /beep
		/echo [$if(n,$time(h)>12,$int($calc($time(h)-12)),$time(h)):$if(n,$time(m)<10,0$time(m),$time(m))$if(n,$time(h)>12,pm,am)] $spawn(@id,name,clean) is up!  ($int($spawn(@id,y)), $int($spawn(@id,x)), $int($spawn(@id,z)))
		/if $ini(SPAWNS_INIFILE,Settings,Log)==ON /mqlog [$if(n,$time(h)>12,$int($calc($time(h)-12)),$time(h)):$if(n,$time(m)<10,0$time(m),$time(m))$if(n,$time(h)>12,pm,am)] $spawn(@id,name,clean) spawned at: ($int($spawn(@id,y)), $int($spawn(@id,x)), $int($spawn(@id,z)))
		/varset SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL)) "$spawn(@id,name,clean)"
		}
	/return @id
	:Despawned
	/if @action==DESPAWNED {
		/echo [$if(n,$time(h)>12,$int($calc($time(h)-12)),$time(h)):$if(n,$time(m)<10,0$time(m),$time(m))$if(n,$time(h)>12,pm,am)] @SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL)) despawned.
		/if $ini(SPAWNS_INIFILE,Settings,Log)==ON /mqlog [$if(n,$time(h)>12,$int($calc($time(h)-12)),$time(h)):$if(n,$time(m)<10,0$time(m),$time(m))$if(n,$time(h)>12,pm,am)] @SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL)) despawned.
		/varset SPAWNLISTARRAY($int(@SPAWNNUMGLOBAL)) UNDEFINED-ARRAY-ELEMENT
		}
/return

Sub GetINIList
	/if $defined(getinilist)==FALSE /declare getinilist local
	/varset getinilist 0
	:Loop
		/if "$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@getinilist))"==NOTFOUND /return
		/varset SPAWNLISTARRAY($int(@getinilist)) "@SPAWNLISTARRAY($int(@getinilist))"
		/varadd getinilist 1
		/goto :Loop
/return

Sub AddSpawn(spawnname)
	/if $defined(tempcount)==FALSE /declare tempcount local
	/varset tempcount 0
	:Loop
		/doevents
		/if "$ini(SPAWNS_INIFILE,"$zone()",Spawn$int(@tempcount))"==NOTFOUND /goto :Add
		/varadd tempcount 1
		/goto :Loop
	:Add
		/ini "SPAWNS_INIFILE" "$zone()" "Spawn$int(@tempcount)" "@spawnname"
		/echo '@spawnname' added to INI file.
		/call GetINIList
/return

Sub Event_CSCommand(text)
	/if "$left(9,"@text")"!="[MQ2] cs " {
		/echo Invalid command.
		/return
		}
	/if "$arg(3,"@text")"=="help" /goto :ShowHelp
	/if "$arg(3,"@text")"=="add" /goto :AddSpawn
	/if "$arg(3,"@text")"=="log" /goto :ToggleLog
	/if "$arg(3,"@text")"=="beep" /goto :ToggleBeep
	/echo Invalid command.
	/return
	:ShowHelp
		/echo - /echo add <spawnname>
		/echo - /echo beep [ONCE/ON/OFF]
		/echo - /echo log [ON/OFF]
		/echo - /echo reload
		/return
	:AddSpawn
		/if "$right(3,@text)"=="add" {
			/echo You must specify a spawn name.
			/return
			}
		/call AddSpawn "$right($calc($strlen("@text")-13),"@text")
		/return
	:ToggleLog
		/if "$right(3,"@text")"==log {
			/if $ini(SPAWNS_INIFILE,Settings,Log)==OFF /goto :On
			/if $ini(SPAWNS_INIFILE,Settings,Log)==ON /goto :Off
			}
		/if "$right(3,"@text")"==OFF /goto :LogOff
		/if "$right(2,"@text")"==ON /goto :LogOn
		/echo Invalid command.
		/return
		:LogOff
			/ini "SPAWNS_INIFILE" "Settings" "Log" "OFF"
			/echo Logging is now OFF.
			/return
		:LogOn
			/ini "SPAWNS_INIFILE" "Settings" "Log" "ON"
			/echo Logging is now ON.
			/return
	:ToggleBeep
		/if "$right(4,"@text")"==beep {
			/if $ini(SPAWNS_INIFILE,Settings,Beep)==OFF /goto :BeepOnce
			/if $ini(SPAWNS_INIFILE,Settings,Beep)==ON /goto :BeepOff
			/if $ini(SPAWNS_INIFILE,Settings,Beep)==ONCE /goto :BeepOn
			}
		/if "$right(3,"@text")"==OFF /goto :BeepOff
		/if "$right(2,"@text")"==ON /goto :BeepOn
		/if "$right(4,"@text")"==ONCE /goto :BeepOnce
		/echo Invalid command.
		/return
		:BeepOnce
			/ini "SPAWNS_INIFILE" "Settings" "Beep" "ONCE"
			/echo Beep notification set to ONCE.
			/beep
			/return
		:BeepOn
			/ini "SPAWNS_INIFILE" "Settings" "Beep" "ON"
			/echo Beep notification set to ON.
			/beep
			/return
		:BeepOff
			/ini "SPAWNS_INIFILE" "Settings" "Beep" "OFF"
			/echo Beep notification set to OFF.
			/return
/return
and...

spawns.ini

Code: Select all

[Settings] 
Beep=ONCE 
Log=ON 

[Iceclad Ocean] 
Spawn0=Lodizal 
Spawn1=Stormfeather 

[Southern Karana] 
Spawn0=Quillmane 

[Lower Guk] 
Spawn0=Raster of Guk 

[Plane of Fear] 
Spawn0=Cazic Thule 
Spawn1=Dracoliche 
Spawn2=Dread 
Spawn3=Fright 
Spawn4=Terror 
Cheers,

Lestor