slow timer issue [SOLVED]

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
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

slow timer issue [SOLVED]

Post by Granamir »

Hi,
i'm experiencing an unusual issue with a script, don't know if really related to timer, for sure is related to time.
I have a script that checks if a monster is dead and then spawn a blocker. Problem is that it take from 1 to 3 seconds to spawn that blocker after monster is dead. More weird is that with same timer and similar script (check if a monster is hit then change his position) it works perfectly.
Anyone knows a reason why this happens?

PS: i need this to prevent monsters to move freely but i need them to fire arrows freely. So if there is a way to achieve that i appreciate any solution (tryed to modify a blocker object with no results).
Last edited by Granamir on Mon Mar 16, 2015 12:14 pm, edited 1 time in total.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: slow timer issue

Post by Eburt »

Without seeing your script, I can't think of anything off the top of my head.

However, you can disable a monster's movement by unchecking the "move" box and it will do everything else as normal. Not sure if this is exactly what you're trying to do...
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: slow timer issue

Post by Granamir »

Yep i disabled movement for first row, archers, but behind them there is a melee row and those need to move.

Btw here is my code:

Code: Select all

function blockerScale()
	for i=1, 3 do
		local m = findEntity("archer_" .. i)
		if not m then
			local b = findEntity("bloccaScale_" .. i)
			if not b then
				spawn("blocker", 6, 4, i+27, 3, 0, "bloccaScale_" .. i)
				print("blocco " .. i .. "fuori")
			end
		end
	end
end
a timer, set to 0.001, is linked to that function
... if i link same timer to this code:

Code: Select all

function mostriGradino()
	for i=1, 4 do
		local m = findEntity("mostro_" .. i)
		if m ~= nil then
			local x, y = m:getPosition()
			if (x == 13 or x == 14) and (y == 14 or y == 15) then
				m:setWorldPositionY(1.3)
			else
			end
		else
		end
	end
end
it works perfectly.
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

Re: slow timer issue

Post by Eburt »

Hmmm, it looks like a monster's entity isn't destroyed immediately upon it's death. This is probably necessary for onDie hooks to work correctly (using one of those would be one potential solution).

You can use m.monster:isAlive() to check in your script with minimal changes though - probably the easiest solution.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: slow timer issue

Post by minmay »

I'm pretty sure it's not necessary for onDie hooks but it is the best way to handle the visual effects on death (particles and light, probably the 3D sound source too).
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: slow timer issue

Post by Azel »

I did something similar, where I needed to check the status of pressure plates in a room when a Monster Boss died. If they are not depressed then the Boss respawns, otherwise other fun stuff happens.

If your blockers are always in a set series of locations, then Spawning them isn't necessary, simply Enable or Disable as needed. If the Blockers location is truly dynamic, then your code looks perfect.

The OnDie Hook is best for checking the logic in this situation.

Below is a code snippet from my Monster Boss battle, hope it helps:

Code: Select all

function NewFireBoss()
	local fireBoss;
	do fireBoss = spawn("uggardian", party.level, 11, 15, 1, 0);
		fireBoss.monster:addConnector("onDie", "script_entity_18","FireBossDeath")
		fireBoss.monster:setLevel(3);
		fireBoss.monster:setMaxHealth(600);
		
		boss_fight_1.bossfight:addMonster(fireBoss.monster);
	end
	
end

function FireBossDeath()

	-- Check for conditions and respond to Boss Death
end
Granamir
Posts: 202
Joined: Wed Jan 07, 2015 7:19 pm

Re: slow timer issue

Post by Granamir »

Thank you guys.
i'll try first easier solution ^_^

EDIT: ...and it works great. Again thank you guys.
Post Reply