Thursday 23 October 2008

Why do the torch lose it's VFX?

Cross-post from NWN2Forums:

While play-testing my module I've noticed that the standard hand-held torch lose it's flame and light effect. I've found four different situations.

1. It sometimes happen when performing an area transition.
2. It often (maybe always) happen when putting the torch in a container.
3. It always happen when using the CopyItem(object, object, int) function.
4. Sometimes it happens without a noticeable cause. I just run around in an area and when equipping the torch it has lost its vfx.

I've tried my own custom light sources and they behave in the same way so I suspect it has something to do with the handling of VFX's on items.

Now I've implemented a "fix lost vfx"-script in the game that the player can use but that's a really ugly solution.

So, is there any solution? Suggestions on a workaround? Any help greatly appreciated!

[EDIT]
There seems to be no solution to this common (as I have come to understand it) problem. So here's a workaround. Place this in your module's OnPlayerUnequipItemScript. It should take care of refreshing the torches and other hand-held light sources every time the PC un-equips them.

// * This code runs when the item is unequipped 
object
oItem = GetPCItemLastUnequipped();

if (GetBaseItemType(oItem) == BASE_ITEM_TORCH)
{
CreateItemOnObject(GetResRef(oItem), GetPCItemLastUnequippedBy(), 1, "", FALSE);
DestroyObject(oItem, 0.1, FALSE);
}
See you later friends!

/A

2 comments:

Lance Botelle (Bard of Althéa) said...

I vaguely remember reading that VFXs can have some issues. I think there was a mod demonstrating some new effects that had the same problem of sometimes going off (or not) as the case may be.

I also recall one of my own VFX acting strangely, but tracked that down to a logic isssue that checked when or when not to activate the effect on a heartbeat. It was one stage more complex than I first thought, requiring a second integer check when confirming something was actually "alight". (This may not make much sense unless you are trying the same sort of thing.)

Lance.

Amraphael said...

Thanks for the suggestion, Lance. I'll take a look at it. It's as you say, probably not the the same error but it's definitely worth an extra examination.