Wheelerm
09-22-2024, 06:16 PM
I'm working on a script that will automatically target critters in the priority order listed. I'm trying to leverage the same logic that ;wander <critter> uses, which only stops for the named critter.
Here's a quick description of what I want it to do:
>;target viper
Script will constantly scan the room and look for vipers entering the room. When one enters, script will automatically target the viper. If in the middle of battle with some other critter when the viper enters, the script will force targeting of the viper for the next attack.
>;target <critter 1> <critter 2> ... <critter n>
Script will target <critter 1> as the highest priority, <critter 2> will be next priority, etc. Any other critters who enter the room (that are not specifically listed) are of no priority and the script will do nothing (i.e., simple game mechanics chooses the next target).
Since this script will be running while hunting, it's important that when the room changes, the targeting system is cleared. This is so that if one is fighting <critter 1> and decides to flee the room (or is otherwise removed from the room [e.g., had fear cast on them]), the targeting system doesn't try to continue to target <critter 1> in the next room, which might prevent the script from actually targeting the next-highest priority critter in the new room if <critter 1> does not exist in this new room.
I think I've reached the end of my limited scripting abilities, so I'm asking for help to bring this home. Below is what I have so far. I have not attempted to implement the paragraph immediately above yet.
CharSettings['critters'] ||= Array.new
CharSettings['untargetable'] ||= Array.new
CharSettings['targetable'] ||= Array.new
if script.vars[1] =~ /help/i
output = "\n"
output.concat ";target <critter1> <critter2> targets critters in the order listed\n"
output.concat ";target list shows saved critter list info in priority order\n"
output.concat ";target clear clears the critter list\n"
output.concat "\n"
respond output
elsif script.vars[1] =~ /^list$/i
output = "\n"
if CharSettings['critters'].empty?
output.concat " critters: none\n"
else
output.concat " critters:\n"
for critters in CharSettings['critters']
output.concat " #{critters.to_s.rjust(5)} #{Room[critters].title.first}\n"
end
end
output.concat "\n"
if CharSettings['targetable'].empty?
output.concat " targetable npcs: none\n"
else
output.concat " targetable npcs: #{CharSettings['targetable'].join(', ')}\n"
end
output.concat "\n"
if CharSettings['untargetable'].empty?
output.concat " untargetable npcs: none\n"
else
output.concat " untargetable npcs: #{CharSettings['untargetable'].join(', ')}\n"
end
output.concat "\n"
respond output
elsif script.vars[1] =~ /^clear$/i
CharSettings['critters'] = Array.new
CharSettings['untargetable'] = Array.new
CharSettings['targetable'] = Array.new
respond 'done'
elsif script.vars.empty?
loop {
critters.call
start_npcs = npcs = GameObj.npcs
npcs.delete_if { |npc| (npc.status =~ /dead/) or CharSettings['untargetable'].include?(npc.name) }
if npcs.nil? or npcs.empty?
sleep CharSettings['delay']
elsif npcs.any? { |npc| CharSettings['targetable'].include?(npc.name) }
break
else
clear
target_result = dothistimeout 'target random', 5, /^Could not find a valid target\.$|^You are now targeting/
if target_result =~ /^You are now targeting \w+ (.*)\.$/
target = $1
CharSettings['targetable'].push(target) unless CharSettings['targetable'].include?(target)
break
elsif target_result == 'Could not find a valid target.'
if GameObj.npcs == start_npcs
npcs.each { |npc| CharSettings['untargetable'].push(npc.name) unless CharSettings['untargetable'].include?(npc.name) }
end
sleep CharSettings['delay']
end
end
}
else
loop {
group = checkpcs.to_a
critters.call
group = group & checkpcs.to_a
group.push(Char.name)
if GameObj.pcs.any? { |pc| pc.noun =~ /#{script.vars[1..-1].join('|')}/i }
break
elsif ((checkpcs.to_a - group).length > 0) or GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) }
sleep CharSettings['delay']
elsif GameObj.npcs.any? { |npc| (npc.status != 'dead') and npc.name =~ /#{script.vars[1..-1].join('|')}/ }
break
else
sleep CharSettings['delay']
end
}
end
Here's a quick description of what I want it to do:
>;target viper
Script will constantly scan the room and look for vipers entering the room. When one enters, script will automatically target the viper. If in the middle of battle with some other critter when the viper enters, the script will force targeting of the viper for the next attack.
>;target <critter 1> <critter 2> ... <critter n>
Script will target <critter 1> as the highest priority, <critter 2> will be next priority, etc. Any other critters who enter the room (that are not specifically listed) are of no priority and the script will do nothing (i.e., simple game mechanics chooses the next target).
Since this script will be running while hunting, it's important that when the room changes, the targeting system is cleared. This is so that if one is fighting <critter 1> and decides to flee the room (or is otherwise removed from the room [e.g., had fear cast on them]), the targeting system doesn't try to continue to target <critter 1> in the next room, which might prevent the script from actually targeting the next-highest priority critter in the new room if <critter 1> does not exist in this new room.
I think I've reached the end of my limited scripting abilities, so I'm asking for help to bring this home. Below is what I have so far. I have not attempted to implement the paragraph immediately above yet.
CharSettings['critters'] ||= Array.new
CharSettings['untargetable'] ||= Array.new
CharSettings['targetable'] ||= Array.new
if script.vars[1] =~ /help/i
output = "\n"
output.concat ";target <critter1> <critter2> targets critters in the order listed\n"
output.concat ";target list shows saved critter list info in priority order\n"
output.concat ";target clear clears the critter list\n"
output.concat "\n"
respond output
elsif script.vars[1] =~ /^list$/i
output = "\n"
if CharSettings['critters'].empty?
output.concat " critters: none\n"
else
output.concat " critters:\n"
for critters in CharSettings['critters']
output.concat " #{critters.to_s.rjust(5)} #{Room[critters].title.first}\n"
end
end
output.concat "\n"
if CharSettings['targetable'].empty?
output.concat " targetable npcs: none\n"
else
output.concat " targetable npcs: #{CharSettings['targetable'].join(', ')}\n"
end
output.concat "\n"
if CharSettings['untargetable'].empty?
output.concat " untargetable npcs: none\n"
else
output.concat " untargetable npcs: #{CharSettings['untargetable'].join(', ')}\n"
end
output.concat "\n"
respond output
elsif script.vars[1] =~ /^clear$/i
CharSettings['critters'] = Array.new
CharSettings['untargetable'] = Array.new
CharSettings['targetable'] = Array.new
respond 'done'
elsif script.vars.empty?
loop {
critters.call
start_npcs = npcs = GameObj.npcs
npcs.delete_if { |npc| (npc.status =~ /dead/) or CharSettings['untargetable'].include?(npc.name) }
if npcs.nil? or npcs.empty?
sleep CharSettings['delay']
elsif npcs.any? { |npc| CharSettings['targetable'].include?(npc.name) }
break
else
clear
target_result = dothistimeout 'target random', 5, /^Could not find a valid target\.$|^You are now targeting/
if target_result =~ /^You are now targeting \w+ (.*)\.$/
target = $1
CharSettings['targetable'].push(target) unless CharSettings['targetable'].include?(target)
break
elsif target_result == 'Could not find a valid target.'
if GameObj.npcs == start_npcs
npcs.each { |npc| CharSettings['untargetable'].push(npc.name) unless CharSettings['untargetable'].include?(npc.name) }
end
sleep CharSettings['delay']
end
end
}
else
loop {
group = checkpcs.to_a
critters.call
group = group & checkpcs.to_a
group.push(Char.name)
if GameObj.pcs.any? { |pc| pc.noun =~ /#{script.vars[1..-1].join('|')}/i }
break
elsif ((checkpcs.to_a - group).length > 0) or GameObj.loot.find { |obj| (obj.noun == 'disk') and (obj.name !~ /#{group.join('|')}/) }
sleep CharSettings['delay']
elsif GameObj.npcs.any? { |npc| (npc.status != 'dead') and npc.name =~ /#{script.vars[1..-1].join('|')}/ }
break
else
sleep CharSettings['delay']
end
}
end