Page 1 of 1

Tieing a script to the activation of an object

Posted: Sat Sep 26, 2015 3:07 am
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.

Re: Tieing a script to the activation of an object

Posted: Sun Sep 27, 2015 8:54 pm
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.

Re: Tieing a script to the activation of an object

Posted: Sun Sep 27, 2015 9:02 pm
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.