Tieing a script to the activation of an object

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
Iceblade
Posts: 1
Joined: Sat Sep 26, 2015 2:56 am

Tieing a script to the activation of an object

Post by Iceblade »

What I'm trying to do is create a stand-in for a poison fountain. What I would like to do is attach a poisoning script to the activation of chosen instances of life crystals.

Unfortunately, I can't seem to find how to add a scripting component to the life crystal.
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: Tieing a script to the activation of an object

Post by Skuggasveinn »

If I understand the question, you want a function in a script entity to get called when you press a particular type of life crystal ?

One way of doing that would be to define your own life crystal, lets call it healing_crystal_poison and create an onClick function in that crystal that calls the function poisonwell inside the script poisonwell that is in the same place as the life crystal.

Code: Select all

defineObject{
	name = "healing_crystal_poison",
	components = {
		{
			class = "Model",
			model = "assets/models/env/healing_crystal.fbx",
			castShadow = false,
		},
		{
			class = "Particle",
			particleSystem = "crystal",
		},
		{
			class = "Light",
			offset = vec(0,1,0),
			color = vec(39/255, 90/255, 205/255),
			range = 7,
			shadowMapSize = 128,
			castShadow = true,
			staticShadows = true,
		},
		{
			class = "Sound",
			offset = vec(0, 1.5, 0),
			sound = "crystal_ambient",
		},
		{
			class = "Animation",
			animations = {
				spin = "assets/animations/env/healing_crystal_spin.fbx",
			},
		},
		{
			class = "Clickable",
			offset = vec(0, 1.5, 0),
			size = vec(1.6, 2, 1.6),
			maxDistance = 1,
			onClick = function(self)
			local x,y = 0,0
				for e in self.go.map:entitiesAt(self.go.x, self.go.y) do
					if e.script and e.script.poisonwell then
						e.script:poisonwell()
					end
				end

			end,
		},
		{
			class = "Obstacle",
		},
		{
			class = "ProjectileCollider",
		},
		{
			class = "Crystal",
			cooldown = 120,
		},
	},
	placement = "floor",
	editorIcon = 60,
	automapIcon = 104,
	automapIconLayer = 1,
}
So place this crystal in your map, create a script called poisonwell and place it on top of your crystal, then create a function within that script called poisonwell.
When you use that crystal anything inside the poisonwell function will get executed.

Hope that helps.

Skuggasveinn.
Last edited by Skuggasveinn on Sun Sep 27, 2015 9:03 pm, edited 1 time in total.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Tieing a script to the activation of an object

Post by minmay »

You'll want to change that so that it only executes that block if the crystal is actually active, surely - clicking on the dead crystal shouldn't do anything.
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