NWScript :
#include "zep_inc_main"
void main()
{
int nLightCycle = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTCYCLE");
int nInitialized = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTINITIALIZED");
//0 if the first time this function has run for this torch, 1 if it has run before
//used so that non-cycling placeables use less CPU time.
if (nInitialized == 1 & nLightCycle == 0) return; //if torch is non cycling and has been initialized, quit
int nAmIOn = GetLocalInt(OBJECT_SELF, "CEP_L_AMION");
string sLightConst = GetLocalString(OBJECT_SELF, "CEP_L_LIGHTCONST");
string sLightSwap = GetLocalString(OBJECT_SELF, "CEP_L_LIGHTSWAP");
int nLight = ColorInit(sLightConst);
if (nInitialized == 0){
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTINITIALIZED", 1);
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL", !GetIsNight());
} //if the placeable wasn't marked as initialized, it is now.
int nLightDiurnal = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL");
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL", GetIsNight());
//this gets the GetIsNight value from the last time zep_torchspawn fired
//it is used to check to see if the torch needs to change state for day/night cycle
if(nLightCycle == 1){ //if this is a cycling placeable
if(GetIsNight() == nLightDiurnal) return;
//if day/night hasn't changed since last time, return.
if((GetIsNight() == 0)&(nAmIOn == 0)) return;
if((GetIsNight() == 1)&(nAmIOn == 1)) return;
//if the on/off state matches what it should be, return.
//otherwise, destroy the placeable and place its lit/unlit counterpart at the same location
if(nAmIOn == 1){nAmIOn = 0;}
else {nAmIOn = 1;}
string sResRef = GetResRef(OBJECT_SELF);
location lLoc = GetLocation(OBJECT_SELF);
object oNew = CreateObject(OBJECT_TYPE_PLACEABLE, sLightSwap, lLoc);
SetLocalInt(oNew, "CEP_L_AMION", nAmIOn);
SetLocalInt(oNew, "CEP_L_LIGHTCYCLE", nLightCycle);
SetLocalInt(oNew, "CEP_L_LIGHTINITIALIZED", nInitialized);
SetLocalInt(oNew, "CEP_L_LIGHTDIURNAL", GetIsNight());
SetLocalString(oNew, "CEP_L_LIGHTCONST", sLightConst);
SetLocalString(oNew, "CEP_L_LIGHTSWAP", sResRef);
if (nAmIOn == 1)
{
effect eLight = EffectVisualEffect(nLight);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, oNew);
}
DestroyObject(OBJECT_SELF, 0.0);
return;
}else{
//if not a cycling placeable and uninitialized, place a light effect, if needed
if (nAmIOn == 1)
{
effect eLight = EffectVisualEffect(nLight);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, OBJECT_SELF);
}
}
}Note : le code affiché ci-dessus n'est pas rendu tel qu'il devrait l'être réellement, en particulier des sauts de lignes sont automatiquement insérés pour éviter de casser la mise en page. En le copiant/collant, vous résoudrez ce problème.
#include "zep_inc_main"
void main()
{
int nLightCycle = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTCYCLE");
int nInitialized = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTINITIALIZED");
//0 if the first time this function has run for this torch, 1 if it has run before
//used so that non-cycling placeables use less CPU time.
if (nInitialized == 1 & nLightCycle == 0) return; //if torch is non cycling and has been initialized, quit
int nAmIOn = GetLocalInt(OBJECT_SELF, "CEP_L_AMION");
string sLightConst = GetLocalString(OBJECT_SELF, "CEP_L_LIGHTCONST");
string sLightSwap = GetLocalString(OBJECT_SELF, "CEP_L_LIGHTSWAP");
int nLight = ColorInit(sLightConst);
if (nInitialized == 0){
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTINITIALIZED", 1);
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL", !GetIsNight());
} //if the placeable wasn't marked as initialized, it is now.
int nLightDiurnal = GetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL");
SetLocalInt(OBJECT_SELF, "CEP_L_LIGHTDIURNAL", GetIsNight());
//this gets the GetIsNight value from the last time zep_torchspawn fired
//it is used to check to see if the torch needs to change state for day/night cycle
if(nLightCycle == 1){ //if this is a cycling placeable
if(GetIsNight() == nLightDiurnal) return;
//if day/night hasn't changed since last time, return.
if((GetIsNight() == 0)&(nAmIOn == 0)) return;
if((GetIsNight() == 1)&(nAmIOn == 1)) return;
//if the on/off state matches what it should be, return.
//otherwise, destroy the placeable and place its lit/unlit counterpart at the same location
if(nAmIOn == 1){nAmIOn = 0;}
else {nAmIOn = 1;}
string sResRef = GetResRef(OBJECT_SELF);
location lLoc = GetLocation(OBJECT_SELF);
object oNew = CreateObject(OBJECT_TYPE_PLACEABLE, sLightSwap, lLoc);
SetLocalInt(oNew, "CEP_L_AMION", nAmIOn);
SetLocalInt(oNew, "CEP_L_LIGHTCYCLE", nLightCycle);
SetLocalInt(oNew, "CEP_L_LIGHTINITIALIZED", nInitialized);
SetLocalInt(oNew, "CEP_L_LIGHTDIURNAL", GetIsNight());
SetLocalString(oNew, "CEP_L_LIGHTCONST", sLightConst);
SetLocalString(oNew, "CEP_L_LIGHTSWAP", sResRef);
if (nAmIOn == 1)
{
effect eLight = EffectVisualEffect(nLight);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, oNew);
}
DestroyObject(OBJECT_SELF, 0.0);
return;
}else{
//if not a cycling placeable and uninitialized, place a light effect, if needed
if (nAmIOn == 1)
{
effect eLight = EffectVisualEffect(nLight);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLight, OBJECT_SELF);
}
}
}