Main
Projects
Art
Music
Scripting
LiveJournal
Forum
Links
OHRRPGCE Tactics
by Moogle1

This is the full scriptage to OHRRPGCE Tactics with additional comments. The script is split into two parts. The first part is the main script and the second is an included file, BATTLES.HSI.
I didn't comment the plot-related scripts. You'll want to change them in your game anyway.


include,plotscr.hsd

define script (1,start,none) #plot-related
define script (2,intro,none) #plot-related
define script (3,defeatleader,none) #initiates a Defeat Leader btl
define script (6,defeatall,none) #initiates a Defeat All btl
define script (autonumber,shownwait,1,0) #shows and waits for a text box
define script (4,dobattle,none) #the battle loop
define script (5,gorolla,none) #plot-related
define script (autonumber,enemyturn,1,0) #an enemy takes his turn
define script (autonumber,allyturn,1,0) #an ally takes his turn
define script (autonumber,heroturn,1,0) #a hero takes his turn
define script (autonumber,showicons,1,0) #show menu icons
define script (autonumber,dowalk,1,0) #hero walks
define script (autonumber,choosedir,1,0) #choose direction at end of turn
define script (autonumber,choosetarget,2,0,1) #choose an attack target

include,tactics.hsi
include,battles.hsi #see below

script,gorolla,begin
  suspendcatapillar
  teleporttomap(1,6,4)
  setherodirection(0,right)
  setherodirection(1,right)
  setherodirection(2,down)
  setherodirection(3,down)
  setheroposition(1,4,4)
  setheroposition(2,6,2)
  setheroposition(3,7,3)
  set tag(6,on)
  shownwait(23)
  walknpc(10,down,3)
  walknpc(10,right,4)
  pancamera(right,5,5)
  waitfornpc(10)
  pancamera(down,3,2)
  walknpc(2,right)
  walknpc(2,up)
  walknpc(3,up)
  walknpc(3,left,4)
  walknpc(1,up)
  walknpc(1,left,2)
  walknpc(0,down)
  walknpc(0,left,2)
  shownwait(24)
  waitforall
  defeatall
  battle2
  dobattle
end

script,start,begin
 intro
 suspendcatapillar
 play song (1) #battle music
 defeatleader
 battle1 #initialize battle
 dobattle
 show text box(16)
end

script,intro,begin
 suspend player
 walk npc(0,left,6)
 walk npc(1,left,6)
 walk npc(2,left,6)
 walk npc(10,down,4)
 walk npc(11,down,4)
 wait for npc(10)
 pan camera(down,2,4)
 walk npc(10,right)
 walk npc(11,right)
 wait for npc(10)
 shownwait(1)
 shownwait(2)
 walk npc(10,right)
 shownwait(3)
 shownwait(4)
 shownwait(5)
 suspend hero walls
 walk hero(me,down,2)
 show text box(6)
 wait for hero(me)
 resume hero walls
 wait for text box
 set npc direction(10,up)
 shownwait(7)
 shownwait(8)
 set hero direction(me,right)
 shownwait(9)
 resume player
end

script,defeatall,begin
 suspendplayer
 fadescreenout(0,0,0)
 show backdrop(1) #it says "Defeat All Enemies"
 wait(2)
 fadescreenin
 waitforkey
 fadescreenout(0,0,0)
 show map
 wait(2)
 fadescreenin
 resumeplayer
 setvariable(wincondition,DftAll) #this is the important part
end

script,defeatleader,begin
 suspendplayer
 fadescreenout(0,0,0)
 show backdrop(2) #it says "Defeat the Leader"
 wait(2)
 fadescreenin
 waitforkey
 fadescreenout(0,0,0)
 show map
 wait(2)
 fadescreenin
 resumeplayer
 setvariable(wincondition,DftLdr) #important!
end

script,shownwait,num,begin #very simple script!
 show text box(num)
 wait for text box
end

