Hi scripting Dudes and dudettes. I want the following thing to happen in a script:
1. A spawner fires a fire_ball down a hallway.
2. If the fire_ball misses the player the spawner doesn't change, but
3. If the player is hit the spawner then starts firing blobs instead.
Basically, is there any way that a fire_ball (or spell in general) can tell if it has hit a player, and can this impact trigger a spawner to change it's spawned entity?
Any help along these lines would be great, since this sort of script is still a little outside my ability.
Changing Fireballs to Blobs
Re: Changing Fireballs to Blobs
The onProjectileHit(self,what,entity) hook is what you're after.
So everytime a fireball is spawned in, add a connector:
I imagine the "what" value that the hook passes to the function is important, I'm not exactly sure what it gives if it hits a player or whatever. So just have it print out the "what" value and experiment a bit. Also, I don't think there's much of a way to add connectors to objects that are spawned in using an actual spawner object, so you might have to handle pretty much everything via script.
So it would be something like.
So everytime a fireball is spawned in, add a connector:
Code: Select all
spawn("fire_ball", ...........).projectile:addConnector("onProjectileHit","myScript","myFunction")
So it would be something like.
Code: Select all
hit_player == false
function spawnFireball() -- trigger this via timer
if hit_player == false then
spawn ("fire_ball", ...........................).projectile:addConnector("onProjectileHit","myScript","fireballHit")
else
spawn ("blob", ...........................)
end
end
function fireballHit(self, what, entity)
print (what) --just to see what it outputs if it hits the player
if what == "whatever this ends up being if it hits a player" then
hit_player = true
end
end
Re: Changing Fireballs to Blobs
The fireball prints out entity every time it hits (the party or anything else)
But what entity is it referring to? I've put party, fireball_blast_medium and fireball_medium, but nothing seems to happen. And what's the correct syntax once I find out the entity it is referring to?
But what entity is it referring to? I've put party, fireball_blast_medium and fireball_medium, but nothing seems to happen. And what's the correct syntax once I find out the entity it is referring to?
Re: Changing Fireballs to Blobs
Alrighty, this should do the trick:
Code: Select all
hit_player = false
function spawnFireball() -- trigger this via timer
if hit_player == false then
spawn ("fireball_medium", 1, 15, 12, 2, 0).projectile:addConnector("onProjectileHit","myScript","fireballHit")
else
spawn ("blob", 1, 15, 12, 2, 0)
end
end
function fireballHit(fireball, what, target)
if target ~= nil and target.name == "party" then
hit_player = true
end
end
Re: Changing Fireballs to Blobs
Thanks for the help Scotty!!! You're script has taught me a bit more about how lua works and helped me with my mod. Like Thorham you are going to added to my list of scripting gurus I will thank with much adulation when it is released.