Ask a simple question, get a simple answer

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!
User avatar
vanblam
Posts: 170
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam » Tue May 14, 2019 7:41 pm

THOM wrote:
Tue May 14, 2019 7:18 pm
it's

Code: Select all

myObjectID.myparticle:restart()
How would use that in the object definition tho?

EDIT: I got it.

Code: Select all

},
			onAnimationEvent = function(self, event)
			if event == "rc_sgl_activate" then
			self.go.lever_hit1:restart()
			elseif event == "rc_sgl_deactivate" then
			self.go.lever_hit2:restart()
				end
			end,
		},
Thanks THOM :)

Stone Lever
Last edited by vanblam on Tue May 14, 2019 9:31 pm, edited 1 time in total.

oldboy87
Posts: 7
Joined: Tue Apr 09, 2019 10:33 am

Re: Ask a simple question, get a simple answer

Post by oldboy87 » Tue May 14, 2019 8:48 pm

Zo Kath Ra wrote:
Mon May 13, 2019 6:34 pm
oldboy87 wrote:
Mon May 13, 2019 5:42 pm
For something completely unrelated, does anybody have any idea what the asset is called in the linked image? I want a sort of portcullis that closes from below and these fit the bill if memory serves correctly. Problem is, I cannot seem to find it in the editor. Doesn't come under the door category and I've tried under gates, portcullis, grating - anything I think it could be.

Image

https://imgur.com/oD4WmPS
mine_door_spear
Perfect, thanks ever so much :)

User avatar
vanblam
Posts: 170
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam » Wed May 15, 2019 7:16 am

One more question so I can clear this up lol. On the code below how would I write for the onAnimationEvent to use "rc_sgl_action" to have the lever activate its target on that frame and then deactivate its self?

Code: Select all

defineObject{
	name = "rc_stone_ground_lever",
	components = {
		{
			class = "Model",
			model = "mod_assets/vanblam/red_cave/models/env/rc_stone_ground_lever.fbx",
			staticShadow = true,
		},
		{
			class = "Animation",
			animations = {
				activate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
				deactivate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
			},
			onAnimationEvent = function(self, event)
			if event == "rc_sgl_activate" then
			self.go.lever_hit1:restart()
			elseif event == "rc_sgl_deactivate" then
			self.go.lever_hit2:restart()
				end
			end,
		},
		{
			class = "Clickable",
			offset = vec(0,0.9,-0.7),
			size = vec(1, 0.6, 0.2),
			maxDistance = 1,
			--debugDraw = true,
		},
		{
			class = "Lever",
			sound = "rc_stone_lever",
		},
		{
				class = "Particle",
				name = "lever_hit1",
				offset = vec(-0.158,0.54,-0.7),
				particleSystem = "rc_hit_lever",
		},
		{
				class = "Particle",
				name = "lever_hit2",
				offset = vec(0.155,0.54,-0.7),
				particleSystem = "rc_hit_lever",
		},
	},
	placement = "wall",
	editorIcon = 12,
	tags = { "red cave", "vanblam" },
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_activate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
		event = "rc_sgl_deactivate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_action",
		frame = 15,
}

User avatar
Isaac
Posts: 2800
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac » Wed May 15, 2019 11:14 pm

Code: Select all

defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_activate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
		event = "rc_sgl_deactivate",
		frame = 19,
}
These events [from your code] trigger on the same frame.

Your hook code should route its execution based on the event value. So, it should behave differently for different event values.
Events are called when the given animation file is run, and at what frame number (or percentage) is specified.
vanblam wrote:
Wed May 15, 2019 7:16 am
...how ... to have the lever activate its target on that frame and then deactivate its self?
Offhand, and without many details, I'd say don't connect the lever to anything, just trigger/call the target, and disable the lever; both from the onAnimationEvent hook. The hook will be called when the lever animation frame number is reached.

User avatar
vanblam
Posts: 170
Joined: Sun Nov 09, 2014 12:15 am

Re: Ask a simple question, get a simple answer

