Changing Fireballs to Blobs

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Changing Fireballs to Blobs

Post by Grimfan »

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. :)
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Re: Changing Fireballs to Blobs

Post by Scotty »

The onProjectileHit(self,what,entity) hook is what you're after.

So everytime a fireball is spawned in, add a connector:

Code: Select all

spawn("fire_ball", ...........).projectile:addConnector("onProjectileHit","myScript","myFunction")
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.

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
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Changing Fireballs to Blobs

Post by Grimfan »

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?
Scotty
Posts: 69
Joined: Fri Nov 07, 2014 2:59 pm

Re: Changing Fireballs to Blobs

Post by Scotty »

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
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Changing Fireballs to Blobs

Post by Grimfan »

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. :D
Post Reply