Torch-on-the-wall On/Off script

Hello guys, I am trying to make torches on the walls of my dungeon light up/snuff out on use. I tried using script generator for this script, but it doesn´t work completely. It gets the frist aprt right I use the placeable and the torch lights up, but when I use it again, it doesn´t do anything. Would anyone be so kind please and would point me in the right direction?

Here is the simple script:
void main()
{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = OBJECT_SELF;

if (GetPlaceableIllumination(oTarget))
{
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);

SetPlaceableIllumination (oTarget, FALSE);

}
else
{
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);

SetPlaceableIllumination (oTarget, TRUE);

}

RecomputeStaticLighting(GetArea(oTarget));

}

EDIT: I am using NWN Enhanced Edition.

Weird. As far as I can see, the script looks correct. Don’t know what could be going on.

Question: when you use the torch a second time to turn off the light, so to speak, does the animation play? If it doesn’t then that should point at that the “if” part isn’t running.
Maybe you could do some SendMessageToPC to try and find where it goes wrong?

(As I only work with NWN2, I hope this kind of script works with NWN:EE)
Maybe something like this:

void main()
{

object oPC = GetLastUsedBy();

if (!GetIsPC(oPC)) return;

object oTarget;
oTarget = OBJECT_SELF;

	if (GetPlaceableIllumination(oTarget))
	{
	SendMessageToPC(oPC,"The torch is lit");
	PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
	SendMessageToPC(oPC,"Animation is running");

	SetPlaceableIllumination (oTarget, FALSE);
	SendMessageToPC(oPC,"The torch is no longer lit");

	}
	else
	{
		SendMessageToPC(oPC,"The torch is not lit");
	PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
	SendMessageToPC(oPC,"Animation is running");

	SetPlaceableIllumination (oTarget, TRUE);

	SendMessageToPC(oPC,"The torch is now lit");
	
	}

RecomputeStaticLighting(GetArea(oTarget));

}

Maybe instead of using GetPlaceableIllumination(oTarget) use a variable.

void main()
{
object oPC = GetLastUsedBy();
if (!GetIsPC(oPC)) return;
object oTarget;
oTarget = OBJECT_SELF;
if (GetLocalInt(oTarget, "Lit")==1)
   {
   SetLocalInt(oTarget, "Lit", 0);
   PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
   SetPlaceableIllumination (oTarget, FALSE);
   }
else
   {
   SetLocalInt(oTarget, "Lit", 1);
   PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
   SetPlaceableIllumination (oTarget, TRUE);
   }
RecomputeStaticLighting(GetArea(oTarget));
}

It is not that the GetPlaceableIllumination() function is wrong, it just might not work in this situation

3 Likes

I tested this in NWN2, and it’s quite strange, but the first if statement doesn’t work. So it’s the same for me as for you.

Yes, try @Mannast way instead. Maybe there’s something wrong/buggy with the GetPlaceableIllumination function.

Edit: Tried Mannast script (with my SendMessageToPC, even though I have no torch that can show light, haven’t found that kind of placeable) and everything seems to check out with that script.

Thank you sir, your script works exactly like I wanted! And thanks again to you and to Andgalf for such a quick and helpful response!

1 Like

There is also this @andgalf and @Nathaniel. Useable Lights by Lochlainn.

2 Likes

@raymondsebas Thanks, I’ll try and download that. However, keep in mind that Nathaniel works with NWN:EE so this maybe won’t do him any good downloading this, unless he can check the script files…Maybe you can actually do that and import the nss files in NWN1, I don’t know.

1 Like

From memory, Lochlainn had done it for both games. But you might be right. :neutral_face: