PDA

View Full Version : Simple brawling script to use with Bigshot



Saurven
09-10-2014, 10:13 PM
I'm missing something.
I'm trying to get this script to pick a target, hold it until it's killed, and exit. The problem is that this script performs perfectly, except for the exiting.
If no NPC is in the room, it'll instantly exit. No trying to hide or anything. If there is an NPC, it performs the brawling section flawlessly. Once the critter is dead, even if there's only 1 critter in the room, it hides again and attempts to punch.
I added the command to exit - if /^You currently have no valid target/ - because my ongoing .status check is FUBAR.
What am I screwing up in this?
I tried making it just one def, with:

def vstrike
If GameObj.npc.find { |thing| thing.status !~ /dead/}
**the rest of the def, after the $vtarg line**
else
exit

That didn't work, so I came up with the complicated crap that still isn't working.


$vpunch = "Strike leaves foe vulnerable to a followup punch"
$vkick = "Strike leaves foe vulnerable to a followup kick"
$vgrapple = "Strike leaves foe vulnerable to a followup grapple"
$vjab = "Strike leaves foe vulnerable to a followup jab"
$currentattack = "punch"
$vtarg = []

def martial_start
mytargs = GameObj.npcs.find_all{ |jackals| jackals.status !~ /dead|gone/ }
if mytargs.size > 0
$targ.push(mytargs.last)
vstrike
else
exit
end
end

def vstrike
if $vtarg.status !~ /dead|gone/
waitrt?
fput "stance def"
fput "hide"
waitrt?
fput "stance off"
result = dothistimeout "#{$currentattack}", 5, /#{$vpunch}|#{$vkick}|#{$vgrapple}|#{$vjab}|^Roundt ime|^You currently have no valid target/
if result =~ /#{$vpunch}/
waitrt?
$currentattack = "punch"
vstrike
elsif result =~ /#{$vkick}/
waitrt?
$currentattack = "kick"
vstrike
elsif result =~ /#{$vgrapple}/
waitrt?
$currentattack = "grapple"
vstrike
elsif result =~ /#{$vjab}/
waitrt?
$currentattack = "jab"
vstrike
elsif result =~ /^Roundtime/
$currentattack = "punch"
vstrike
elsif result =~ /^You currently have no valid target/
exit
end
elsif $vtarg.status =~ /^dead|gone/
exit
end
end

martial_start

Saurven
09-10-2014, 10:19 PM
I should point out that with the script the way it is, if I'm attacking something, and another critter comes in, instead of exiting after Critter.last is dead, it just starts right in attacking the next one that entered. Since I'm hunting for boxes at the moment, to please DeLuca and the other blood-thirsty savages, it makes looting a bit difficult. Defeating the purpose.

Saurven
09-10-2014, 10:52 PM
Nevermind. I finally remembered how I did that. I'm a moron sometimes.


$vpunch = "Strike leaves foe vulnerable to a followup punch"
$vkick = "Strike leaves foe vulnerable to a followup kick"
$vgrapple = "Strike leaves foe vulnerable to a followup grapple"
$vjab = "Strike leaves foe vulnerable to a followup jab"
$currentattack = "punch"

def vstrike
exit if GameObj.npcs.find{ |jackals| jackals.status =~ /^dead/}
waitrt?
fput "stance def"
fput "hide"
waitrt?
fput "stance off"
result = dothistimeout "#{$currentattack}", 5, /#{$vpunch}|#{$vkick}|#{$vgrapple}|#{$vjab}|^Roundt ime|^You currently have no valid target/
if result =~ /#{$vpunch}/
waitrt?
$currentattack = "punch"
vstrike
elsif result =~ /#{$vkick}/
waitrt?
$currentattack = "kick"
vstrike
elsif result =~ /#{$vgrapple}/
waitrt?
$currentattack = "grapple"
vstrike
elsif result =~ /#{$vjab}/
waitrt?
$currentattack = "jab"
vstrike
elsif result =~ /^Roundtime/
$currentattack = "punch"
vstrike
elsif result =~ /^You currently have no valid target/
exit
end
end

vstrike

DaCapn
09-11-2014, 12:55 AM
It sounds like you have this working for you but I just wanted to throw a couple things out there:
(1) Calling a function from within itself is a bit worry-some. You may want to just set up this script with a downstream hook (or just have it loop getting lines as a helper script) and set the $currentattack global variable. I don't see an actual attack command being sent...
(2) A hash would be a great data type to use since it can keep pieces of data paired in something array-like. That is, you have "punch" as a key linked with the "punch message" value (similary for "kick", "grapple", "jab") and you have all of these key/value pairs lumped together into a single variable. The flexibility and compactness is shown below.

Combining these two ideas roughly, the second block you posted basically compacts down to this (with a couple minor details/messages omitted):


messages = {
"punch" => "punch message"
"kick" => "kick message"
}

joinedmessages = messages.values.join("|")

while line = get
if line =~ /#{joinedmessages}/
messages.each { |key,value|
if result =~ /#{value}/
waitrt?
$currentattack = key
end
}
end
end