PDA

View Full Version : Lich script tries to poach despite safeguards (Wizard)



Renian
03-18-2008, 05:17 AM
So despite the fact that I had a reliable safeguard (at least, it's reliable in SF), my script's trying to poach dudes every so often.



[huntotf2]>north
>
[Old Ta'Faendryl, Basilica Plaza]
To the east a series of wide stone steps lead up the side of a pyramid. A palatial building awaits at the top of the stairs, towering above the ruins of the surrounding city. In the river to the west, partially submerged in the water, can be seen a carved obsidian statue fashioned in the image of a massive warrior. The tip of a thick obsidian spear rests among the bulrush growing along the edge of the river bank. You also see a war griffin that is flying around, some silver coins and a twisted crystal-tipped staff.
Also here: Great Lord Wecodean
Obvious paths: north, south
[huntotf2]>aim right eye
>
A wrathful crevasse spirit floats in, following Wecodean.
[huntotf2]>stance offensive
>
You're now aiming at the right eye of your target when using a ranged weapon, or while ambushing.
>
You are now in an offensive stance.
[huntotf2]>get 1 arrow from my backpack
>
Wecodean chants a reverent litany and clasps his hands while tightly focusing his thoughts...
Wecodean gestures at a war griffin.
A single dim, crystal green globe springs to life in Wecodean's left hand. The globe leaps from Wecodean's left hand and dances through the air toward a war griffin!
CS: +503 - TD: +403 + CvA: +25 + d100: +91 == +216
Warding failed!
The orb squarely impacts a war griffin, discharging the crystal green energy over its entire being for 85 points of damage!
The crystal green energy pulses for an additional 59 points of damage ...
The war griffin crashes to the ground, motionless.
... the remaining energy dissipates harmlessly from the griffin's corpse.

>
You remove a single arrow from a bundle of arrows.
[huntotf2]>fire griffin
>
A war griffin is quite dead already.
[huntotf2]>put my arrow in my arrows in my backpack
>
You add an arrow to your bundle.
[huntotf2]>loot
>


Here's the script. The problem likely lies in the huntotf2 subroutine. I made the script into a class because I'm probably going to optimize it so it's good by programming standards.



$i = 0
$return = false

class Huntotf

def initialize
end

load "scripts/lootfunc.lic"

def tablecheck
if checkroom =~ /Table/i
move "out"
move "out"
tootf()
end
if checkroom =~ /[Ta'Faendryl Approach]/i
bounty()
huntotf()
end
end

def tootf
fput "ready weapon"
fput "tootf"
matchwait "Cannot follow"
fput "go water"
fput "swim east"
sleep 6
signs()
bounty()
fput "tootf"
matchwait "Reached destination"
huntotf()
end

def fromotf
fput "tavern"
matchwait "Cannot follow"
fput "go water"
fput "swim west"
sleep 6
fput "tavern"
matchwait "Reached destination"
move "go tavern"
fput "go tiad table"
fput "go tiad table"
fput "tap tiad"
unbox()
exit
end

def bounty
fput "bounty"
bountycheck = matchtimeout 3, "ithzir adept", "ithzir janissary", "ithzir seer", "ithzir initiate", "war griffin"
if bountycheck =~ /ithzir adept/i
$bounty = true
$bountytarget = "adept"
elsif bountycheck =~ /ithzir janissary/i
$bounty = true
$bountytarget = "janissary"
elsif bountycheck =~ /ithzir seer/i
$bounty = true
$bountytarget = "seer"
elsif bountycheck =~ /ithzir initiate/i
$bounty = true
$bountytarget = "initiate"
elsif bountycheck =~ /war griffin/i
$bounty = true
$bountytarget = "griffin"
else
$bounty = false
end
end

def signs
fput "sign of swords"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of smiting"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of striking"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of shields"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of defending"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of warding"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of staunching"
matchtimeout 1, "veins throb"
fput "sign of dissipation"
sleep 1
fput "sign of deflection"
sleep 1
end

def arrowmobs
fput "aim right eye"
aim = "right"
target_line = "null"
fighting = false
if checknpcs.length >= 1 && $target =~ /adept|griffin|initiate|seer|janissary/i && $invalidmob == false && checknpcs.length <= 2 && $return == false && percenthealth > 70
fighting = true
end
while checknpcs.length >= 1 && $target =~ /adept|griffin|initiate|seer|janissary/i && $invalidmob == false && checknpcs.length <= 2 && $return == false && percenthealth > 70
if stance != "offensive"
fput "stance offensive"
matchtimeout 2, "You are now in an offensive stance"
end
arrowcheck()
fput "fire " + $target
target_line = matchtimeout 2, "dies", "But it is dead!", "You are still stunned",
"Sorry, you can only have", "You have completed this portion", "Roundtime",
"falls prone to the ground, twitches one last time and dies." , "What were you referring to?",
"is already dead", "quite dead already", "leaving you firing at nothingness", "I could not find", "You cannot fire a bundle of arrows",
"crashes to the ground, motionless", "falls to the ground in a crumpled heap", "falls, the life fading from",
"vainly struggles to rise, then goes still.", "then collapses.", "You are too injured to fire that"
if target_line =~ /Roundtime/i
sleep 2
waitrt?
end
if target_line =~ /dies|But it is dead!|You have completed this portion of your|vainly struggles to rise, then goes still.|falls prone to the ground, twitches one last time and dies.|is already dead|quite dead already|crashes to the ground, motionless|falls to the ground in a crumpled heap|falls, the life fading from|then collapses./i
if target_line =~ /is already dead|quite dead already/
fput "put my arrow in my arrows in my backpack"
arrowd = matchtimeout 2, "I could not find", "You bundle", "You add an arrow"
if arrowd =~ /I could not find/
fput "put my arrow in my backpack"
end
end
waitrt?
loot()
gather()
if target_line =~ /You have completed this portion of your/i
$bounty = false
end
checkmobs()
end
if target_line =~ /You cannot fire a bundle of arrows/
fput "put my arrows in my backpack"
end

if target_line =~ /What were you referring to?|leaving you firing at nothingness|I could not find/i
gather()
$invalidmob = true
end
if target_line =~ /You are too injured to fire that/i
gather()
$return = true
fromotf()
end
while standing? == false
sleep 1
if stance != "defensive"
fput "stance defensive"
matchtimeout 2, "You are now in a defensive stance", "You are still stunned", "...wait"
end
fput "stand"
matchtimeout 2, "You stand back up", "You are still stunned", "You struggle", "...wait"
end
if aim == "right"
fput "aim left eye"
aim = "left"
else
fput "aim right eye"
aim = "right"
end
end
if fighting == true
gather()
end
end

def arrowcheck
fput "get 1 arrow from my backpack"
target_line = matchtimeout 2, "You remove", "light fades", "Get what?"
if target_line =~ /light fades/
fput "drop my arrow"
$return = true
fromotf()
end
if target_line =~ /Get what?/
fput "get my arrows from my cloak"
target_line = matchtimeout 2, "You remove", "Get what?"
if target_line =~ /You remove/
fput "put my arrows in my backpack"
arrowcheck()
else
$return = true
fromotf()
end
end
end

def gather
if stance != "defensive"
fput "stance defensive"
matchtimeout 1, "defensive stance"
end
fput "gather arrow"
target_line = matchtimeout 2, "You may only gather", "You pick up the arrow", "You gather", "You see nothing identical enough to the arrow to bundle with it"
if target_line =~ /You pick up the arrow|You gather|You see nothing identical enough to the arrow to bundle with it/
fput "put my arrow in my arrows in my backpack"
target_line = "I could not find", "You bundle some arrows together", "You cannot bundle", "You add an arrow"
if target_line =~ /I could not find/
fput "put my arrows in my backpack"
end
if target_line =~ /You cannot bundle/
fput "drop my arrow"
end
end
end

def huntotf
$i = 0
$movearray = [ne, ne, ne, n, n, n, n, e, e, e, e, ne, ne, ne, ne, n, sw, e, n, nw, w, w, e, s, s, s, se, w, w, sw, s, w, w, n, n, n, n, "go steps",
n, "go spear", w, w, w, "go foot", s, w, sw, ne, e, n, w, w, w, w, w, e, e, e, e, e, n, nw, n, ne, e, s, s, s, "go foot", e, e, e, "go spear",
n, n, e, e, e, s, ne, se, s, sw, nw, s, w, w, w, "go steps", s, s, s, s, s, s, s, s, sw, sw, sw]
while checkmind != "fried" && percenthealth >= 50 && $return == false
$invalidmob = false
move $movearray[$i]
$i = $i + 1
if $i == $movearray.length
$i = 0
end
matchtimeout 2, "Obvious paths", "Obvious exits"
checknpcs.length >= 1 && checknpcs.length <= 2 && !(checkpcs.length > 0) && checkmind != "must rest" && $invalidmob == false && $return == false
checkmobs()
if $invalidmob == false && $target != "none"
arrowmobs()
#echo "Target acquired."
#echo "Unpause the script to continue"
#pause_script "huntotf"
end
end
fromotf()
end

def checkmobs
#echo "checking mobs"
$target = "none"
$invalidmob = false
checknpcs.each do |mob|
if (mob == "griffin" || mob == "seer" || mob == "initiate" || mob == "adept" || mob == "janissary") && $target == "none" #&& $bounty == false
$target = mob
#echo "target is now " + mob
elsif (mob == $bountytarget && $bounty == true)
$target = mob
#echo "Bounty target sighted. Target is now " + mob
end
if (mob != "griffin" && mob != "seer" && mob != "initiate" && mob != "adept" && mob != "janissary") && checknpcs.length >= 1 #&& $bounty == false
$invalidmob = true
#echo "Invalid target found"
elsif (mob != $bountytarget && $bounty == true)
$invalidmob = true
#echo "Invalid target found"
end
end
#echo "mobcheck complete"
end

end

Huntotf.new.tablecheck()

Renian
03-18-2008, 05:19 AM
Actually I just realized I don't have && !(checkpcs.length > 0) in the arrowmobs() subroutine, but it shouldn't even get there...

EDIT: Now I remember why I don't have it there. It's so that once I'm already there, someone doesn't walk in and cause me to move due to the nature of the while loop.

Shaelun
03-18-2008, 05:39 AM
Honestly, trying to follow nested loops and multiple levels of if/else branches without any sort of syntax highlighting or spacing just makes my eyes hurt.

Can you enclose the script in code tags instead of quote tags so that the formatting gets through? Or just upload the script or something...?

I can't even find the huntotf2 method that you mentioned. I see huntotf, but that's it.

BTW -- methods are any "function"-like "command" you declare using the def keyword. Is that what you mean when you say subroutine?

Oh, also... just from a quick scroll through the script, it looks as though you're calling methods infinitely without ever allowing the calls to "return" -- if you're going to do that, you need to use labels, not methods. Methods involve saving the "context" at the time of a call, so that it can be returned to, and there's a limit to how many can be saved. You'll eventually hit a "stack too large" error if I'm reading this right.

Renian
03-18-2008, 11:30 AM
Oh sorry. And thanks for the clarification about def statements and whatnot; I didn't realize they had a limit.
I also didn't know about the code tags.
Also, huntotf2 is the name of the script. Huntotf is the name of the problem method, supposedly.


$i = 0
$return = false

class Huntotf

def initialize
end

load "scripts/lootfunc.lic"

def tablecheck
if checkroom =~ /Table/i
move "out"
move "out"
tootf()
end
if checkroom =~ /[Ta'Faendryl Approach]/i
bounty()
huntotf()
end
end

def tootf
fput "ready weapon"
fput "tootf"
matchwait "Cannot follow"
fput "go water"
fput "swim east"
sleep 6
signs()
bounty()
fput "tootf"
matchwait "Reached destination"
huntotf()
end

def fromotf
fput "tavern"
matchwait "Cannot follow"
fput "go water"
fput "swim west"
sleep 6
fput "tavern"
matchwait "Reached destination"
move "go tavern"
fput "go tiad table"
fput "go tiad table"
fput "tap tiad"
unbox()
exit
end

def bounty
fput "bounty"
bountycheck = matchtimeout 3, "ithzir adept", "ithzir janissary", "ithzir seer", "ithzir initiate", "war griffin"
if bountycheck =~ /ithzir adept/i
$bounty = true
$bountytarget = "adept"
elsif bountycheck =~ /ithzir janissary/i
$bounty = true
$bountytarget = "janissary"
elsif bountycheck =~ /ithzir seer/i
$bounty = true
$bountytarget = "seer"
elsif bountycheck =~ /ithzir initiate/i
$bounty = true
$bountytarget = "initiate"
elsif bountycheck =~ /war griffin/i
$bounty = true
$bountytarget = "griffin"
else
$bounty = false
end
end

def signs
fput "sign of swords"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of smiting"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of striking"
matchtimeout 1, "repeating the sign", "renewed vigor"
fput "sign of shields"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of defending"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of warding"
matchtimeout 1, "repeating the sign", "web of protection"
fput "sign of staunching"
matchtimeout 1, "veins throb"
fput "sign of dissipation"
sleep 1
fput "sign of deflection"
sleep 1
end

def arrowmobs
if !(checkpcs.length > 0)
fput "aim right eye"
aim = "right"
target_line = "null"
fighting = false
if checknpcs.length >= 1 && $target =~ /adept|griffin|initiate|seer|janissary/i && $invalidmob == false && checknpcs.length <= 2 && $return == false && percenthealth > 70
fighting = true
end
while checknpcs.length >= 1 && $target =~ /adept|griffin|initiate|seer|janissary/i && $invalidmob == false && checknpcs.length <= 2 && $return == false && percenthealth > 70
if stance != "offensive"
fput "stance offensive"
matchtimeout 2, "You are now in an offensive stance"
end
arrowcheck()
fput "fire " + $target
target_line = matchtimeout 2, "dies", "But it is dead!", "You are still stunned",
"Sorry, you can only have", "You have completed this portion", "Roundtime",
"falls prone to the ground, twitches one last time and dies." , "What were you referring to?",
"is already dead", "quite dead already", "leaving you firing at nothingness", "I could not find", "You cannot fire a bundle of arrows",
"crashes to the ground, motionless", "falls to the ground in a crumpled heap", "falls, the life fading from",
"vainly struggles to rise, then goes still.", "then collapses.", "You are too injured to fire that"
if target_line =~ /Roundtime/i
sleep 2
waitrt?
end
if target_line =~ /dies|But it is dead!|You have completed this portion of your|vainly struggles to rise, then goes still.|falls prone to the ground, twitches one last time and dies.|is already dead|quite dead already|crashes to the ground, motionless|falls to the ground in a crumpled heap|falls, the life fading from|then collapses./i
if target_line =~ /is already dead|quite dead already/
fput "put my arrow in my arrows in my backpack"
arrowd = matchtimeout 2, "I could not find", "You bundle", "You add an arrow"
if arrowd =~ /I could not find/
fput "put my arrow in my backpack"
end
end
waitrt?
loot()
gather()
if target_line =~ /You have completed this portion of your/i
$bounty = false
end
checkmobs()
end
if target_line =~ /You cannot fire a bundle of arrows/
fput "put my arrows in my backpack"
end

if target_line =~ /What were you referring to?|leaving you firing at nothingness|I could not find/i
gather()
$invalidmob = true
end
if target_line =~ /You are too injured to fire that/i
gather()
$return = true
fromotf()
end
while standing? == false
sleep 1
if stance != "defensive"
fput "stance defensive"
matchtimeout 2, "You are now in a defensive stance", "You are still stunned", "...wait"
end
fput "stand"
matchtimeout 2, "You stand back up", "You are still stunned", "You struggle", "...wait"
end
if aim == "right"
fput "aim left eye"
aim = "left"
else
fput "aim right eye"
aim = "right"
end
end
if fighting == true
gather()
end
end
end

def arrowcheck
fput "get 1 arrow from my backpack"
target_line = matchtimeout 2, "You remove", "light fades", "Get what?"
if target_line =~ /light fades/
fput "drop my arrow"
$return = true
fromotf()
end
if target_line =~ /Get what?/
fput "get my arrows from my cloak"
target_line = matchtimeout 2, "You remove", "Get what?"
if target_line =~ /You remove/
fput "put my arrows in my backpack"
arrowcheck()
else
$return = true
fromotf()
end
end
end

def gather
if stance != "defensive"
fput "stance defensive"
matchtimeout 1, "defensive stance"
end
fput "gather arrow"
target_line = matchtimeout 2, "You may only gather", "You pick up the arrow", "You gather", "You see nothing identical enough to the arrow to bundle with it"
if target_line =~ /You pick up the arrow|You gather|You see nothing identical enough to the arrow to bundle with it/
fput "put my arrow in my arrows in my backpack"
target_line = "I could not find", "You bundle some arrows together", "You cannot bundle", "You add an arrow"
if target_line =~ /I could not find/
fput "put my arrows in my backpack"
end
if target_line =~ /You cannot bundle/
fput "drop my arrow"
end
end
end

def huntotf
$i = 0
$movearray = [ne, ne, ne, n, n, n, n, e, e, e, e, ne, ne, ne, ne, n, sw, e, n, nw, w, w, e, s, s, s, se, w, w, sw, s, w, w, n, n, n, n, "go steps",
n, "go spear", w, w, w, "go foot", s, w, sw, ne, e, n, w, w, w, w, w, e, e, e, e, e, n, nw, n, ne, e, s, s, s, "go foot", e, e, e, "go spear",
n, n, e, e, e, s, ne, se, s, sw, nw, s, w, w, w, "go steps", s, s, s, s, s, s, s, s, sw, sw, sw]
while checkmind != "fried" && percenthealth >= 50 && $return == false
$invalidmob = false
move $movearray[$i]
$i = $i + 1
if $i == $movearray.length
$i = 0
end
matchtimeout 2, "Obvious paths", "Obvious exits"
checknpcs.length >= 1 && checknpcs.length <= 2 && !(checkpcs.length > 0) && checkmind != "must rest" && $invalidmob == false && $return == false
checkmobs()
if $invalidmob == false && $target != "none"
arrowmobs()
#echo "Target acquired."
#echo "Unpause the script to continue"
#pause_script "huntotf"
end
end
fromotf()
end

def checkmobs
#echo "checking mobs"
$target = "none"
$invalidmob = false
checknpcs.each do |mob|
if (mob == "griffin" || mob == "seer" || mob == "initiate" || mob == "adept" || mob == "janissary") && $target == "none" #&& $bounty == false
$target = mob
#echo "target is now " + mob
elsif (mob == $bountytarget && $bounty == true)
$target = mob
#echo "Bounty target sighted. Target is now " + mob
end
if (mob != "griffin" && mob != "seer" && mob != "initiate" && mob != "adept" && mob != "janissary") && checknpcs.length >= 1 #&& $bounty == false
$invalidmob = true
#echo "Invalid target found"
elsif (mob != $bountytarget && $bounty == true)
$invalidmob = true
#echo "Invalid target found"
end
end
#echo "mobcheck complete"
end

end

Huntotf.new.tablecheck()

Shaelun
03-18-2008, 09:21 PM
Your problem may be as simple as Lich running the script faster than it makes sense for it to -- in Wizard, the arrival times & order of game lines is virtually written in stone. It isn't that reliable in SF, though, and to make a long story short, I wrote the prog initially only to be compatible with the Wizard. I think the script may be checking if anybody's in the room just a hair sooner than Lich is actually receiving the information about someone being there or not. Try sticking in just a little pause, e.g.


pause 0.2
... or something whenever you move rooms, and see if that does it.

One more tidbit: you don't need to explicitly declare the initialize method. A default constructor is provided if you don't specify one, so you can skip it unless you have some code you want executed whenever a new object of that class is constructed/instanciated. Or would it be spelled instantiated? Bah, who cares -- whenever an instance of that class is allocated, is what I mean.

Shaelun
03-18-2008, 10:31 PM
Yeah, uh, ignore my last post... I just noticed that on line 228 (in the huntotf method), you're missing an if I think. The line is:


checknpcs.length >= 1 && checknpcs.length <= 2 && !(checkpcs.length > 0) && checkmind != "must rest" && $invalidmob == false && $return == false

That's not actually doing anything. I mean it's executing, but you're not branching based on whether or not all that stuff is true/false.

Renian
03-19-2008, 04:41 PM
!
You're right! No wonder it's been doing wonky crap as well like aiming at a mob and then continuing on. $return must have been true and then it just kept staying in the while loop.
Thanks, Shaelun!