Legend of Grimrock

Legend of Grimrock

Not enough ratings
Scripting 'fx' in the Dungeon Editor
By Niet de AIVD
This guide assumed you have basic knowledge of the Dungeon Editor.

How do you put 'fx' in your dungeon? I'm going to show you how in this short tutorial. I'll explain how to spawn 'fx' dynamically and how to do things with your 'fx' object.
   
Award
Favorite
Favorited
Unfavorite
Preparations
I'm going to assume you already have a dungeon set up. If not, create a new dungeon.

To start, create an object 'script_entity', this is where we shall put the script in. Place it where you want the 'fx' to be.

Then, spawn a 'wall_button' or some other kind of button(Key works fine, too).

Do not spawn an 'fx'. The script takes care of spawning this.

Everything should look like in this image:
The script (and what now?)
function spawnLight() spawn("fx",1,self.x,self.y,1,"effect") effect:setLight(1,0,0,20,7,10,true) effect:translate(0,2,0) end

Put that in the 'script_entity' you just created. Next up, link the button to the 'script_entity', using function 'spawnLight()'.

If everything is right, you should be able to press the button and have a red light appear at the place where you put the 'script_entity'. The light will last for 10 seconds before fading away.
Explanation
I will go through every line of the script and explain what it does.

function spawnLight()
Everything inside 'script_entity' starts when the entity is loaded. In order to keep it from doing that, we use a function. This way, we can have a button(or a different script) call said function.


spawn("fx",1,self.x,self.y,1,"effect")
This spawns the 'fx'.
Reference entry:
"spawn(object, level, x, y, facing, [id])"


effect:setLight(1,0,0,20,7,10,true)
This sets the light at the location of 'fx'.

Reference entry:
"FX:setLight(red, green, blue, brightness, range, time, castShadow)"


effect:translate(0,2,0)
This lights the light off the ground. Basically, it means: Move effect 2 meters up.

Reference entry:
"FX:translate(x, y, z)"


end
This dictates the end of 'spawnLight()'
What can you do with 'fx'?
Excerpt from the reference
FX:setParticleSystem(name) Sets the particle system to be played when the FX is first updated. FX:setLight(red, green, blue, brightness, range, time, castShadow) Sets the light effect to be played when the FX is first updated. Red, green and blue define the color of the emitted light in range 0-1, brightness is light’s brightness typically in range 0-20, range is light’s range in world units (meters), time is the length of the effect in seconds, castShadow is a boolean flag which enables shadow casting for the light source. Large range and shadow casting can cause drops in frame rate. FX:translate(x, y, z) Translates (i.e. moves) the FX by x,y,z in world space. This function is typically used to lift particle system off the ground. FX:destroy() Removes the entity from the level.

More explanation and examples are WIP.