ActionEquipItem and ActionUnEquipItem weirdness? [FIXED]

In the latest stable release of EE, I can no longer do the following:

AssignCommand(oPC, ActionUnequipItem(GetItemInSlot(INVENTORY_SLOT_LEFTHAND)));

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?

Curious - that still works in my module (for both torches and shields).

I have exactly that ActionUnequipItem call within a function that is assigned as a command - but I don’t suppose that makes any difference.

Working here as well.

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:

    #include "x2_inc_switches"

    void OnEquip(object oItem, object oEquippedBy);

    void main()
    {
        int nEvent = GetUserDefinedItemEventNumber();

        switch (nEvent)
        {
            case X2_ITEM_EVENT_EQUIP:
                OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy());
                break;
        }
    }

    void OnEquip(object oItem, object oEquippedBy)
    {
            AssignCommand(oEquippedBy, ClearAllActions());
            AssignCommand(oEquippedBy, ActionUnequipItem(oItem));
    }

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.

1 Like

:crazy_face: Ah yes, my old nemesis, Is Equal to!!!

Thanks @Proleric for catching that! I still need the delay command on the UnEquip so that the VoiceChat and SpeakString function properly.

All is good now.