Skip to content

Unequip item by tag && area is clean

Hi.. , :) Could you help me about this?

i have a mod with a wolf as hechman, and i wish it unequip item when a playergame put it to the wolf, if item has NOT an especific TAG (premade item by me)
***

Thaaanks :)

And how do you do the tipycal mision..

Area A:
"clean this area (B) of monsters and returnt to me"?

Thaaanks :)

Comments

  • TheBarbarianTheBarbarian Member Posts: 58
    Hi. :-)

    For the item, it might be easiest to disable inventory access for the wolf entirely and have the player give the item to the wolf via dialogue.

    In the wolf's dialogue, create an option [Give item]. Add a condition to it:
    
    int StartingConditional()
    {
        return (GetItemPossessedBy(GetPCSpeaker(), "TagOfTheItemHere") != OBJECT_INVALID);
    }
    
    (if the player speaker has an item tagged "TagOfTheItemHere", this dialogue option appears)

    In the "Actions Taken When..." tab of the same node, add a script to give the item to the wolf, and to make the wolf equip it:
    
    void main()
    {
        object oPC   = GetPCSpeaker();
        object oItem = GetItemPossessedBy(oPC, "TagOfTheItemHere");
    
        ClearAllActions(TRUE);
        ActionTakeItem(oItem, oPC);
        ActionEquipItem(oItem, INVENTORY_SLOT_NECK);
    }
    
    (take the first found item tagged "TagOfTheItemHere" from the player, then equip it into the Neck slot)

    The ActionEquipItem command needs to specify the correct inventory slot for the item type. Trying to equip an amulet into the chest slot would fail.


    Assuming that you're using the x2_henchman scripts for the wolf - set the local int X2_JUST_A_DISABLEEQUIP to 1 on the wolf, and the player can no longer open their inventory.




    If you want to instantaneously destroy all enemies in the area, you could cycle through them like this, for example:
    
    int i = 1;
    object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, i);
    while (oTarget != OBJECT_INVALID)
        {
        DestroyObject(oTarget);
        oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, ++i);    
        }
    or like this:
    object oArea = GetArea(oPC);
    object oTarget = GetFirstObjectInArea(oArea);
    while (oTarget != OBJECT_INVALID)
        {
        if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetIsEnemy(oTarget, oPC))
             DestroyObject(oTarget);    
    
        oTarget = GetNextObjectInArea(oArea);
        }




    If you want your wolf to autonomously go hunt down enemies and return to the player once all enemies in the area are dead, you could set off a recursive:
    
    void Wolf_GoHunt(object oMaster)
    {
        // Abort if either the wolf or it's master are dead,
        // or if it doesn't have the hunting variable set anymore (manual abort).
        if (GetIsDead(OBJECT_SELF) ||
            GetIsDead(oMaster)     ||
            !GetLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING"))
            return;
    
        // If an enemy is found and we aren't currently attacking something, attack it.
        int nContinueHunting;
        object oNearestEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY);
        if (oNearestEnemy != OBJECT_INVALID &&
            GetCurrentAction() != ACTION_ATTACKOBJECT)
            {
            nContinueHunting = TRUE;
            ActionAttack(oNearestEnemy);
            }
    
        // If we're done hunting, we should return to our master.
        if (!nContinueHunting)
            {
            ClearAllActions();
            ActionForceFollowObject(oMaster, 1.0);
            SendMessageToPC(oMaster, "The wolf has finished hunting.");
            DeleteLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING");
            }
        else
            DelayCommand(10.0, Wolf_GoHunt(oMaster));
    }
    
  • Sfera_RojaSfera_Roja Member Posts: 9
    Hi. :-)

    For the item, it might be easiest to disable inventory access for the wolf entirely and have the player give the item to the wolf via dialogue.

    In the wolf's dialogue, create an option [Give item]. Add a condition to it: int StartingConditional() { return (GetItemPossessedBy(GetPCSpeaker(), "TagOfTheItemHere") != OBJECT_INVALID); }

    (if the player speaker has an item tagged "TagOfTheItemHere", this dialogue option appears)

    In the "Actions Taken When..." tab of the same node, add a script to give the item to the wolf, and to make the wolf equip it: void main() { object oPC = GetPCSpeaker(); object oItem = GetItemPossessedBy(oPC, "TagOfTheItemHere"); ClearAllActions(TRUE); ActionTakeItem(oItem, oPC); ActionEquipItem(oItem, INVENTORY_SLOT_NECK); }

    (take the first found item tagged "TagOfTheItemHere" from the player, then equip it into the Neck slot)

    The ActionEquipItem command needs to specify the correct inventory slot for the item type. Trying to equip an amulet into the chest slot would fail.


    Assuming that you're using the x2_henchman scripts for the wolf - set the local int X2_JUST_A_DISABLEEQUIP to 1 on the wolf, and the player can no longer open their inventory.




    If you want to instantaneously destroy all enemies in the area, you could cycle through them like this, for example: int i = 1; object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, i); while (oTarget != OBJECT_INVALID) { DestroyObject(oTarget); oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, ++i); }

    or like this:object oArea = GetArea(oPC); object oTarget = GetFirstObjectInArea(oArea); while (oTarget != OBJECT_INVALID) { if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetIsEnemy(oTarget, oPC)) DestroyObject(oTarget); oTarget = GetNextObjectInArea(oArea); }





    If you want your wolf to autonomously go hunt down enemies and return to the player once all enemies in the area are dead, you could set off a recursive: void Wolf_GoHunt(object oMaster) { // Abort if either the wolf or it's master are dead, // or if it doesn't have the hunting variable set anymore (manual abort). if (GetIsDead(OBJECT_SELF) || GetIsDead(oMaster) || !GetLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING")) return; // If an enemy is found and we aren't currently attacking something, attack it. int nContinueHunting; object oNearestEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY); if (oNearestEnemy != OBJECT_INVALID && GetCurrentAction() != ACTION_ATTACKOBJECT) { nContinueHunting = TRUE; ActionAttack(oNearestEnemy); } // If we're done hunting, we should return to our master. if (!nContinueHunting) { ClearAllActions(); ActionForceFollowObject(oMaster, 1.0); SendMessageToPC(oMaster, "The wolf has finished hunting."); DeleteLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING"); } else DelayCommand(10.0, Wolf_GoHunt(oMaster)); }

    thaaanks, guy.. sorry if see it now, i forget it :)
    GREAT JOB :)
  • Sfera_RojaSfera_Roja Member Posts: 9
    Hi. :-)

    For the item, it might be easiest to disable inventory access for the wolf entirely and have the player give the item to the wolf via dialogue.

    In the wolf's dialogue, create an option [Give item]. Add a condition to it: int StartingConditional() { return (GetItemPossessedBy(GetPCSpeaker(), "TagOfTheItemHere") != OBJECT_INVALID); }

    (if the player speaker has an item tagged "TagOfTheItemHere", this dialogue option appears)

    In the "Actions Taken When..." tab of the same node, add a script to give the item to the wolf, and to make the wolf equip it: void main() { object oPC = GetPCSpeaker(); object oItem = GetItemPossessedBy(oPC, "TagOfTheItemHere"); ClearAllActions(TRUE); ActionTakeItem(oItem, oPC); ActionEquipItem(oItem, INVENTORY_SLOT_NECK); }

    (take the first found item tagged "TagOfTheItemHere" from the player, then equip it into the Neck slot)

    The ActionEquipItem command needs to specify the correct inventory slot for the item type. Trying to equip an amulet into the chest slot would fail.


    Assuming that you're using the x2_henchman scripts for the wolf - set the local int X2_JUST_A_DISABLEEQUIP to 1 on the wolf, and the player can no longer open their inventory.




    If you want to instantaneously destroy all enemies in the area, you could cycle through them like this, for example: int i = 1; object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, i); while (oTarget != OBJECT_INVALID) { DestroyObject(oTarget); oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oPC, ++i); }

    or like this:object oArea = GetArea(oPC); object oTarget = GetFirstObjectInArea(oArea); while (oTarget != OBJECT_INVALID) { if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE && GetIsEnemy(oTarget, oPC)) DestroyObject(oTarget); oTarget = GetNextObjectInArea(oArea); }





    If you want your wolf to autonomously go hunt down enemies and return to the player once all enemies in the area are dead, you could set off a recursive: void Wolf_GoHunt(object oMaster) { // Abort if either the wolf or it's master are dead, // or if it doesn't have the hunting variable set anymore (manual abort). if (GetIsDead(OBJECT_SELF) || GetIsDead(oMaster) || !GetLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING")) return; // If an enemy is found and we aren't currently attacking something, attack it. int nContinueHunting; object oNearestEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY); if (oNearestEnemy != OBJECT_INVALID && GetCurrentAction() != ACTION_ATTACKOBJECT) { nContinueHunting = TRUE; ActionAttack(oNearestEnemy); } // If we're done hunting, we should return to our master. if (!nContinueHunting) { ClearAllActions(); ActionForceFollowObject(oMaster, 1.0); SendMessageToPC(oMaster, "The wolf has finished hunting."); DeleteLocalInt(OBJECT_SELF, "WOLF_IS_HUNTING"); } else DelayCommand(10.0, Wolf_GoHunt(oMaster)); }

    In the fact, i asked about the tipycal mission of cleanimg am area of enemies and get reward in other ..., lool
    Its in incleible the things a good writter screeps can do.. o_o
Sign In or Register to comment.