Author Topic: Forcing unequip  (Read 342 times)

Legacy_Alphamojo

  • Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Forcing unequip
« on: October 14, 2011, 01:14:59 pm »


               Been having issues with getting items to unequip when they are supposed to be considered broken.

   object oItem = GetPCItemLastEquipped();
   object oPC   = GetPCItemLastEquippedBy();
   
    if (GetLocalInt(oItem, "BROKENITEM") == 1){
    ClearAllActions(TRUE);
    ActionUnequipItem(oItem);
    FloatingTextStringOnCreature("This item is broken, and cannot be equipped", oPC);
}

Basically it will not unequip an item with this code....is there something else i can do?
               
               

               
            

Legacy_SHOVA

  • Hero Member
  • *****
  • Posts: 893
  • Karma: +0/-0
Forcing unequip
« Reply #1 on: October 14, 2011, 01:59:53 pm »


               try removing the clear all actions line.

If that does not work, Then I would guess because the item is already equiped, that is why it is not working. Try adding unequip the item to where the local int is placed on the item.
               
               

               


                     Modifié par SHOVA, 14 octobre 2011 - 01:02 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Forcing unequip
« Reply #2 on: October 14, 2011, 03:24:28 pm »


               For a force unequip workaround, I've had to go with copying the item to the PCs inventory complete with variables, then destroying the original.  It's a bit crude, but works every time.

 I believe that nwnx for linux might actually have a force unequip option, if you're using that, but otherwise the copy/destroy might be your best option.
               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Forcing unequip
« Reply #3 on: October 14, 2011, 03:31:21 pm »


               Copy/Destroy might be your best option, but with this code you'll want to assign those actions to the PC since it actually the module which is running the OnUnequip event. So change these lines:
ClearAllActions(TRUE);
ActionUnequipItem(oItem);

to these:

AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oPC, ActionUnequipItem(oItem));
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Forcing unequip
« Reply #4 on: October 14, 2011, 05:04:36 pm »


               So with what everyone has already said:

void main()
{
    object oItem = GetPCItemLastEquipped();
    object oPC = GetPCItemLastEquippedBy();

    if (GetLocalInt(oItem, "BROKENITEM") == 1)
    {
        AssignCommand(oPC, ActionUnequipItem(oItem));
        FloatingTextStringOnCreature("This item is broken, and cannot be equipped", oPC);
    }
}
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Forcing unequip
« Reply #5 on: October 14, 2011, 05:26:30 pm »


               

Failed.Bard wrote...

 For a force unequip workaround, I've had to go with copying the item to the PCs inventory complete with variables, then destroying the original.  It's a bit crude, but works every time.

Best option. The code posted by GoG is highly vulnerable to exploits allowing to retain item equipped.

Second best option is to make more than one unequip calls with slight delay.
               
               

               


                     Modifié par ShaDoOoW, 14 octobre 2011 - 04:27 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Forcing unequip
« Reply #6 on: October 14, 2011, 05:38:24 pm »


               

ShaDoOoW wrote...

Failed.Bard wrote...

 For a force unequip workaround, I've had to go with copying the item to the PCs inventory complete with variables, then destroying the original.  It's a bit crude, but works every time.

Best option. The code posted by GoG is highly vulnerable to exploits allowing to retain item equipped.

Second best option is to make more than one unequip calls with slight delay.


Oh yeah. I completely forgot about the needed delay. And the bug with the item getting "stuck" in the slot or what not if there is no delay.
               
               

               
            

Legacy_Alphamojo

  • Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Forcing unequip
« Reply #7 on: October 14, 2011, 11:23:44 pm »


               Thanks guys, I did try copy/destroy option before coming here problem I ran into there was when the character died ( item damage could occur as death penalty ) and items broke seemed to not work to well.

I will try out the assign command, haha i did use delays to try a bully the unequip haha but thought i was being silly...nice to know i was somewhat on right path.

As always thanks, this community still rocks 11 years running =)
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Forcing unequip
« Reply #8 on: October 18, 2011, 07:27:41 am »


               Here's an exploit-proof unequipper script:


void ForceUnequip (object oTarget, object oItem) {
    if (!GetIsObjectValid(oTarget) || GetObjectType(oTarget) != OBJECT_TYPE_CREATURE)
        return;

    if (!GetIsObjectValid(GetArea(oTarget))) {
        DelayCommand(5.0, ForceUnequip(oTarget, oItem));
        return;
    }

    if (GetIsDead(oTarget)) {
        ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectResurrection(), oTarget);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oTarget)), oTarget);

        if (GetIsPC(oTarget))
            AssignCommand(oTarget, ExecuteScript("fky_deathprocess", oTarget));

        DelayCommand(0.1, ForceUnequip(oTarget, oItem));
    } else {
        AssignCommand(oTarget, ClearAllActions(TRUE));

        AssignCommand(oTarget, ActionUnequipItem(oItem));
        AssignCommand(oTarget, ActionDoCommand(SetCommandable(TRUE)));
        AssignCommand(oTarget, SetCommandable(FALSE));
    }
}


This clause:

        if (GetIsPC(oTarget))

            AssignCommand(oTarget, ExecuteScript("fky_deathprocess", oTarget));

is only necessary if you have a script you execute when a player is brought back to life, in which case you would substitute the name of that script. Otherwise just remove that if clause.

Funky
               
               

               


                     Modifié par FunkySwerve, 18 octobre 2011 - 06:29 .
                     
                  


            

Legacy_Alphamojo

  • Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
Forcing unequip
« Reply #9 on: October 18, 2011, 01:10:23 pm »


               Awesome thanks Funky!