Removable light source
From NWNWiki
Contents |
[edit] Removable light source
[edit] What it does
Allows you to create torch brackets with removable torches. When the torch is removed, the light goes out, and comes back in if you put another torch in (actually, any light source will do).
This script is useful if you want to put one torch bracket at the beginning of a tunnel or dungeon. The PC can remove the torch from the bracket and use it as they continue down the dark tunnel. When they take the torch out, the bracket goes out, and won't come back on until another light source is put in. At the moment, you could use any light source, including a ring that cast light... Don't ask me how the bracket uses the ring. You could very easily limit the working item to a torch though.
[edit] Note
In order to use these scripts, you will need to create a Torch Bracket and check Useable and Has Inventory. Then put a regular torch in the Torch Bracket's inventory. I also set its initial state to Activated, just to make sure, but I think it will be lit anyway if you leave it as default. Now,
[edit] The Scripts
place the first script in the Torch Bracket's onDisturbed event. Place the second script in the Torch Bracket's onUsed event.
//::///////////////////////////////////////////////
//:: kv_02_dist.nss
//:://////////////////////////////////////////////
/*
onDisturb Event of Torch Bracket
Take away or replace light source in a
light source container (wall bracket, etc.)
*/
//:://////////////////////////////////////////////
//:: Created By: Kevin
//:: Created On: 08/16/2002
//:://////////////////////////////////////////////
void main()
{
int bLightable = FALSE;
// Check to see if it has a "lightable" item in its inventory
if (GetHasInventory(OBJECT_SELF))
{
object oSource = GetFirstItemInInventory();
while (GetIsObjectValid(oSource))
{
if (GetItemHasItemProperty(oSource,ITEM_PROPERTY_LIGHT))
{
bLightable = TRUE;
}
oSource = GetNextItemInInventory();
}
}
if (!bLightable && GetLocalInt(OBJECT_SELF,"NW_L_AMION") == 1)
{
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
DelayCommand(0.4,SetPlaceableIllumination(OBJECT_SELF, FALSE));
SetLocalInt(OBJECT_SELF,"NW_L_AMION",0);
DelayCommand(0.9,RecomputeStaticLighting(GetArea(OBJECT_SELF)));
}
}
//::///////////////////////////////////////////////
//:: kv_O2_ONOFF.nss
//:://////////////////////////////////////////////
/*
Turns the placeable object's animation on/off
kev: Only if a light source is still there... (torch in most cases)
variation off of NW_02_ONOFF.nss by Bioware.
*/
//:://////////////////////////////////////////////
//:: Created By: Brent (of Bioware)
//:: Created On: January 2002
//:: Modified By: Kevin
//:://////////////////////////////////////////////
void main()
{
int bLightable = FALSE;
// Check to see if it has a "lightable" item in its inventory
if (GetHasInventory(OBJECT_SELF))
{
object oSource = GetFirstItemInInventory();
while (GetIsObjectValid(oSource))
{
if (GetItemHasItemProperty(oSource,ITEM_PROPERTY_LIGHT))
bLightable = TRUE;
oSource = GetNextItemInInventory();
}
}
if (bLightable) {
if (GetLocalInt(OBJECT_SELF,"NW_L_AMION") == 0)
{
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
DelayCommand(0.4,SetPlaceableIllumination(OBJECT_SELF, TRUE));
SetLocalInt(OBJECT_SELF,"NW_L_AMION",1);
DelayCommand(0.5,RecomputeStaticLighting(GetArea(OBJECT_SELF)));
}
else
{
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
DelayCommand(0.4,SetPlaceableIllumination(OBJECT_SELF, FALSE));
SetLocalInt(OBJECT_SELF,"NW_L_AMION",0);
DelayCommand(0.9,RecomputeStaticLighting(GetArea(OBJECT_SELF)));
}
}
}
