Aller au contenu

Photo

Destroying player weapons


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

#1
TrekSL

TrekSL
  • Members
  • 32 messages
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!!!!

#2
Alex Warren

Alex Warren
  • Members
  • 179 messages

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 .


#3
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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 .


#4
ffbj

ffbj
  • Members
  • 593 messages
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

#5
Tiggers.no.tail

Tiggers.no.tail
  • Members
  • 41 messages
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 .


#6
Tiggers.no.tail

Tiggers.no.tail
  • Members
  • 41 messages
 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.

#7
ffbj

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

#8
CID-78

CID-78
  • Members
  • 1 124 messages
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.