Author Topic: Stripping an NPC of their inventory  (Read 328 times)

Legacy_blurbrbrb

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Stripping an NPC of their inventory
« on: April 24, 2012, 10:09:50 am »


               Fairly, er, obvious title. 

Attempting to mod a thrilling hostage situation, and I'd quite like to strip an NPC of their inventory and transfer it to the player. (Or, if it's even remotely possible, the player and another two NPCs) Would any of you fine ladies and gentlemen have any clue as to how I might go about this?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Stripping an NPC of their inventory
« Reply #1 on: April 24, 2012, 02:01:54 pm »


               It certainly is possible. But we'd need a little more specifics.
What event will cause this to happen? Conversation, pull of a lever, inventory item, etc? And do you want specific items from the one NPC to go to the player and the other NPCs or will it be random? Does this also include equipped items like the NPCs clothing or armor? Which items will go to who?

Probably best to explain exactly what you want to happen.
               
               

               
            

Legacy_blurbrbrb

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Stripping an NPC of their inventory
« Reply #2 on: April 24, 2012, 02:29:06 pm »


               Yeah, sorry - I meant via conversation; the idea was to give the player (currently being held prisoner) an option to overpower one of their guards and hold them hostage, after which they could either provoke a firefight or successfully make the other guards surrender, then instruct the other prisoners to relieve the other guards of their (equipped) weapons and armour. So it'd be a case of Guard A's entire inventory going to the PC, Guard B's entire inventory going to Prisoner A, and Guard C's entire inventory going to Prisoner B.

Thanks for replying - I mostly rely on Lilac Soul's Script Generator so when that lets me down I find myself adrift!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Stripping an NPC of their inventory
« Reply #3 on: April 24, 2012, 04:18:52 pm »


               Hmm. Could try something like this:

void CopyItems(object oReciever, object oTarget)
{
    object oItem;

    oItem = GetFirstItemInInventory(oTarget);
    while ( oItem != OBJECT_INVALID )
    {
        CopyItem(oItem, oReciever, TRUE);
        DestroyObject(oItem);
        oItem = GetNextItemInInventory(oTarget);
    }

    int nCount = NUM_INVENTORY_SLOTS;
    while ( nCount-- > 0 )
    {
        oItem = GetItemInSlot(nCount, oTarget);
        CopyItem(oItem, oReciever, TRUE);
        DestroyObject(oItem);
    }
}

void main()
{
    object oPC = GetPCSpeaker();
    object oGuardA = GetObjectByTag("GuardA");
    object oGuardB = GetObjectByTag("GuardB");
    object oGuardC = GetObjectByTag("GuardC");
    object oPrisonerA = GetObjectByTag("PrisonerA");
    object oPrisonerB = GetObjectByTag("PrisonerB");

    CopyItems(oPC, oGuardA);
    CopyItems(oPrisonerA, oGuardB);
    CopyItems(oPrisonerB, oGuardC);
}


Warning. I am still half asleep and haven't had my morning coffee yet. I also have not tested this. ':blink:'
               
               

               


                     Modifié par GhostOfGod, 24 avril 2012 - 03:20 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Stripping an NPC of their inventory
« Reply #4 on: April 24, 2012, 06:39:31 pm »


               

GhostOfGod wrote...

Hmm. Could try something like this:

void CopyItems(object oReciever, object oTarget)
{
    object oItem;

    oItem = GetFirstItemInInventory(oTarget);
    while ( oItem != OBJECT_INVALID )
    {
        CopyItem(oItem, oReciever, TRUE);
        DestroyObject(oItem);
        oItem = GetNextItemInInventory(oTarget);
    }

  

Looks good, but it will have the same bug as the HotU of not copying over containers with items in them.
               
               

               


                     Modifié par WhiZard, 24 avril 2012 - 05:40 .
                     
                  


            

Legacy_blurbrbrb

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Stripping an NPC of their inventory
« Reply #5 on: April 24, 2012, 08:30:11 pm »


               Many thanks - I'll give that a go!