Im working on an archer that will follow a lead character. when the archer sees a target creature, he will attack it. he will constantly move so that his lead is between him and the creature. this is the begining:
set %timWait ( #SCNT - 16 )
set %findtype PI_DH_FD_ME_TD
set %lastMon 00000
set %disMon 00000
set %corpse YFM
set %Gold POF
set %keys LZF
set %loot POF_LZF_ZFM_MIG
set %prize SWO
set %BOS 00000000
set %findPet 00000000
set %aids ZLF
;=====================================================
set %location 0 ; 0 = everything, 1 = ice, 2 = doom,
;=====================================================
if %location = 0
{
set %creaturetype TH_ME_PI_DH_FD_ME_TD_WD_R_EB
}
if %location = 1
{
set %creaturetype TH
}
if %location = 2
{
set %creaturetype ????
}
;=====================================================
FINDITEM %aids C_ , #BACKPACKID
IF #FINDKIND = -1
{
DISPLAY you need aids. $ HALTED!
HALT
}
set %bandage #findid
gosub setLead
;================== main loop =========================
loop:
gosub healthcheck
wait 1
gosub movOption
wait 1
goto loop
;======================================================
;================== health check ======================
sub healthcheck
if %timWait < ( #SCNT - 4 )
{
if ( #HITS + 10 ) < #MAXHITS || C in #CHARSTATUS
event sysmessage injured
set #lobjectid %bandage
event macro 17 0
target 2s
event macro 23 0
if #MAXSTAM < 115
{
set %timWait ( #SCNT + 2 )
}
set %timWait ( #SCNT + 1 )
}
}
return
;======================================================
sub movOption
gosub findMonster
return
;======================================================
sub findMonster
findItem %creaturetype G_8
if #findkind <> -1
{
if #finddist < 2
{
set #ltargetid #findid
set %target #findid
set %monX #findx
set %monY #findY
gosub findLead2
}
goto fm
}
gosub findLead1
fm:
return
sub findLead1
findItem %lead G_17
if #findkind <> -1
{
if #finddist <= 2
{
set %movex ( #findx )
set %movey ( #findy )
gosub moveNow1
}
}
return
sub findLead2
findItem %lead G_17
if #findkind <> -1
{
if #findx > %monX
{
if #findy > %monY
{
set %movex ( #findx + 1 )
set %movey ( #findy + 1 )
}
if #findy < %monY
{
set %movex ( #findx + 1 )
set %movey ( #findy - 1 )
}
if #findy = %monY
{
set %movex ( #findx + 1 )
set %movey ( #findy )
}
}
if #findx < %monX
{
if #findy > %monY
{
set %movex ( #findx - 1 )
set %movey ( #findy + 1 )
}
if #findy < %monY
{
set %movex ( #findx - 1 )
set %movey ( #findy - 1 )
}
if #findy = %monY
{
set %movex ( #findx - 1 )
set %movey ( #findy )
}
}
if #findx = %monX
{
if #findy > %monY
{
set %movex ( #findx )
set %movey ( #findy + 1 )
}
if #findy < %monY
{
set %movex ( #findx )
set %movey ( #findy - 1 )
}
}
gosub moveNow2
gosub attack
}
return
;================== move now ==========================================
sub moveNow1
set %x %movex
set %y %movey
set %z %movez
moving1:
event pathfind %x %y
if #CHARPOSX < ( %x - 2 ) || #CHARPOSX > ( %x + 2 ) || #CHARPOSY < ( %y - 2) || #CHARPOSY > ( %y + 2)
{
wait 10
goto moving1
}
return
sub moveNow2
set %x %movex
set %y %movey
set %z %movez
moving2:
event pathfind %x %y
if #CHARPOSX <> %x || #CHARPOSY <> %y
{
wait 10
goto moving2
}
return
;========================= attack ======================================
sub attack
event macro 22 0
wait 1
event macro 27 0
event sysmessage attack!
wait 10
return
;========================================================================
sub setLead
display ok please target your Lead.
set #targcurs 1
target 5s
watLeadLup:
if #targcurs = 1
{
goto watLeadLup
wait 5
}
finditem #ltargetid
set %lead #ltargetid
return