script,dobattle,begin
 suspendcatapillar
 suspendplayer
 variable(ctr)
 variable(win)
 variable(ctr2)
 set variable(win,false)
 #hold down 'q' after your turn to quit (debug key!)
 while (keyispressed(16)==false,and,win==false,and,checktag(100)==false) do
 (
   #this loop increments AT until someone reaches 150. they then take their turn.
   set variable(win,true)
   for (ctr,1,numenemies,1) do
   (
     #every turn, each character's AT bar is incremented by his speed.
     setenemystat(ctr,at,getenemystat(ctr,at)+getenemystat(ctr,spd))
     if (getenemystat(ctr,hp)<<1) then (setenemystat(ctr,at,0))
     else #if this character is alive...
     (
      #if he is the leader (always character no. 1), you don't win
      if (ctr==1) then(set variable(win,false))
      #if you must defeat everyone, you still don't win
      if (wincondition==DftAll) then(set variable(win,false))
     )
     #when AT reaches at least 150, the character takes his turn
     if (getenemystat(ctr,at)>>150) then
     (
       enemyturn (ctr)
       setenemystat(ctr,at,getenemystat(ctr,at)--150)
     )
   )
   #this does the same thing, but for cpu-controlled allies
   for (ctr,1,numallies,1) do
   (
     setallystat(ctr,at,getallystat(ctr,at)+getallystat(ctr,spd))
     if (getallystat(ctr,hp)<<1) then (setallystat(ctr,at,0))
     if (getallystat(ctr,at)>>150,and,win==false) then
     (
       allyturn (ctr)
       setallystat(ctr,at,getallystat(ctr,at)--150)
     )
     set variable(win,true)
     #this is another victory-check
     for (ctr2,1,numenemies,1) do
     (
       if (getenemystat(ctr2,hp)<<1) then (setenemystat(ctr2,at,0))
       else
       (
         if (ctr2==1) then(set variable(win,false))
         if (wincondition==DftAll) then(set variable(win,false))
       )
     )
   )
   set tag(100,true)
   #same thing AGAIN (see how inefficient I am?) but for heroes
   for (ctr,0,3,1) do
   (
     setheroat(ctr+1,getheroat(ctr+1)+getherostat(ctr,stat:Spd))
     if (getherostat(ctr,stat:hp,currentstat)<<1) then (setheroat(ctr+1,0))
     else (set tag(100,false))
     if (getheroat(ctr+1)>>150,and,win==false) then
     (
       heroturn (ctr)
       setheroat(ctr+1,getheroat(ctr+1)--150)
     )
     set variable(win,true)
     #yet another victory check
     for (ctr2,1,numenemies,1) do
     (
       if (getenemystat(ctr2,hp)<<1) then (setenemystat(ctr2,at,0))
       else
       (
         if (ctr2==1) then(set variable(win,false))
         if (wincondition==DftAll) then(set variable(win,false))
       )
     )
   )
 )
 #main loop is over, so time to return control to player
 resumeplayer
 if (checktag(100)==false) then
 (
   showbackdrop(3)
   set tag(6,on) #field clear tag
   waitforkey(usekey)
   showmap
 )
 if (checktag(100)) then
 (
   showbackdrop(4)
   waitforkey(usekey)
   showmap
   gameover
 )
 resumecatapillar
end

