What happens is that the PC continues to hold the torch aloft but it also appears in inventory. This script used to work just fine in earlier releases. Any ideas?
From the screenshot I see, that you pc has nothing in his hand. So the unequip actually works. There seams to be a check on heartbeat (more than one “unsafe” line). Maybe here is a bug. That your PC appears with a torch could be a graphics / creature model issue.
In an attempt to eliminate as many variables as possible, I did the following:
Create a new module
Create a custom torch called “torch” (name, tag, & resref) and also “shield” and “dagger”
Create the following script:
Result: Item always equips but is grayed out in inventory. When unequipped from the toolbar, it almost never unequips unless replaced by a different item, e.g. torch by shield and vice versa.
What am I missing here? Can anyone else follow the same steps and get the same or different result?
Okay, I fixed the unequip problem by introducing a delay. However I also added a VoiceChat and a SpeakString which fire both on ACQUIRE as well as EQUIP!!! Here is the code:
#include "x2_inc_switches"
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
object oArea = GetArea(oPC);
int bTorchSafe = GetLocalInt(oArea, "bTorchSafe");
if (nEvent = X2_ITEM_EVENT_EQUIP)
{
if (bTorchSafe != TRUE)
{
AssignCommand(oPC, PlayVoiceChat(VOICE_CHAT_BADIDEA));
AssignCommand(oPC, ActionSpeakString("It's not safe to equip torches here."));
DelayCommand(0.5, AssignCommand(oPC, ActionUnequipItem(oItem)));
}
}
}
Context is everything! I’m pretty sure I’ve seen ghosting of this sort before EE when the equip / unequip events are firing close together, solved by a short delay.
The reason all events are firing the chat is that you have = where you mean == X2_ITEM_EVENT_EQUIP.