@andgalf
Are you trying to make dynamic lights?
As @raymondsebas explains, prefabs are to make building easier rather than anything else. I.e. Rather than go to placeables, place a torch, go to lights, place a light and finally go to effects and place an effect … a prefab drops all three items in one go. So prefabs are designed for speed of building repetitious cluster of objects. They can also be a little fiddly to setup and use, but once established can be a time saver.
Now, if you want dynamic lights (which I nearly answered a couple of times, but thought you had marked it as solved for you), I have a slightly different approach, but still uses prefabs for speed … Anyway, I include an explanation here for you.
The important point to note is that light objects lose their tags between reloads, and referencing them becomes awkward. So, here is what I do, which I imagine you will know what to do, but ask if you need any additional explanation here.
PRE BUILD CAVEAT: The light object position is the reference for the VFX when required.
- Place the torch or other light placeable object. (Have TAG ref “OFF” if the source starts off.)
- Place the light object just above the placeable where you intend the VFX to also appear.
- Have a script on the placeable OnUsed that controls everything.
The script must then determine from the placeable TAG whether the light source is currently on or off for initial usage. (Thereafter it should just toggle any state.) Any light placed above the torch (also where the flame will be created) is also set matching “ON” or “OFF” at time of build placement.
The script then searches for the nearest light OBJECT to the placeable (not tag of light which breaks), and then toggles the light source object “ON” or “OFF” subject to current state, initially dictated by the placeable TAG. At the same time, the script creates or destroys the VFX you have setup as a template for the object.
My own script has grown quite large to accommodate all sorts of other lighting setups and so may only confuse matters if I posted it. I can do, but only if you think it might help you to understand some of what I wrote here.
EDIT: Actually, I found the smaller older script I use for this sort of thing … This version assumes the light source starts OFF wherever you place it at build time. i.e. No flame VFX placed and light that is placed is set “OFF”.
This script is set on the OnUsed of the light object.
//////////////////////////////////////////////////////////////////////////////////////
// LIGHT SWITCH FOR LAMPS (WILL SAVE 1) AND TORCHES (WILL SAVE 0)
// LIGHT MUST BE PLACED (FLAME IS CREATED)
//////////////////////////////////////////////////////////////////////////////////////
void StopLight(object oSelf)
{
object oFlame = GetNearestObjectByTag("alb_wall_torch_flame", oSelf);
DestroyObject(oFlame);
object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, OBJECT_SELF);
SetLightActive(oLight, FALSE); // NEAREST LIGHT FIX APPLED
}
void Ignite(object oSelf)
{
object oLight = GetNearestObject(OBJECT_TYPE_LIGHT, OBJECT_SELF);
SetLightActive(oLight, TRUE); // NEAREST LIGHT FIX APPLED
location lFlame = GetLocation(oLight);
if(GetWillSavingThrow(oSelf) == 0)
{
CreateObject(OBJECT_TYPE_PLACED_EFFECT, "alb_wall_torch_flame", lFlame);
}
else
{
object oLampFlame = CreateObject(OBJECT_TYPE_PLACED_EFFECT, "alb_candle_light", lFlame);
SetTag(oLampFlame, "alb_wall_torch_flame");
}
}
void main()
{
object oPlayer = GetLastUsedBy();
AssignCommand(oPlayer,ClearAllActions());
AssignCommand(oPlayer, ActionMoveToObject(OBJECT_SELF,FALSE,0.5));
AssignCommand(oPlayer, ActionPlayAnimation(ANIMATION_LOOPING_GET_MID,1.0,0.5));
object oSelf = OBJECT_SELF;
// LIGHT IS CURRENTLY OFF (TURN ON) ////////////////////////////////////////
object oFlame = GetNearestObjectByTag("alb_wall_torch_flame", oSelf);
float fDis = 0.0;
if(oFlame != OBJECT_INVALID)
{
fDis = GetDistanceBetween(oFlame, oSelf);
//SendMessageToAllPCs(" >>> " + FloatToString(fDis));
}
if(fDis == 0.0 || fDis > 2.0)
{
// IGNITE EFFECT (TORCHES ONLY)
if(GetWillSavingThrow(OBJECT_SELF) == 0)
{
effect eFlame = EffectNWN2SpecialEffectFile("IgniteTorch");
DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT,eFlame,OBJECT_SELF));
}
DelayCommand(1.0, Ignite(oSelf));
DelayCommand(0.5, AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)));
}
// LIGHT IS CURRENTLY ON (TURN OFF) ////////////////////////////////////////
else if(fDis > 0.0 && fDis <= 2.0)
{
DelayCommand(1.0, StopLight(oSelf));
AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
}
}