Spike Trap Script Help Needed

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
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Spike Trap Script Help Needed

Post by Echoplex »

First time posting here, trying(albeit failing) to wrap my head around Lua. I'm trying to code a simple spike trap that would work off of a timer. The trap would activate spike traps in a pattern(Im thinking determined by a timer) however I can't get the darn traps to spring using a Script. Here's the test run I have below but obviously I fail at Lau language and cant get it to fire off. I have a timer connected to the script Lau. Im thinking im not defining what the floor_spike_trap is I.e. a trap but im not sure what its called or maybe im totally off base here. Anyway any help is much appreciated.

function Spikestrap()

if timecount == 1 then
floor_spike_trap_7:activate()

elseif timecount == 2 then
floor_spike_trap_8:activate()
end
timecount = 1
return
end
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Spike Trap Script Help Needed

Post by Prozail »

floor_spike_trap_7.controller:activate()

is what youre looking for. Also i made a kind of basic spike-trap thingy here
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: Spike Trap Script Help Needed

Post by Blichew »

When do you deactivate the traps ? With your example they will both be activated after 2 secs (timer ticks). Also: you're setting timecount to 1 every time the function runs (it's outside the elsif clause). If you want it to cycle you have to do something like that:

Code: Select all

function Spikestrap()
	if timecount == 1 then
		floor_spike_trap_7.controller:activate()
		floor_spike_trap_8.controller:deactivate()
	elseif timecount == 2 then
		floor_spike_trap_8.controller:activate()
		floor_spike_trap_7.controller:deactivate()
		timecount = 1
	end
end
also: @Prozail - thinking about next video tutorial :) ?
Last edited by Blichew on Fri Nov 07, 2014 11:04 am, edited 1 time in total.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Spike Trap Script Help Needed

Post by Prozail »

You don't need to deactivate them asfaik. Activate just does a one-shot.
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: Spike Trap Script Help Needed

Post by Blichew »

Oh, then I've just added two useless lines to this code :) still timecount has to be under elsif to alter between 1 and 2
Echoplex
Posts: 63
Joined: Tue Nov 04, 2014 10:59 pm

Re: Spike Trap Script Help Needed

Post by Echoplex »

Doh controller! Thank you, when I get some time ill check it out. Thank you for the responses everyone.
Post Reply