Log in

View Full Version : How do i cast a spell at each mob in the room...



Glaves
07-11-2019, 01:38 AM
I realize this is probably insanely simple but i am still fairly new to coding and I have been trying to write a script that will cast a spell once at each mob in the room and i am getting nowhere and I was hoping somebody could help me out. It will cast at the first target, then exits and doesn't continue on casting at the others.


GameObj.npcs.each { |mob|

if mob.status !=~ /dead|gone/
1.times {
fput "prep 917"
fput "cast ##{mob.id}"
waitcastrt?
waitrt?
}
end
}

If somebody could help me out it would be most appreciated.

Rjex
07-11-2019, 02:09 AM
if mob.status !~ /dead|gone/

Rjex
07-11-2019, 02:11 AM
GameObj.npcs.each { |mob|
if (mob.status !~ /dead|gone/)
Spell[917].cast("##{mob.id}") if Spell[917].affordable?
waitcastrt?
waitrt?
end
}

Talonhawke
07-11-2019, 02:18 AM
GameObj.npcs.each { |mob|
if mob.status !~ /dead|gone/ and mob.type =~ /\baggressive\b/
if Spell[917].affordable?
Spell[917].cast mob
waitcastrt?
waitrt?
end
end
}


Been away a while, so not sure if the aggressive is still needed or not to make sure you don't attack things you don't intend to.

Glaves
07-11-2019, 02:26 AM
THANK YOU BOTH! I added the aggressive tag to the code Rjex provided and it seems to be working great!!!

I was so close too.

Glaves
07-11-2019, 02:33 AM
Now i just need to figure out how to make it not include certain mobs and it'll be perfect

Glaves
07-11-2019, 02:55 AM
I got it! Seriously, thank you! Been trying to get this to work for a couple days now and it was driving me nuts. Very much appreciated.


GameObj.npcs.each { |mob|
if (mob.status !~ /dead|gone|flying/ && !['raptor'].include?(mob.noun) && mob.type =~ /\baggressive\b/)
Spell[917].cast("##{mob.id}") if Spell[917].affordable?
waitcastrt?
waitrt?
end
}

Donquix
07-11-2019, 10:59 AM
set a macro to: \xtarget next\rincant 917\r
tape the key down
go afk

come back fried with full wizard juice.

You're welcome.

Rjex
07-11-2019, 11:01 AM
Incidentally, wouldn't this be cleaner anyway?



GameObj.targets.each { |mob|
if (mob.status !~ /flying/)
Spell[917].cast("##{mob.id}") if Spell[917].affordable?
waitcastrt?
waitrt?
end
}


targets already filters out everything that's dead, gone, or familiar type

Glaves
07-11-2019, 05:00 PM
Incidentally, wouldn't this be cleaner anyway?



GameObj.targets.each { |mob|
if (mob.status !~ /flying/)
Spell[917].cast("##{mob.id}") if Spell[917].affordable?
waitcastrt?
waitrt?
end
}


targets already filters out everything that's dead, gone, or familiar type

Ohhh i didn't know they auto filtered that stuff. The raptor isn't a familiar it's a mob i ignore in a hunting ground. When did that change? I remember when i was on shattered i had to add the dead/gone and my animal companion to avoid the friendly npc. It would seem the update to ruby 2.0 changed a bunch of stuff. I also have just been gone for a couple years now and am sooo rusty.

Glaves
07-11-2019, 05:02 PM
set a macro to: \xtarget next\rincant 917\r
tape the key down
go afk

come back fried with full wizard juice.

You're welcome.

I legit didn't know you could even do target next. damn! Thank you! What does the the \x do?

Rjex
07-11-2019, 06:52 PM
doesn't incant automatically target whatever's in the room?

Gelston
07-11-2019, 06:56 PM
doesn't incant automatically target whatever's in the room?

Yes.

Donquix
07-11-2019, 11:26 PM
doesn't incant automatically target whatever's in the room?

yes but target next would cycle through all the things, eventually.

coincidentally there also target prev pretty sure but i never use that.

\x clears the input line, so if you fat finger something it doesn't screw up the macro by trying to send whatever you had typed but not sent yet + the macro