Author Topic: Destroying player weapons  (Read 316 times)

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
Destroying player weapons
« on: July 29, 2011, 02:30:39 pm »


               Trying to remove a sword from someone's inventory but I'm not sure how it's done (I think to check an inventory for weapons you'd need to equip one to a slot and then destroy whatever is in the slot)

Finally, as an aside - in playing about the the toolset and doing variable checks, have any of you figured out a more elegant way of doing it? By the end of mine, I has so many different check scripts that I lost track of the names I was giving them!!!!
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Destroying player weapons
« Reply #1 on: July 29, 2011, 03:30:50 pm »


               

I think to check an inventory for weapons you'd need to equip one to a slot and then destroy whatever is in the slot.

Yes, you would have to check that in case player has equipped the sword. To check if item is in characters inventory you can use two scripts:


void main()
{
object oPC = (depends form where you call this script)
object oSword = GetItemPossessedBy(oPC, "swords_tag");
DestroyObject(oSword);
}

second - looping through characters inventory


void main()
{
object oPC = (same as above)
object oItem = GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{
    if(GetTag(oItem) == "swords_tag")
{
        DestroyObject(oItem);
}
    oItem = GetNextItemInInventory(oPC);
}
}

               
               

               


                     Modifié par Alex Warren, 29 juillet 2011 - 02:36 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Destroying player weapons
« Reply #2 on: July 29, 2011, 08:40:21 pm »


               This will remove the sword whether it is equipped, in players inventory, or in another container in the players inventory. Just plug in the tag of your sword:


void main()
{
    object oTarget = GetEnteringObject();
    object oItem = GetFirstItemInInventory(oTarget);
    int iSlot;

    //Loop through inventory items
    while (GetIsObjectValid(oItem))
    {
        //if item is a container, loop through items inside
        if (GetHasInventory(oItem))
        {
            object oConItem = GetFirstItemInInventory(oItem);
            while (GetIsObjectValid(oConItem))
            {
                if (GetTag(oConItem) == "Tag of sword here")
                DestroyObject(oConItem);
                oConItem = GetNextItemInInventory(oItem);
            }
        }
        else
        {
            if (GetTag(oItem) == "Tag of sword here")
            DestroyObject(oItem);
        }
        oItem = GetNextItemInInventory(oTarget);
    }

    //Cycle through equipped items.
    for (iSlot=0; iSlot<NUM_INVENTORY_SLOTS; iSlot++)
    {
        oItem = GetItemInSlot(iSlot, oTarget);
        if (GetTag(oItem) == "Tag of sword here")
        DestroyObject(oItem);
    }
}
               
               

               


                     Modifié par GhostOfGod, 29 juillet 2011 - 07:42 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Destroying player weapons
« Reply #3 on: July 30, 2011, 02:46:45 pm »


               If  you want to destroy the item when it's equipped you don't need a tag, just oItem and then the inventory slot.  Though you did say inventory.  For instance I have a door with magic runes on it that will destroy your sword if you bash it
               
               

               
            

Legacy_Tiggers.no.tail

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
Destroying player weapons
« Reply #4 on: July 31, 2011, 10:25:38 am »


               void StripPlayer( object oPlayer ) {
   //the first time the player load in they lose everything in their inventory

       //destroy everything they have currently equipped
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_ARMS ) ) );
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_ARROWS, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_BELT, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_BOLTS, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_BOOTS, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_BULLETS, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CARMOUR, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CHEST, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CLOAK, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CWEAPON_B, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CWEAPON_L, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_CWEAPON_R, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_HEAD, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_LEFTHAND, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_LEFTRING, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_NECK, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_RIGHTHAND, oPlayer ) ));
       AssignCommand( oPlayer, DestroyObject( GetItemInSlot( INVENTORY_SLOT_RIGHTRING, oPlayer ) ));

       //temporary object of what is in inventory
       object oItem = GetFirstItemInInventory( oPlayer );

       //get each item in the inventory
       while( oItem != OBJECT_INVALID )
       {
           //destroy it
           DestroyObject( oItem );

           //get the next item
           oItem = GetNextItemInInventory( oPlayer );
       }


   //take away their gold too
   //TakeGoldFromCreature( GetGold( oPlayer ), oPlayer, TRUE );

}
               
               

               


                     Modifié par Tiggers.no.tail, 31 juillet 2011 - 09:29 .
                     
                  


            

Legacy_Tiggers.no.tail

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
Destroying player weapons
« Reply #5 on: July 31, 2011, 10:33:23 am »


                And yes, in my short experience you will be doing a LOT of variables checks. I try to follow a standard form for the pre-req and action scripts. something of the form

Pre-reqs:

schk_<VARNAME><VARVALUE>

for example:
schk_conv_jero1

would indicate that it is a script to check (schk) for a conversation variable (conv) for actor jero of value 1

For action scripts

set_<VARNAME><VARVALUE>

for example
set_conv_jero01

would indicate that the script is setting the conversation variable for jero to 1

for generic scripts I simply use
sc_<DESCRIPTION>

for example

sc_tele_pc

for things I want to trigger stuff (only from triggers) i preface the script with
tr_<DESCRIPTION>

I'm sure theres a better way, but I havent found it.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Destroying player weapons
« Reply #6 on: August 01, 2011, 03:20:31 am »


               That's worthwhile information though I think what the op wanted was just to destroy a specific sword in the players inventory.
               
               

               
            

Legacy_CID-78

  • Sr. Member
  • ****
  • Posts: 261
  • Karma: +0/-0
Destroying player weapons
« Reply #7 on: August 01, 2011, 06:59:14 am »


               you can avoid alot of check by storing the pieces in easy accessible places. and use Naming system. The script will adapt to the pieces and pull the right answear. ie instead of going Get->JeroState1. you go Get->Jero->1 and you can replace the "jero" piece with "harry" on another NPC and the same script will work.

aslong as each piece is store on the NPC and not hardcoded in the script. (you probably can't do something about the 1, since you usually want to beable to check all the states in the same conversation.