Post by vanblam » Thu May 16, 2019 6:54 am

Isaac wrote:
Wed May 15, 2019 11:14 pm

Code: Select all

defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_activate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
		event = "rc_sgl_deactivate",
		frame = 19,
}
These events [from your code] trigger on the same frame.

Your hook code should route its execution based on the event value. So, it should behave differently for different event values.
Events are called when the given animation file is run, and at what frame number (or percentage) is specified.
vanblam wrote:
Wed May 15, 2019 7:16 am
...how ... to have the lever activate its target on that frame and then deactivate its self?
Offhand, and without many details, I'd say don't connect the lever to anything, just trigger/call the target, and disable the lever; both from the onAnimationEvent hook. The hook will be called when the lever animation frame number is reached.
Well the two events you have selected there are to different animations that control the dust particles when you flip the switch and when the frame hits 19 on both animations the dust particle takes place and works just fine. But what I'm looking to do is have the lever activate its target with a delay. But I need this to take place with-in the object definition and NOT in the editor at all what so ever (except for choosing your target of course). I'm not sure if you can use a controller because that's more like a receiver right? I have a feeling there is something simple I'm missing that I can't see lol.

Zo Kath Ra
Posts: 713
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra » Thu May 16, 2019 7:35 am

vanblam wrote:
Thu May 16, 2019 6:54 am
But what I'm looking to do is have the lever activate its target with a delay. But I need this to take place with-in the object definition and NOT in the editor at all what so ever (except for choosing your target of course). I'm not sure if you can use a controller because that's more like a receiver right? I have a feeling there is something simple I'm missing that I can't see lol.
At the risk of saying the obvious:
delayedCall(receiver, delay, msg)

oldboy87
Posts: 7
Joined: Tue Apr 09, 2019 10:33 am

Re: Ask a simple question, get a simple answer

Post by oldboy87 » Thu May 16, 2019 8:27 am

How would I go about adding a set target option for a map transition that isn't stairs? So lets say I have forest_exit_rock_tunnel but I don't want it to transition at the same spot and elevation in the next map as it would be default, I'd like to be able to select where it will transition to without there being a stair ascending / descending animation.

User avatar
Isaac
Posts: 2800
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac » Thu May 16, 2019 9:23 am

oldboy87 wrote:
Thu May 16, 2019 8:27 am
I have forest_exit_rock_tunnel but I don't want it to transition at the same spot and elevation in the next map as it would be default, I'd like to be able to select where it will transition to without there being a stair ascending / descending animation.
An easy way is to set an invisible teleporter on the tile where the party arrives through the exit, and have it place them on the tile you would like. This keeps the automatic fade effects that come with using an exit. This is simplest if the actual destination tiles from the exits exist outside the accessible map.

Image

___________________________________
vanblam wrote:
Thu May 16, 2019 6:54 am
But what I'm looking to do is have the lever activate its target with a delay. But I need this to take place with-in the object definition and NOT in the editor at all what so ever (except for choosing your target of course).
If you need the effect to be entirely self contained, and editor independent, but that the user still places the lever asset, and connects it to an arbitrary target... then you need to detect the lever's connectors, and issue delayedCalls to trigger them.

Code: Select all

onInit = function(self) self.go.lever:disable() end,
onAnimationEvent = function(self, event)
				local delay = 3 --seconds
				for x = 1, self.go.lever:getConnectorCount() do
					local hook, target, action = self.go.lever:getConnector(x)
					if event:match(hook) or action == "toggle" then
						delayedCall(target, delay, action)
						self.go.clickable:disable() -- Disables the lever functionality
					end
				end	
			end

Note that these are changed.

Code: Select all

defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_onActivate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
		event = "rc_sgl_onDeactivate",
		frame = 19,
}

oldboy87
Posts: 7
Joined: Tue Apr 09, 2019 10:33 am

Re: Ask a simple question, get a simple answer

Post by oldboy87 » Thu May 16, 2019 10:15 am