script,enemyturn,who,begin #AI script for enemies!
 variable (movement)
 variable (ctr)
 variable (targetdist)
 variable (targethp)
 variable (targetx)
 variable (targety)
 variable (tempdist)
 variable (range)
 variable (targetid)
 variable (offx)
 variable (offy)
 variable (lastmov)
 focuscamera(npcx(who--1),npcy(who--1),10)
 waitforcamera
 camerafollowsnpc(who--1)
 set variable (targetdist,50)
 set variable (targethp,999)
 set variable (movement,getenemystat(who,mov))
 set variable (range,getenemystat(who,rng))
 if (getenemystat(who,cls)==Wizard,and,getenemystat(who,mp)>>1) then
   (set variable (range,5)) #he will use a spell if he can
 if (getenemystat(who,cls)<>Priest) then #Priest AI wasn't ever done
 (
  #find weakest enemy within range
  for (ctr,1,numallies,1) do
  (
    if (getallystat(ctr,hp)>>0) then
    (
      setvariable(tempdist,abs(npcx(who--1)--npcx(ctr+9))+abs(npcy(who--1)--npcy(ctr+9)))
      if (targetdist>>movement+range,and,targetdist>>tempdist) then
      (
        #if previous target is out of reach then select new target
        set variable(targetdist,tempdist)
        set variable(targethp,getallystat(ctr,hp))
        set variable(targetx,npcx(ctr+9))
        set variable(targety,npcy(ctr+9))
        set variable(targetid,ctr+9)
      )
      else
      (
        if (tempdist<>getallystat(ctr,hp)) then
        (
          #if new target is weaker than old target, attack him instead
          set variable(targetdist,tempdist)
          set variable(targethp,getallystat(ctr,hp))
          set variable(targetx,npcx(ctr+9))
          set variable(targety,npcy(ctr+9))
          set variable(targetid,ctr+9)
        )
      )
    )
  )
  #we just looked for Guests, but not heroes
  #time to look for Heroes!
  for (ctr,0,3,1) do
  (
    if (getherostat(ctr,stat:hp)>>0) then
    (
      setvariable(tempdist,abs(npcx(who--1)--herox(ctr))+abs(npcy(who--1)--heroy(ctr)))
      if (targetdist>>movement+range,and,targetdist>>tempdist) then
      (
        #if previous target is out of reach then select new target
        set variable(targetdist,tempdist)
        set variable(targethp,getherostat(ctr,stat:hp))
        set variable(targetx,herox(ctr))
        set variable(targety,heroy(ctr))
        set variable(targetid,ctr)
      )
      else
      (
        if (tempdist<>getherostat(ctr,stat:hp)) then
        (
          #if new target is weaker than old target and within range
          set variable(targetdist,tempdist)
          set variable(targethp,getherostat(ctr,stat:hp))
          set variable(targetx,herox(ctr))
          set variable(targety,heroy(ctr))
          set variable(targetid,ctr)
        )
      )
    )
  )
  if (targetdist<<50) then #if a target is selected, move in
  (
    variable(movctr)
    setvariable(movctr,0)
    setvariable(tempdist,targetdist)
    setvariable(lastmov,-1)
    while (movement>>0,and,tempdist>>range) do
    (
      set variable(offx,npcx(who--1))
      set variable(offy,npcy(who--1))
      if ((targetx<left) then
      (
        walk npc(who--1,left)
        set variable(lastmov,left)
      )
      else (if ((targety<up) then
      (
        walk npc(who--1,up)
        set variable(lastmov,up)
      )
      else (if ((targety>>npcy(who--1),or,(lastmov==left,and,random(1,5)==5),or,(lastmov==right,and,random(1,5)==5)),and,lastmov<>down) then
      (
        walk npc(who--1,down)
        set variable(lastmov,down)
      )
      else (if ((targetx>>npcx(who--1),or,(lastmov==up,and,random(1,5)==5),or,(lastmov==down,and,random(1,5)==5)),and,lastmov<>right) then
      (
        walk npc(who--1,right)
        set variable(lastmov,right)
      ))))
      if (movctr>>20) then (walknpc(who--1,random(0,3)))
      if (targetid<<10) then
      (setvariable(tempdist,abs(npcx(who--1)--herox(targetid))+abs(npcy(who--1)--heroy(targetid))))
      if (targetid>>9) then
      (setvariable(tempdist,abs(npcx(who--1)--npcx(targetid))+abs(npcy(who--1)--npcy(targetid))))
      decrement(movement)
      waitfornpc(who--1)
      if (npcx(who--1)==offx,and,npcy(who--1)==offy) then
      (
        increment(movement) #he didn't really move
        increment(movctr)
      )
      else
      (
        if ((lastmov==down,and,npcy(who--1)<>targety--1),or,
          (lastmov==left,and,npcx(who--1)>>targetx--1),or,
          (lastmov==right,and,npcx(who--1)<>abs(targety--npcy(who--1))) then
    (
      if (targetx<>npcx(who--1)) then (setnpcdirection(who--1,right) setvariable(offx,1))
    )
    else
    (
      if (targety<>npcy(who--1)) then (setnpcdirection(who--1,down) setvariable(offy,1))
    )

    #do another range check
    if (targetid<<10) then
     (setvariable(tempdist,abs(npcx(who--1)--herox(targetid))+abs(npcy(who--1)--heroy(targetid))))
    if (targetid>>9) then
     (setvariable(tempdist,abs(npcx(who--1)--npcx(targetid))+abs(npcy(who--1)--npcy(targetid))))

    if (tempdist<<(range+1)) then #attack!
    (
      #show and position the weapon
      set tag(2,on)
      set npc position (35,npcx(who--1)+offx,npcy(who--1)+offy)
      set npc direction (35,npcdirection(who--1))
      set npc frame(35,0)

      #change its appearance
      if (getenemystat(who,cls)==knight,or,getenemystat(who,cls)==tempus,or,getenemystat(who,cls)==gallus) then
      (
        alter npc(35,npcstat:picture,6)
        alter npc(35,npcstat:palette,1)
      )
      if (getenemystat(who,cls)==archer) then
      (
        alter npc(35,npcstat:picture,7)
        alter npc(35,npcstat:palette,17) #palette 17 is for enemy archers only
      )
      if (getenemystat(who,cls)==priest,or,getenemystat(who,cls)==wizard) then
      (
        alter npc(35,npcstat:picture,14)
        alter npc(35,npcstat:palette,0)
      )
      variable(damage)
      set variable(damage,getenemystat(who,str))
      if (range>>1) then #long-range atks need confusing line of fire algorithm
      (
        variable(slope)
        variable(direction)
        set variable(direction,npcdirection(35))
        alter npc(35,npcstat:movespeed,10)
        suspendobstruction
        set variable(offx,npcx(35)--targetx)
        set variable(offy,npcy(35)--targety)
        if (direction==left,or,direction==right) then
        (
          if (abs(offy)>>0) then (set variable(slope,abs(offx/offy))) else (set variable(slope,0))
          for (ctr,abs(offx),1,-1) do
          (
            walk npc(35,direction)
            if (slope>>0) then
            (if ((offx,mod,slope)==(slope/2)) then
            (if (offy>>0) then (walknpc(35,up)) else (walknpc(35,down))))
            waitfornpc(35)
          )
        )
        else
        (
          if (abs(offx)>>0) then (set variable(slope,abs(offy/offx))) else (set variable(slope,0))
          for (ctr,abs(offy),1,-1) do
          (
            walk npc(35,direction)
            if (slope>>0) then
            (if ((offy,mod,slope)==(slope/2)) then
            (if (offx>>0) then (walknpc(35,left)) else (walknpc(35,right))))
            waitfornpc(35)
          )
        )
        resumeobstruction #missile weapons go through walls!
      )
      setvariable(targetid,findchar(npcx(35),npcy(35)))
      if (targetid==0) then (set variable(damage,0))
      wait(3)
      set tag(3,on) #show damage
      set npc position(33,npcx(35),npcy(35))
      set variable(ctr,damage/10)
      if (ctr>>7) then (alternpc(33,npcstat:picture,16)) else (alternpc(33,npcstat:picture,15))
      set npc frame(33,(ctr,mod,2))
      set npc direction(33,((ctr/2),mod,4))
      set npc position(34,targetx,targety)
      set variable(ctr,damage--(ctr*10))
      if (ctr>>7) then (alternpc(34,npcstat:picture,18)) else (alternpc(34,npcstat:picture,17))
      set npc frame(34,(ctr,mod,2))
      set npc direction(34,((ctr/2),mod,4))
      set npc frame(35,1) #animate
      wait(8)
      damagechar(targetid,damage)
      set tag(2,off) #disappear
      set tag(3,off) #hide damage
      wait(1)
    )
  )
 )
 else
 (
  #find most damaged ally
  #this was supposed to be the Priest AI
 )
end

script,allyturn,who,begin #this is the same as the Enemy AI, but for Guests
 variable (movement)
 variable (ctr)
 variable (targetdist)
 variable (targethp)
 variable (targetx)
 variable (targety)
 variable (tempdist)
 variable (range)
 variable (targetid)
 variable (offx)
 variable (offy)
 variable (lastmov)
 focuscamera(npcx(who+9),npcy(who+9),10)
 waitforcamera
 camerafollowsnpc(who+9)
 set variable (targetdist,50)
 set variable (targethp,999)
 set variable (movement,getallystat(who,mov))
 set variable (range,getallystat(who,rng))
 if (getallystat(who,cls)==Wizard,and,getallystat(who,mp)>>1) then
   (set variable (range,5)) #he will use a spell if he can
 if (getallystat(who,cls)<>Priest) then
 (
  #find weakest enemy within range
  for (ctr,1,numenemies,1) do
  (
    if (getallystat(ctr,hp)>>0) then
    (
      setvariable(tempdist,abs(npcx(who--1)--npcx(ctr+9))+abs(npcy(who--1)--npcy(ctr+9)))
      if (targetdist>>movement+range,and,targetdist>>tempdist) then
      (
        #if previous target is out of reach then select new target
        set variable(targetdist,tempdist)
        set variable(targethp,getenemystat(ctr,hp))
        set variable(targetx,npcx(ctr--1))
        set variable(targety,npcy(ctr--1))
        set variable(targetid,ctr--1)
      )
      else
      (
        if (tempdist<>getenemystat(ctr,hp)) then
        (
          #new target is weaker than old target
          set variable(targetdist,tempdist)
          set variable(targethp,getenemystat(ctr,hp))
          set variable(targetx,npcx(ctr--1))
          set variable(targety,npcy(ctr--1))
          set variable(targetid,ctr--1)
        )
      )
    )
  )
  if (targetdist<<50) then #if a target is selected, move in
  (
    setvariable(tempdist,targetdist)
    setvariable(lastmov,-1)
    variable(movctr)
    while (movement>>0,and,tempdist>>range) do
    (
      set variable(offx,npcx(who+9))
      set variable(offy,npcy(who+9))
      if ((targetx<left) then
      (
        walk npc(who+9,left)
        set variable(lastmov,left)
      )
      else (if ((targety<up) then
      (
        walk npc(who+9,up)
        set variable(lastmov,up)
      )
      else (if ((targety>>npcy(who+9),or,(lastmov==left,and,random(1,5)==5),or,(lastmov==right,and,random(1,5)==5)),and,lastmov<>down) then
      (
        walk npc(who+9,down)
        set variable(lastmov,down)
      )
      else (if ((targetx>>npcx(who+9),or,(lastmov==up,and,random(1,5)==5),or,(lastmov==down,and,random(1,5)==5)),and,lastmov<>right) then
      (
        walk npc(who+9,right)
        set variable(lastmov,right)
      ))))
      if (movctr>>20) then (walknpc(who+9,random(0,3)))
      setvariable(tempdist,abs(npcx(who+9)--npcx(targetid))+abs(npcy(who+9)--npcy(targetid)))
      decrement(movement)
      waitfornpc(who+9)
      if (npcx(who+9)==offx,and,npcy(who+9)==offy) then
      (
        increment(movement) #he didn't really move
        increment(movctr)
      )
      else
      (
        if ((lastmov==down,and,npcy(who+9)<>targety--1),or,
          (lastmov==left,and,npcx(who+9)>>targetx--1),or,
          (lastmov==right,and,npcx(who+9)<>abs(targety--npcy(who+9))) then
    (
      if (targetx<>npcx(who+9)) then (setnpcdirection(who+9,right) setvariable(offx,1))
    )
    else
    (
      if (targety<>npcy(who+9)) then (setnpcdirection(who+9,down) setvariable(offy,1))
    )

    #do another range check
    setvariable(tempdist,abs(npcx(who+9)--npcx(targetid))+abs(npcy(who+9)--npcy(targetid)))

    if (tempdist<<(range+1)) then #attack!
    (
      #show and position the weapon
      set tag(2,on)
      set npc position (35,npcx(who+9)+offx,npcy(who+9)+offy)
      set npc direction (35,npcdirection(who+9))
      set npc frame(35,0)

      #change its appearance
      if (getallystat(who,cls)==knight,or,getallystat(who,cls)==tempus,or,getallystat(who,cls)==gallus) then
      (
        alter npc(35,npcstat:picture,6)
        alter npc(35,npcstat:palette,1)
      )
      if (getallystat(who,cls)==archer) then
      (
        alter npc(35,npcstat:picture,7)
        alter npc(35,npcstat:palette,27) #palette 27 is for ally archers only
      )
      if (getallystat(who,cls)==priest,or,getallystat(who,cls)==wizard) then
      (
        alter npc(35,npcstat:picture,14)
        alter npc(35,npcstat:palette,0)
      )
      variable(damage)
      set variable(damage,getallystat(who,str))
      if (range>>1) then #long-range atks need line of fire algorithm
      (
        variable(slope)
        variable(direction)
        set variable(direction,npcdirection(35))
        alter npc(35,npcstat:movespeed,10)
        suspendobstruction
        set variable(offx,npcx(35)--targetx)
        set variable(offy,npcy(35)--targety)
        if (direction==left,or,direction==right) then
        (
          if (abs(offy)>>0) then (set variable(slope,abs(offx/offy))) else (set variable(slope,0))
          for (ctr,abs(offx),1,-1) do
          (
            walk npc(35,direction)
            if (slope>>0) then
            (if ((offx,mod,slope)==(slope/2)) then
            (if (offy>>0) then (walknpc(35,up)) else (walknpc(35,down))))
            waitfornpc(35)
          )
        )
        else
        (
          if (abs(offx)>>0) then (set variable(slope,abs(offy/offx))) else (set variable(slope,0))
          for (ctr,abs(offy),1,-1) do
          (
            walk npc(35,direction)
            if (slope>>0) then
            (if ((offy,mod,slope)==(slope/2)) then
            (if (offx>>0) then (walknpc(35,left)) else (walknpc(35,right))))
            waitfornpc(35)
          )
        )

        resumeobstruction
      )
      set variable(targetid,findchar(npcx(35),npcy(35)))
      if (targetid==0) then (set variable(damage,0))
      wait(3)
      set tag(3,on) #show damage
      set npc position(33,npcx(35),npcy(35))
      set variable(ctr,damage/10)
      if (ctr>>7) then (alternpc(33,npcstat:picture,16)) else (alternpc(33,npcstat:picture,15))
      set npc frame(33,(ctr,mod,2))
      set npc direction(33,((ctr/2),mod,4))
      set npc position(34,targetx,targety)
      set variable(ctr,damage--(ctr*10))
      if (ctr>>7) then (alternpc(34,npcstat:picture,18)) else (alternpc(34,npcstat:picture,17))
      set npc frame(34,(ctr,mod,2))
      set npc direction(34,((ctr/2),mod,4))
      set npc frame(35,1) #animate
      wait(8)
      damagechar(targetid,damage)
      set tag(2,off) #disappear
      set tag(3,off) #hide damage
      wait(1)
    )
  )
 )
 else
 (
  #find most damaged ally
 )
end

script,heroturn,who,begin 
 variable(choice)
 variable(canwalk)
 variable(canact)
 variable(notdone)
 setvariable(canwalk,true)
 setvariable(canact,true)
 setvariable(notdone,true)
 focuscamera(herox(who),heroy(who),10)
 waitforcamera
 camerafollowshero(who)
 while((canwalk,or,canact),and,notdone) do
 (
   set tag(5,on) #tag 5 makes menu icons appear
   setvariable(choice(showicons(who)))
   set tag(5,off)
   if (choice==up,and,canwalk) #walk
   then (dowalk(who) setvariable(canwalk,false))
   else (if (choice==down) #end turn
   then (setvariable(notdone,false))
   else (if (choice==left,and,canact) #attack
   then (if (choosetarget(who,getherostat(who,stat:Rng))) then (set variable(canact,false))
   )))
   waitforhero(who)
 )
 if (canwalk) then (setheroat(who+1,getheroat(who+1)+25))
 if (canact) then (setheroat(who+1,getheroat(who+1)+25))
 choosedir(who)
 wait(1)
end

script,showicons,who,begin #this is the basic menu
 variable(ctr)
 variable(choice)
 set hero direction(who,down)
 set variable(choice,down)
 set npc position(20,herox(who)+1,heroy(who))
 set npc position(21,herox(who)--1,heroy(who))
 set npc position(22,herox(who),heroy(who)--1)
 set npc position(23,herox(who),heroy(who)+1)
 set npc direction(20,left)
 set npc direction(21,up)
 set npc direction(22,right)
 set npc direction(23,down)
 while (keyispressed(28),or,keyispressed(29),or,
  keyispressed(57)) do (wait(2)) #clear keypress buffer
 while (keyispressed(28)==false,and,keyispressed(29)==false,and,
  keyispressed(57)==false) do #check all usekeys!
 (
   increment(ctr)
   if (ctr==10) then
   (
     for(ctr,20,23,1) do
     (
       set npc frame(ctr,1)
     )
     set variable(ctr,10)
   )
   if (ctr==20) then
   (
     for(ctr,20,23,1) do
     (
       set npc frame(ctr,0)
     )
     set variable(ctr,0)
   )
   if (keyispressed(75)) then (setherodirection(who,left) setvariable(choice,left))
   if (keyispressed(77)) then (setherodirection(who,right) setvariable(choice,right))
   if (keyispressed(80)) then (setherodirection(who,down) setvariable(choice,down))
   if (keyispressed(72)) then (setherodirection(who,up) setvariable(choice,up))
   wait(1)
 )
 return(choice)
end

script,dowalk,who,begin #this lets the character walk within his Move range
 suspend box advance
 show text box(13)
 variable(steps)
 variable(oldx)
 variable(oldy)
 setvariable(steps,getherostat(who,stat:Move))
 while (steps>>0,and,keyispressed(1)==false) do #quit walking with Esc
 (
   setvariable(oldx,herox(who))
   setvariable(oldy,heroy(who))
   waitforkey(anykey)
   showvalue(steps)
   if (keyispressed(75)) then (walkhero(who,left))
   if (keyispressed(77)) then (walkhero(who,right))
   if (keyispressed(80)) then (walkhero(who,down))
   if (keyispressed(72)) then (walkhero(who,up))
   waitforhero(who)
   if (oldx<>herox(who),or,oldy<>heroy(who)) then (decrement(steps))
   showvalue(steps)
 )
 shownovalue
 advance text box
 resume box advance
end

script,choosedir,who,begin #lets player choose direction at the end of a turn
 showtextbox(12)
 suspend box advance
 while (keyispressed(28),or,keyispressed(29),or,
  keyispressed(57)) do (wait(2)) #clear keypress buffer
 while (keyispressed(28)==false,and,keyispressed(29)==false,and,
  keyispressed(57)==false) do #check all usekeys!
 (
   if (keyispressed(75)) then (setherodirection(who,left))
   if (keyispressed(77)) then (setherodirection(who,right))
   if (keyispressed(80)) then (setherodirection(who,down))
   if (keyispressed(72)) then (setherodirection(who,up))
   wait(1)
 )
 advance text box
 resume box advance
)

script,choosetarget,who,range,begin #lets player choose a target within a range
 suspendobstruction
 suspendnpcwalls
 variable(inrange)
 variable(offx)
 variable(offy)
 variable(dir)
 variable(ctr)
 set variable(inrange,true)
 set tag(4,on) #show cursor
 alternpc(32,npcstat:palette,8)
 set npc position(32,herox(who),heroy(who))
 wait(2)
 while (keyispressed(28),or,keyispressed(29),or,
  keyispressed(57)) do (wait(2)) #clear keypress buffer
 while ((keyispressed(28)==false,and,keyispressed(29)==false,and,
  keyispressed(57)==false),or,inrange==false,and,keyispressed(1)==false) do
 (
   if (keyispressed(75)) then (walknpc(32,left))
   if (keyispressed(77)) then (walknpc(32,right))
   if (keyispressed(80)) then (walknpc(32,down))
   if (keyispressed(72)) then (walknpc(32,up))
   if (abs(npcx(32)--herox(who))+abs(npcy(32)--heroy(who))>>range) then
   (
     setvariable(inrange,false)
     alternpc(32,npcstat:palette,2)
   )
   else
   (
     setvariable(inrange,true)
     alternpc(32,npcstat:palette,8)
   )
   if (abs(npcx(32)--herox(who))>>abs(npcy(32)--heroy(who))) then
   (
     if (npcx(32)<<>0) then
 (
   if (dir==left,or,dir==right) then
   (
    if (abs(offy)>>0) then (set variable(slope,abs(offx/offy))) else (set variable(slope,0))
    for (ctr,abs(offx),1,-1) do
    (
      walk npc(35,dir)
      if (slope>>0) then
        (if ((offx,mod,slope)==(slope/2)) then
        (if (offy>>0) then (walknpc(35,up)) else (walknpc(35,down))))
        waitfornpc(35))
      )
      else
      (
        if (abs(offx)>>0) then (set variable(slope,abs(offy/offx))) else (set variable(slope,0))
        for (ctr,abs(offy),1,-1) do
        (
          walk npc(35,dir)
          if (slope>>0) then
          (if ((offy,mod,slope)==(slope/2)) then
          (if (offx>>0) then (walknpc(35,left)) else (walknpc(35,right))))
          waitfornpc(35)
        )
   )
   resumeobstruction
 )
 variable(targetid)
 set variable(targetid,findchar(npcx(35),npcy(35)))
 if (targetid==0) then (set variable(damage,0))
 wait(3)
 set tag(3,on) #show damage
 set npc position(33,npcx(35),npcy(35))
 set variable(ctr,damage/10)
 if (ctr>>7) then (alternpc(33,npcstat:picture,16)) else (alternpc(33,npcstat:picture,15))
 set npc frame(33,(ctr,mod,2))
 set npc direction(33,((ctr/2),mod,4))
 set npc position(34,targetx,targety)
 set variable(ctr,damage--(ctr*10))
 if (ctr>>7) then (alternpc(34,npcstat:picture,18)) else (alternpc(34,npcstat:picture,17))
 set npc frame(34,(ctr,mod,2))
 set npc direction(34,((ctr/2),mod,4))
 set npc frame(35,1) #animate
 wait(8)
 damagechar(targetid,damage)
 set tag(2,off) #disappear
 set tag(3,off) #hide damage
 wait(1)
 resume obstruction
 resume npc walls
 return (true)
 )
 else (resume obstruction
 resume npc walls
 set tag(2,off)
 return(false))
end


Site layout (c)2000 Jennifer Raby. Used by permission.