Author Topic: Creature Weapons for a PC  (Read 333 times)

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Creature Weapons for a PC
« on: September 10, 2014, 08:16:45 pm »


               

I'm trying to create a function that creates a bite/claw for a subrace PC, but am banging my head against a wall trying to figure out why it's not working.


 


Can anyone review the below and see if I've done anything glaring?  It's my understanding that PCs can be granted this feat/wield creature weapons.


 


Essentially, there's a check to see if an item is currently equipped in the creature right-hand weapon.


If the correct item is not found, it unequips items in the PCs hands and checks for the creature weapon proficiency


If the PC does not have the proficiency, it gives it to him/her.


If the PC does not have the item in its inventory, it creates the item on the PC and adds subrace abilities.


It then attempts to equip the item.


Finally, there's a follow-up call to this function again as a fail-safe to ensure the item is equipped.



SendMessageToAllDMs("DEBUG:  Firing");
object oItem= GetItemInSlot(INVENTORY_SLOT_CWEAPON_R,oPC);
string sTag = GetTag (oItem);
//RH does not have item
if (sTag!="sItem")
    {
    SendMessageToAllDMs("DEBUG:  Equip:  CWEAPON_R does not have item");
    //unequip items
    AssignCommand (oPC, ClearAllActions());
    AssignCommand (oPC, ActionUnequipItem(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC)));
    AssignCommand (oPC, ActionUnequipItem(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC)));
    SendMessageToAllDMs("DEBUG:  Equip: Check for  proficiency");
    if(!GetHasFeat (FEAT_WEAPON_PROFICIENCY_CREATURE, oPC))
        {
        SendMessageToAllDMs("DEBUG:  Equip:  PC does not have weapon proficiency");
        NWNXFuncs_AddFeat (oPC, FEAT_WEAPON_PROFICIENCY_CREATURE);
        }
    //nor is it in inventory, so start from scratch
    if (GetItemPossessedBy(oPC, "item")==OBJECT_INVALID)
        {
        SendMessageToAllDMs("DEBUG:  Equip: item not in inventory");
        oItem = CreateItemOnObject ("item", oPC);
        ApplyProperties (oItem, oPC);
        }
    //item in inventory, but not equpped
    DelayCommand(4.0, AssignCommand (oPC, ActionEquipItem(oItem, INVENTORY_SLOT_CWEAPON_R)));
    DelayCommand(6.0, ItemEquip (oPC));    //pseudo-hb to ensure item gets equipped
    SendMessageToAllDMs("DEBUG:  Equip: End of function reached");
    }

What actually happens is that there is a never-ending loop of the item not being in the CWEAPON_R slot, but it is in inventory.  The PC does have the proficiency, but never equips the item.


 


I do have a custom ILR in place that I thought might have been preventing it, but I set the value of the item to 0 in the ApplyProperties function, so it shouldn't trip the ILR.  Plus, there's no message to the PC that they can't equip the item due to a level requirement.


 


Any thoughts about what I'm doing wrong?



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Creature Weapons for a PC
« Reply #1 on: September 10, 2014, 10:48:23 pm »


               

Have you tried equipping the item right then and there rather than delaying it? You never know what state the action queue may be in in 4 seconds.



               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Creature Weapons for a PC
« Reply #2 on: September 10, 2014, 11:10:07 pm »


               BelowTheBelt,
I could be wrong, but as I recall, Item Creation Is always the last thing a script does. A simple script like,
CreateItemOnObject("oSword",oPC);
DelayCommand(3.0,AssCom(oPC,ActEqItem(oSword,nSlot)));
can fail. The Item will be in inventory, but will not be equiped.
You could try a second script to equip the item. I alot of times will set a variable and execute the script again.

if(GetLocalInt) == 1)
{
Equip the Item
}
else
{
Create the Item
SetLocalInt to 1
ExecuteScript(ThisScript,oPC);
}
If this is any help, You're welcome. If not, I'll crawl back into my hole and throw a board into it.

Ed
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Creature Weapons for a PC
« Reply #3 on: September 10, 2014, 11:24:28 pm »


               


Have you tried equipping the item right then and there rather than delaying it? You never know what state the action queue may be in in 4 seconds.




 


I believe that when I originally wrote it, I did not have a delay in there (but it didn't work so I put the delay in).  I also wanted to give some time for the item properties to be properly applied, thinking that possibly it wasn't getting equipped since the properties function hadn't finished.  However, I'll go back and give it another go, thanks.  It's a good point about the action queue.  I suppose I could also set the 'commandable' option on the PC if I need the time for the item properties.


 




BelowTheBelt,

I could be wrong, but as I recall, Item Creation Is always the last thing a script does. A simple script like,

CreateItemOnObject("oSword",oPC);

DelayCommand(3.0,AssCom(oPC,ActEqItem(oSword,nSlot)));

can fail. The Item will be in inventory, but will not be equiped.

You could try a second script to equip the item. I alot of times will set a variable and execute the script again.


if(GetLocalInt) == 1)

{

Equip the Item

}

else

{

Create the Item

SetLocalInt to 1

ExecuteScript(ThisScript,oPC);

}

If this is any help, You're welcome. If not, I'll crawl back into my hole and throw a board into it.


Ed




 


Interesting idea, Ed, thanks.  I'll take a look and see if that works as well.


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Creature Weapons for a PC
« Reply #4 on: September 11, 2014, 12:28:37 am »


               

It's object destruction that does not happen until the end of the script. You can operate on object you create right away. You get the object reference returned from the creation call after all. I don't recall having issues equipping just created item, but maybe I missed it.