Isaac wrote:
Thu May 16, 2019 9:23 am
oldboy87 wrote:
Thu May 16, 2019 8:27 am
I have forest_exit_rock_tunnel but I don't want it to transition at the same spot and elevation in the next map as it would be default, I'd like to be able to select where it will transition to without there being a stair ascending / descending animation.
An easy way is to set an invisible teleporter on the tile where the party arrives through the exit, and have it place them on the tile you would like. This keeps the automatic fade effects that come with using an exit. This is simplest if the actual destination tiles from the exits exist outside the accessible map.

Image

Thanks for the suggestion, I'm clearly not doing something right with it though. When I transition the screen fades to black but does not fade back in again (the map's ambient sound also does not play so I am left in silence). It will remain that way until I walk through a proper level transition again. On the gif you provided the invisible teleporter isn't actually on the tile that the player steps on to, I expect this is where I've gone wrong as I have the teleporter placed on the transition and the target placed in front of the transition on the other map and vice versa. I'm not sure how to have the teleporter placed somewhere else and point to both where the player will teleport from and to, I can only see the position and the target. Please see my screenshots:

https://imgur.com/IFG54dd

https://imgur.com/apYeTc9

I also wondered if having them placed right at the edge of the map was causing the issue but I did also try pushing them in a tile and the same thing happens.

minmay
Posts: 2532
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Thu May 16, 2019 10:28 am

Unfortunately that won't work because lever connectors pass the LeverComponent as the first argument if connected to a ScriptControllerComponent, and you can't pass a component through a delayedCall without breaking save games. So you are either not imitating the connector correctly (which will break people's mods) or you are breaking save games (which will break people's mods).
You must use LeverComponent:toggle() to handle the connectors. There is no other way.

A disabled LeverComponent won't trigger its connectors. So the simplest way to do this is to start it out disabled, and have your onAnimationEvent hook enable it, toggle it, then disable it again. And remember to disable the ClickableComponent during this so that the player can't toggle the lever again themselves and mess it up. Like this:

Code: Select all

defineObject{
	name = "rc_stone_ground_lever",
	components = {
		{
			class = "Model",
			model = "mod_assets/vanblam/red_cave/models/env/rc_stone_ground_lever.fbx",
			staticShadow = true,
		},
		{
			class = "Animation",
			animations = {
				activate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
				deactivate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
			},
			onAnimationEvent = function(self, event)
				if event == "rc_sgl_start" then
					self.go.clickable:disable()
				elseif event == "rc_sgl_activate" then
					self.go.lever_hit1:restart()
					self.go.lever:enable()
					self.go.lever:toggle()
					self.go.lever:disable()
					self.go.clickable:enable()
				elseif event == "rc_sgl_deactivate" then
					self.go.lever_hit2:restart()
				end
			end,
		},
		{
			class = "Clickable",
			offset = vec(0,0.9,-0.7),
			size = vec(1, 0.6, 0.2),
			maxDistance = 1,
			--debugDraw = true,
		},
		{
			class = "Lever",
			sound = "rc_stone_lever",
			enabled = false,
		},
		{
				class = "Particle",
				name = "lever_hit1",
				offset = vec(-0.158,0.54,-0.7),
				particleSystem = "rc_hit_lever",
		},
		{
				class = "Particle",
				name = "lever_hit2",
				offset = vec(0.155,0.54,-0.7),
				particleSystem = "rc_hit_lever",
		},
	},
	placement = "wall",
	editorIcon = 12,
	tags = { "red cave", "vanblam" },
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_start",
		frame = 0,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
		event = "rc_sgl_activate",
		frame = 19,
}
defineAnimationEvent{
		animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
		event = "rc_sgl_deactivate",
		frame = 19,
}
(warning I was too lazy to actually test this specific code)

Note that this will only trigger the lever's onToggle and onDeactivate connectors, not its onActivate connectors. You might prefer to leave the LeverComponent enabled the whole time instead, which will make it trigger its onActivate and onToggle connectors when initially pulled, and its onDeactivate and onToggle connectors when it flips back up.
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.

Post Reply