spawning a monster onDie

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!
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

spawning a monster onDie

Post by bongobeat »

Hello,

can a monster be spawned after the death of another monster, and a the same place of the dying monster?
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: spawning a monster onDie

Post by Azel »

bongobeat wrote:Hello,

can a monster be spawned after the death of another monster, and a the same place of the dying monster?
Yessir. There are at least 2 ways to accomplish this. Let's say you want to Spawn an Ice Guardian when a Uggardian dies:

1) To do this without ever typing a single line of LUA Script, simply place the Ice Guardian in a Single Square room (so he can't move) and place a Teleporter on top of him. Set the Teleporter's Initial State to Deactivate. Now with the Uggardian, in the Script Editor click on his Connector and the OnDie method becomes available. Tie that OnDie method to the Teleporter, make sure it triggers it to Activate. Lastly, set the Teleporter's location to wherever you want the Ice Guardian to end up after the Uggardian dies. You can set up many monsters this way, and get even more creative with how they respawn, where they respawn, and how often this can occur if you tie everything to Counters, Spawners, and Timers. All with zero code!

2) You can Spawn monsters at Runtime using the Spawn() method by creating a Function that sets the OnDie behavior of a monster. Below is example Script that Spawns the Uggardian from a LUA Function, and then after it dies it looks at a Master Counter result to decide if the Uggardian will respawn (along with a Flame Elemental for funsies), or if a hidden Ice Guardian will be moved in to position to attack the party. This uses a combination of the example in Step 1 above (minus the Teleporter) along with script to Spawn a creature at Runtime. This script also checks the position the Ice Guardian should face based on the direction the Party is looking at the time of the Uggardian's death.

Code: Select all


function NewUggardian()
	local mob;
	do mob = spawn("uggardian", party.level, 11, 15, 1, 0);
		mob.monster:addConnector("onDie", "script_entity_18","UggDeath")
		mob.monster:setLevel(3);
		mob.monster:setMaxHealth(600);
	end
	
end

function UggDeath()

	local secondMobFacing = 1; -- Default to East
	
	-- if North then South
	if party.facing == 0 then secondMobFacing = 2; end
	
	-- if East then West
	if party.facing == 1 then secondMobFacing = 3; end
	
	-- if South then North
	if party.facing == 2 then secondMobFacing = 0; end
	
	if master_counter.counter:getValue() <= 0 then
		-- move the hidden Ice Guardian in to attack position
		ice_guardian_1:setPosition(party.x,party.y,secondMobFacing,party.elevation,party.level);
	else
		-- respawn the original Uggardian
		NewUggardian();
		
		-- for funsies, spawn a Fire Elemental as well
		spawn("fire_elemental", party.level, 12, 15, 1)
		
		-- Prompt the players
		hudPrint("The creature has returned!");
	end

end


To run that script above all you have to do is begin by calling NewUggardian() somehow (like from a Floor Trigger when the party enters a room). Hope this helps, cheers!
:mrgreen:
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: spawning a monster onDie

Post by minmay »

3) To get the same results as those two terrible methods, while being significantly less terrible, put this in the monster's onDie hook instead:

Code: Select all

onDie = function(self)
	self.go:spawn("fjeld_warg")
end,
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: spawning a monster onDie

Post by Azel »

Mod Troll wrote:To get the same results as those two terrible methods, while being significantly less terrible
aww, minmay the Mod Troll is on the attack. Poor lil fella.

Your script does not achieve the same result at all, key differences:

1) My script allows you to set the Monster level, your script Spawns the default Level 1

2) My script allows you to set the Monster health, your script Spawns the default Health

3) My script Respawns 2 monsters at once in one scenario, or a second monster in a different, yours spawns 1 no matter what

If you are having trouble understanding why they are different, refer to this:
http://www.grimrock.net/modding/scripting-reference/
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: spawning a monster onDie

Post by minmay »

lol "Mod" where the hell did that come from? can someone just ban you already so you stop ruining other people's mods with broken scripts

but for the benefit of other readers: code in the onDie hook allows doing the exact same things:

Code: Select all

onDie = function(self)
  local warg = spawn("fjeld_warg",self.go.level,self.go.x,self.go.y,(party.facing+2)%4,self.go.elevation)
  warg.monster:setLevel(3)
  warg.monster:setMaxHealth(600)
  warg.monster:setHealth(600)
end,
etc
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: spawning a monster onDie

Post by Azel »

This is a "Mod Creation" forum and you like insulting people on it, hence you are the Mod Troll... :P

There's nothing broken about the script I wrote, you are just upset because you have some personal issues. Save your whining for your little Skype sessions with Isaac and crew (I heard about those LOL).

As for your script, you decided to make it look so much more like mine, only you sacrificed readability in order to shove everything in to a single line. Neither your code nor my code is broken, but yours is definitely shaped like oatmeal. Go troll someone else, lil fella.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: spawning a monster onDie

Post by minmay »

Azel wrote:Save your whining for your little Skype sessions with Isaac and crew (I heard about those LOL).
ok this is pretty funny I admit
but really can you keep your trolling to the regular forum instead of trying to sabotage other people's mods? it's a pretty dickish thing to do and i'm pretty sure nobody except you thinks it's funny
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: spawning a monster onDie

Post by Azel »

I fail to see how my original response in this thread is trolling or how it "sabotages" peoples mods. All I know for certain is that you get angry when someone other than you or your little crew contributes code. You can "say" my script is bad but you have failed to illustrate how, which actually makes you the troll. You are far too arrogant for someone who has a tiny bit of borrowed abilities. My intentions are good, your intentions seem quite petty and egotistical, which is why you can't help but insult others who try to contribute on this forum. If you don't like my posts, or my script, you can just ignore them. Pretty easy.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: spawning a monster onDie

Post by bongobeat »

hermmm, thanks all for your help. Don't get angry, keep cool 8-)
I'm gonna try that, I think I will use minmay script, it seems more easier to do.

I want to do that, for only 1 monster, that the party has to fight, then he respawn a npc version of the 1st monster, which will talk to the party.

Azel, I'm not sure that I understand all with the teleporter solution. This method can't spawn the 2nd monster on the exact place where the 1st monster dies, you don't know where the party will kill the first monster. Or I did not understand what you are saying.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: spawning a monster onDie

Post by Azel »

Oh yeah, the Teleporter wouldn't be able to do it in the exact location where the original monster died; unless you added Script. The smaller script minmay gave is definitely better for a straight 1-to-1 scenario: monster dies, monster spawns. Sorry if I confused you, I tend to like to make things a bit more adventurous, so to speak. Cheers!
Post Reply