Aller au contenu

Photo

Bug in Uncle FB scripts: equipped item switching


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
kamal_

kamal_
  • Members
  • 5 261 messages
There seems to be a bug where if an npc transitions between two activities that require equipped hands (right at least), the npc keeps the item from the first activity. For instance, woodsman to guitar (lute), the npc will keep the handaxe equipped from the woodsman activity.

the following line seems to be the cause
if (oCheck != OBJECT_INVALID) {return;}
in the NpcEquipItemxxxx function does not check that the item equipped is a valid item for the activity.

Here's an npc playing lute with his handaxe. METAL!
600x300http://dl.dropbox.com/u/3879894/NWN2_SS_032512_162109.jpg[/img]

Modifié par kamal_, 25 mars 2012 - 09:02 .


#2
PJ156

PJ156
  • Members
  • 2 988 messages
I found this and could not fix it. It would be great if you have ...

It works if you carry out an activity between switching. So a person that plays lute then chats then plays flute will work just fine.

PJ

#3
kamal_

kamal_
  • Members
  • 5 261 messages
I've only identified it at this point. I would think you could have a sanity check on the item in the scripts, One way would be as part of the functions that carry out the action, check what item is equipped and if it's not the item for the action, run the disarm function and then the item equip function again. The other way would be to move that logic into the equip function itself, this would mean you'd need to check the action of the npc as part of the equip functions.

Doing these things when the npc decides to change action shouldn't be a problem, the npc would most likely be walking from the wp of the first action to that of the second at the change of equipped item

Actually, I was hoping you'd already found this since I know you use Uncle FB, and solved it so I could ask you for your code :D

Modifié par kamal_, 25 mars 2012 - 09:49 .


#4
PJ156

PJ156
  • Members
  • 2 988 messages
Sorry, found it but not fixed it.

I found it most inconvenient when I asked a musician to change instruments on stage since if the music calls for a flute then I like to have the players with the right tools.

In the end, for me, it was a minor inconvienience which I fixed by adding another musician. they rotate on stage so the right instrument is being played.

Sorry to not be of help Kamal_

PJ

#5
kamal_

kamal_
  • Members
  • 5 261 messages
ok, I seem to have been able to fix it (I tested this a few times). It was just a matter of comparing the tag of the equipped item to the tag of the item for the given activity. Fortunately, both the current item and the item for the activity were already recorded by the original script :-)

Here is the corrected script. I removed
if (oCheck != OBJECT_INVALID) {return;}
because it was no longer needed.

//Call before activities that need right hand item with no armor
void NpcEquipItemRight(object oNpc)
{
object oArmor = GetItemInSlot (1, oNpc); //slot 1 is chest
object oCheck = GetItemInSlot (4, oNpc); //slot 4 is right hand
int nAct = GetLocalInt(oNpc, "nCurrentActivity");
string sItem = GetItemString (oNpc, nAct);
if (GetTag(oCheck) != sItem) //has wrong item, disarm. kamal
{
                NpcDisarm (oNpc);
                SetLocalInt (oNpc, "armed", 0);
                EquipNewItem(oNpc, sItem, 4);
                DelayCommand (0.4, EquipNewItem(oNpc, sItem, 4, FALSE));
                SetLocalInt (oNpc, "equipcounter",1);
                SetLocalInt (oNpc, "armed", 1);
}

if (oArmor != OBJECT_INVALID) {NpcDisarm (oNpc);}
if (oCheck == OBJECT_INVALID) {SetLocalInt (oNpc, "armed", 0);}
int nArmed = GetLocalInt (oNpc,"armed");
int nEquip = GetLocalInt (oNpc, "equipcounter");
    {switch (nArmed)
        {
        case 0:                   
            {switch (nEquip)
                {
                default: 
                 {                   
                ClearFlags (oNpc);
                EquipNewItem(oNpc, sItem, 4);
                DelayCommand (0.4, EquipNewItem(oNpc, sItem, 4, FALSE));
                SetLocalInt (oNpc, "equipcounter",1);
                SetLocalInt (oNpc, "armed", 1);
                break;
                }
                case 1:  
                {                   
                ClearFlags (oNpc);
                EquipNewItem(oNpc, sItem, 4);
                DelayCommand (0.4, EquipNewItem(oNpc, sItem, 4, FALSE));
                SetLocalInt (oNpc, "equipcounter",2);
                SetLocalInt (oNpc, "armed", 1);
                break; 
                }
                case 2:   
                {                   
                ClearFlags (oNpc);
                CreateItemOnObject(sItem, oNpc, 1);
                ActionEquipMostDamagingMelee();
                SetLocalInt (oNpc, "equipcounter",3);
                SetLocalInt (oNpc, "armed", 1);
                break;
                }
                case 3:
                {
                break;
                }
                }               
            }                             
        break;
        default:
        break;
        }
    }   
}

Modifié par kamal_, 25 mars 2012 - 11:17 .


#6
kamal_

kamal_
  • Members
  • 5 261 messages
//correct script

//call before activities that need left hand item with no armor
void NpcEquipItemLeft(object oNpc)
{
int nAct = GetLocalInt(oNpc, "nCurrentActivity");
string sItem = GetItemString (oNpc, nAct);
object oCheck = GetItemInSlot (5, oNpc);
if (GetTag(oCheck) != sItem) //has wrong item, disarm. kamal
{
NpcDisarm (oNpc);
SetLocalInt (oNpc, "armed", 0);
EquipNewItem(oNpc, sItem, 4);
DelayCommand (0.4, EquipNewItem(oNpc, sItem, 5, FALSE));
SetLocalInt (oNpc, "equipcounter",1);
SetLocalInt (oNpc, "armed", 1);
}
if (oCheck == OBJECT_INVALID) {SetLocalInt (oNpc, "armed", 0);}
int nArmed = GetLocalInt (oNpc,"armed");
    {switch (nArmed)
        {
        case 0:
        ClearFlags (oNpc);
        DestroyItemInSlot(oNpc, 4);
        EquipNewItem(oNpc, sItem, 5, 1);
        SetLocalInt (oNpc, "armed", 1);
        break;
        default:
        break;
        }
    }    
}

Modifié par kamal_, 25 mars 2012 - 11:14 .