Author Topic: Disarm weapon script?  (Read 709 times)

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
Disarm weapon script?
« on: November 24, 2010, 12:55:15 am »


                Shocked to find zero of these on the vault. I know ive played on servers where if you do a succesful disarm your enemies weapon goes into its backpack instead of falling to the ground. I am also wanting there to be a short period before that weapon can be reequipped if thats possible.

 Anyone know?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Disarm weapon script?
« Reply #1 on: November 25, 2010, 12:07:34 am »


               You would need to alter your modules "OnUnAcquireItem" script. This is what the default "x2_mod_def_unaqu" script would look like with the needed changes:


//::///////////////////////////////////////////////
//:: Example XP2 OnItemUnAcquireScript
//:: x2_mod_def_unaqu
//:: © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*

    Put into: OnItemUnAcquire Event

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////

#include "x2_inc_switches"
#include "x2_inc_itemprop"
void main()
{
     object oItem = GetModuleItemLost();

     ///////////////////////////////////////////////////////////////////////////

     //::Added to place disarmed weapons back into a player inventory.
     ///////////////////////////////////////////////////////////////////////////
     object oPC = GetModuleItemLostBy();
     int iLoopStop = GetLocalInt(oItem, "LOOP_STOP");

     if (GetIsPC(oPC) && GetIsInCombat(oPC))
        {
        if (IPGetIsMeleeWeapon(oItem))
            {
            if (iLoopStop != TRUE)
                {
                SetLocalInt(oItem, "LOOP_STOP", TRUE);

                object oCopy = CopyItem(oItem, oPC, TRUE);
                DelayCommand(2.0, DeleteLocalInt(oCopy, "LOOP_STOP"));
                DestroyObject(oItem, 0.0);
                }
            }

        }
     ///////////////////////////////////////////////////////////////////////////

     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,

     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss

     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);

        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }
    }
}


This does not include anything for delaying the ability to equipp the weapon again. I suppose you could just add another variable to the weapon and then add a delay to delete the variable. Then go to your "OnPlayerEquipItem" script and do a check for the variable. If found then unequip the weapon?

Hope this helps. good luck.

P.S. This also takes into consideration the fact that the players inventory might be full. In which case the item will still have to go onto the ground.
               
               

               


                     Modifié par GhostOfGod, 25 novembre 2010 - 12:09 .
                     
                  


            

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
Disarm weapon script?
« Reply #2 on: November 25, 2010, 07:23:05 am »


               wow thanks for this. I will test it out soon. I am terrible with scripting beyond Lilacs generator so I really do appreciate it.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Disarm weapon script?
« Reply #3 on: November 25, 2010, 10:26:36 pm »


               Can only melee weapons be disarmed?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Disarm weapon script?
« Reply #4 on: November 25, 2010, 11:01:07 pm »


               

Baragg wrote...

Can only melee weapons be disarmed?


I was under the impression that was the case. However since I've never used it I am most likely mistaken.

If Baragg is correct then this line:

if (IPGetIsMeleeWeapon(oItem))

should be changed to:

if (IPGetIsMeleeWeapon(oItem) || IPGetIsRangedWeapon(oItem))
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Disarm weapon script?
« Reply #5 on: November 25, 2010, 11:23:00 pm »


               Here's our function for this, which includes CEP weapon types:

int GetItemIsWeapon (object oItem) {
    switch (GetBaseItemType(oItem)) {
        case BASE_ITEM_CLUB:
        case BASE_ITEM_DIREMACE:
        case BASE_ITEM_HEAVYFLAIL:
        case BASE_ITEM_LIGHTFLAIL:
        case BASE_ITEM_LIGHTHAMMER:
        case BASE_ITEM_LIGHTMACE:
        case BASE_ITEM_MORNINGSTAR:
        case BASE_ITEM_QUARTERSTAFF:
        case BASE_ITEM_WARHAMMER:

        case BASE_ITEM_DAGGER:
        case BASE_ITEM_RAPIER:
        case BASE_ITEM_SHORTSPEAR:
        case BASE_ITEM_SHORTSWORD:
        case BASE_ITEM_TRIDENT:
        case BASE_ITEM_LANCE:

        case BASE_ITEM_BASTARDSWORD:
        case BASE_ITEM_BATTLEAXE:
        case BASE_ITEM_DOUBLEAXE:
        case BASE_ITEM_DWARVENWARAXE:
        case BASE_ITEM_GREATAXE:
        case BASE_ITEM_GREATSWORD:
        case BASE_ITEM_HALBERD:
        case BASE_ITEM_HANDAXE:
        case BASE_ITEM_KAMA:
        case BASE_ITEM_KATANA:
        case BASE_ITEM_KUKRI:
        case BASE_ITEM_LONGSWORD:
        case BASE_ITEM_SCIMITAR:
        case BASE_ITEM_SCYTHE:
        case BASE_ITEM_SICKLE:
        case BASE_ITEM_TWOBLADEDSWORD:
        case BASE_ITEM_WHIP:

        case BASE_ITEM_DART:
        case BASE_ITEM_HEAVYCROSSBOW:
        case BASE_ITEM_LIGHTCROSSBOW:
        case BASE_ITEM_LONGBOW:
        case BASE_ITEM_SHORTBOW:
        case BASE_ITEM_SHURIKEN:
        case BASE_ITEM_SLING:
        case BASE_ITEM_THROWINGAXE:

        case BASE_ITEM_MAGICSTAFF:

        case BASE_ITEM_CEP_ASSASSINDAGGER:
        case BASE_ITEM_CEP_DOUBLEPICK:
        case BASE_ITEM_CEP_DOUBLESCIMITAR:
        case BASE_ITEM_CEP_FALCHION:
        case BASE_ITEM_CEP_GOAD:
        case BASE_ITEM_CEP_HEAVYMACE:
        case BASE_ITEM_CEP_HEAVYPICK:
        case BASE_ITEM_CEP_KATAR:
        case BASE_ITEM_CEP_LIGHTPICK:
        case BASE_ITEM_CEP_MAUL:
        case BASE_ITEM_CEP_MERCURIALGREATSWORD:
        case BASE_ITEM_CEP_MERCURIALLONGSWORD:
        case BASE_ITEM_CEP_NUNCHAKU:
        case BASE_ITEM_CEP_SAI:
        case BASE_ITEM_CEP_SAP:
        case BASE_ITEM_CEP_WINDFIREWHEEL:
            return TRUE;
    }

    return FALSE;
}

Here are all the non-standard consts:


const int BASE_ITEM_LANCE                                         = 92;
const int BASE_ITEM_TRUMPET                                       = 93;
const int BASE_ITEM_MOONONASTICK                                  = 94;
const int BASE_ITEM_CRAFTBASE                                     = 112;
const int BASE_ITEM_CEP_COINS                                     = 203;
const int BASE_ITEM_CEP_THINBOX                                   = 204;
const int BASE_ITEM_CEP_HERB_SMALL                                = 205;
const int BASE_ITEM_CEP_HERB_THIN                                 = 206;
const int BASE_ITEM_CEP_STACKSMALL_1                              = 207;
const int BASE_ITEM_CEP_PELT_LARGE                                = 208;
const int BASE_ITEM_CEP_PELT_THIN                                 = 209;
const int BASE_ITEM_CEP_TINYSPEAR                                 = 210;
const int BASE_ITEM_CEP_MISCSMALL_3                               = 211;
const int BASE_ITEM_CEP_MISCMEDIUM_3                              = 212;
const int BASE_ITEM_CEP_DYE                                       = 224;
const int BASE_ITEM_CEP_TRIDENT                                   = 300;
const int BASE_ITEM_CEP_HEAVYPICK                                 = 301;
const int BASE_ITEM_CEP_LIGHTPICK                                 = 302;
const int BASE_ITEM_CEP_SAI                                       = 303;
const int BASE_ITEM_CEP_NUNCHAKU                                  = 304;
const int BASE_ITEM_CEP_FALCHION                                  = 305;
const int BASE_ITEM_CEP_SMALLBOX                                  = 306;
const int BASE_ITEM_CEP_MISCMEDIUM_2                              = 307;
const int BASE_ITEM_CEP_SAP                                       = 308;
const int BASE_ITEM_CEP_ASSASSINDAGGER                            = 309;
const int BASE_ITEM_CEP_KATAR                                     = 310;
const int BASE_ITEM_CEP_MISCSMALL_2                               = 311;
const int BASE_ITEM_CEP_FASHION_ACCESSORY                         = 314;
const int BASE_ITEM_CEP_HEAVYMACE                                 = 317;
const int BASE_ITEM_CEP_MAUL                                      = 318;
const int BASE_ITEM_CEP_MERCURIALLONGSWORD                        = 319;
const int BASE_ITEM_CEP_MERCURIALGREATSWORD                       = 320;
const int BASE_ITEM_CEP_DOUBLESCIMITAR                            = 321;
const int BASE_ITEM_CEP_GOAD                                      = 322;
const int BASE_ITEM_CEP_WINDFIREWHEEL                             = 323;
const int BASE_ITEM_CEP_DOUBLEPICK                                = 324;
const int BASE_ITEM_CEP_FLOWERS                                   = 325;
const int BASE_ITEM_CEP_CLOAK                                     = 349;
const int BASE_ITEM_CEP_RING_2                                    = 350;
const int BASE_ITEM_CEP_AMULET_2                                  = 351;
const int BASE_ITEM_CEP_BUCKLER                                   = 352;
const int BASE_ITEM_CEP_RING_ARMOR                                = 353;
const int BASE_ITEM_CEP_RING_NATURAL                              = 354;
const int BASE_ITEM_CEP_RING_SHIELD                               = 355;
const int BASE_ITEM_CEP_AMULET_ARMOR                              = 356;
const int BASE_ITEM_CEP_AMULET_DEFLECT                            = 357;
const int BASE_ITEM_CEP_AMULET_SHIELD                             = 358;
const int BASE_ITEM_CEP_BELT_ARMOR                                = 359;
const int BASE_ITEM_CEP_BELT_NATURAL                              = 360;
const int BASE_ITEM_CEP_BELT_SHIELD                               = 361;
const int BASE_ITEM_CEP_BRACER_SHIELD                             = 362;
const int BASE_ITEM_CEP_CLOAK_ARMOR                               = 363;
const int BASE_ITEM_CEP_CLOAK_DODGE                               = 364;
const int BASE_ITEM_CEP_CLOAK_NATURAL                             = 365;
const int BASE_ITEM_CEP_CLOAK_SHIELD                              = 366;
const int BASE_ITEM_CEP_TORCH_SHIELD                              = 367;
const int BASE_ITEM_CEP_RING_2_ARMOR                              = 368;
const int BASE_ITEM_CEP_RING_2_NATURAL                            = 369;
const int BASE_ITEM_CEP_RING_2_SHIELD                             = 370;
const int BASE_ITEM_CEP_AMULET_2_ARMOR                            = 371;
const int BASE_ITEM_CEP_AMULET_2_DEFLECT                          = 372;
const int BASE_ITEM_CEP_AMULET_2_SHIELD                           = 373;
const int BASE_ITEM_CEP_RUNESTONE                                 = 374;
const int BASE_ITEM_CEP_HELMET_ARMOR                              = 375;
const int BASE_ITEM_CEP_GLOVES_SPIKED                             = 376;
const int BASE_ITEM_CEP_GLOVES_BLADED                             = 377;
const int BASE_ITEM_CEP_MISCSMALL_4                               = 380;
const int BASE_ITEM_CEP_MISCMEDIUM_4                              = 381;
const int BASE_ITEM_CEP_MISCTHIN_2                                = 382;
const int BASE_ITEM_CEP_MISCTHIN_3                                = 383;
const int BASE_ITEM_CEP_MISCTHIN_4                                = 384;
const int BASE_ITEM_CEP_MISCLARGE_2                               = 385;
const int BASE_ITEM_CEP_MISCLARGE_3                               = 386;
const int BASE_ITEM_CEP_MISCLARGE_4                               = 387;
const int BASE_ITEM_CEP_STACKSMALL_2                              = 388;
const int BASE_ITEM_CEP_STACKSMALL_3                              = 389;
const int BASE_ITEM_CEP_STACKSMALL_4                              = 390;
const int BASE_ITEM_CEP_STACKMEDIUM_1                             = 391;
const int BASE_ITEM_CEP_STACKMEDIUM_2                             = 392;
const int BASE_ITEM_CEP_STACKMEDIUM_3                             = 393;
const int BASE_ITEM_CEP_STACKMEDIUM_4                             = 394;
const int BASE_ITEM_CEP_STACKTHIN_1                               = 395;
const int BASE_ITEM_CEP_STACKTHIN_2                               = 396;
const int BASE_ITEM_CEP_STACKTHIN_3                               = 397;
const int BASE_ITEM_CEP_STACKTHIN_4                               = 398;
const int BASE_ITEM_CEP_STACKLARGE_1                              = 399;
const int BASE_ITEM_CEP_STACKLARGE_2                              = 400;
const int BASE_ITEM_CEP_STACKLARGE_3                              = 401;
const int BASE_ITEM_CEP_STACKLARGE_4                              = 402;

Funky
               
               

               


                     Modifié par FunkySwerve, 25 novembre 2010 - 11:24 .
                     
                  


            

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
Disarm weapon script?
« Reply #6 on: November 26, 2010, 01:21:18 am »


               so what would that look like combined with the other script then? '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Disarm weapon script?
« Reply #7 on: November 27, 2010, 04:33:42 am »


               Ok. So with Funky's function(slightly altered) and implementing the delay for equipping the disarmed weapon, the new "OnUnAcquireItem" script would look something like so(the red highlited part is what I added for the equip delay. You can adjust the ten seconds to however long you want):

//::///////////////////////////////////////////////
//:: Example XP2 OnItemUnAcquireScript
//:: x2_mod_def_unaqu
//:: © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*

    Put into: OnItemUnAcquire Event

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////

#include "x2_inc_switches"
#include "x2_inc_itemprop"
#include "zep_inc_main"

//GetItemIsWeapon prototype:
int GetItemIsWeapon(object oItem);

const int BASE_ITEM_LANCE = 92;
const int BASE_ITEM_DOUBLEPICK = 324;

void main()
{
    object oItem = GetModuleItemLost();

    ///////////////////////////////////////////////////////////////////////////

    //::Added to place disarmed weapons back into a player inventory.
    ///////////////////////////////////////////////////////////////////////////
    object oPC = GetModuleItemLostBy();
    int iLoopStop = GetLocalInt(oItem, "LOOP_STOP");

    if (GetIsPC(oPC) && GetIsInCombat(oPC))
    {
        if (GetItemIsWeapon(oItem))
        {
            if (iLoopStop != TRUE)
            {
                SetLocalInt(oItem, "LOOP_STOP", TRUE);
                SetLocalInt(oItem, "EQUIP_DELAY", TRUE);
                object oCopy = CopyItem(oItem, oPC, TRUE);
                DelayCommand(2.0, DeleteLocalInt(oCopy, "LOOP_STOP"));
                //Equip delay below:
                DelayCommand(10.0, DeleteLocalInt(oCopy, "EQUIP_DELAY"));
                DestroyObject(oItem, 0.0);
            }
        }
    }
     ///////////////////////////////////////////////////////////////////////////

     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,

     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss

     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);

        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }
    }
}

int GetItemIsWeapon(object oItem)
{
    switch (GetBaseItemType(oItem))
    {
        case BASE_ITEM_CLUB:
        case BASE_ITEM_DIREMACE:
        case BASE_ITEM_HEAVYFLAIL:
        case BASE_ITEM_LIGHTFLAIL:
        case BASE_ITEM_LIGHTHAMMER:
        case BASE_ITEM_LIGHTMACE:
        case BASE_ITEM_MORNINGSTAR:
        case BASE_ITEM_QUARTERSTAFF:
        case BASE_ITEM_WARHAMMER:

        case BASE_ITEM_DAGGER:
        case BASE_ITEM_RAPIER:
        case BASE_ITEM_SHORTSPEAR:
        case BASE_ITEM_SHORTSWORD:
        case BASE_ITEM_TRIDENT:
        case BASE_ITEM_LANCE:

        case BASE_ITEM_BASTARDSWORD:
        case BASE_ITEM_BATTLEAXE:
        case BASE_ITEM_DOUBLEAXE:
        case BASE_ITEM_DWARVENWARAXE:
        case BASE_ITEM_GREATAXE:
        case BASE_ITEM_GREATSWORD:
        case BASE_ITEM_HALBERD:
        case BASE_ITEM_HANDAXE:
        case BASE_ITEM_KAMA:
        case BASE_ITEM_KATANA:
        case BASE_ITEM_KUKRI:
        case BASE_ITEM_LONGSWORD:
        case BASE_ITEM_SCIMITAR:
        case BASE_ITEM_SCYTHE:
        case BASE_ITEM_SICKLE:
        case BASE_ITEM_TWOBLADEDSWORD:
        case BASE_ITEM_WHIP:

        case BASE_ITEM_DART:
        case BASE_ITEM_HEAVYCROSSBOW:
        case BASE_ITEM_LIGHTCROSSBOW:
        case BASE_ITEM_LONGBOW:
        case BASE_ITEM_SHORTBOW:
        case BASE_ITEM_SHURIKEN:
        case BASE_ITEM_SLING:
        case BASE_ITEM_THROWINGAXE:

        case BASE_ITEM_MAGICSTAFF:

        case BASE_ITEM_DAGGERASSASSIN:
        case BASE_ITEM_DOUBLEPICK:
        case BASE_ITEM_KUKRI2:
        case BASE_ITEM_TRIDENT_1H:
        case BASE_ITEM_DOUBLESCIMITAR:
        case BASE_ITEM_FALCHION1:
        case BASE_ITEM_FALCHION2:
        case BASE_ITEM_GOAD:
        case BASE_ITEM_HEAVYMACE:
        case BASE_ITEM_HEAVYPICK:
        case BASE_ITEM_KATAR:
        case BASE_ITEM_LIGHTPICK:
        case BASE_ITEM_MAUL:
        case BASE_ITEM_MERCURIALGREATSWORD:
        case BASE_ITEM_MERCURIALLONGSWORD:
        case BASE_ITEM_NUNCHAKU:
        case BASE_ITEM_SAI:
        case BASE_ITEM_SAP:
        case BASE_ITEM_WINDFIREWHEEL:
        return TRUE;
    }
    return FALSE;
}


And then you need to add to your modules "OnPlayerEquipItem" script. The red highlighted section is all I added to the default "x2_mod_def_equ" script.

//::///////////////////////////////////////////////
//:: Example XP2 OnItemEquipped
//:: x2_mod_def_equ
//:: © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Put into: OnEquip Event
*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-16
//:://////////////////////////////////////////////
//:: Modified By: Deva Winblood
//:: Modified On: April 15th, 2008
//:: Added Support for Mounted Archery Feat penalties
//:://////////////////////////////////////////////

#include "x2_inc_switches"
#include "x2_inc_intweapon"
#include "x3_inc_horse"

void main()
{

    object oItem = GetPCItemLastEquipped();
    object oPC   = GetPCItemLastEquippedBy();

    if (GetLocalInt(oItem, "EQUIP_DELAY"))
    {
        ActionUnequipItem(oItem);
        SendMessageToPC(oPC, "You must wait 10 seconds before equipping this weapon.");
        return;
    }

    // -------------------------------------------------------------------------
    // Intelligent Weapon System
    // -------------------------------------------------------------------------
    if (IPGetIsIntelligentWeapon(oItem))
    {
        IWSetIntelligentWeaponEquipped(oPC,oItem);
        // prevent players from reequipping their weapon in
        if (IWGetIsInIntelligentWeaponConversation(oPC))
        {
                object oConv =   GetLocalObject(oPC,"X2_O_INTWEAPON_SPIRIT");
                IWEndIntelligentWeaponConversation(oConv, oPC);
        }
        else
        {
            //------------------------------------------------------------------
            // Trigger Drain Health Event
            //------------------------------------------------------------------
            if (GetLocalInt(oPC,"X2_L_ENSERRIC_ASKED_Q3")==1)
            {
                ExecuteScript ("x2_ens_dodrain",oPC);
            }
            else
            {
                IWPlayRandomEquipComment(oPC,oItem);
            }
        }
    }

    // -------------------------------------------------------------------------
    // Mounted benefits control
    // -------------------------------------------------------------------------
    if (GetWeaponRanged(oItem))
    {
        SetLocalInt(oPC,"bX3_M_ARCHERY",TRUE);
        HORSE_SupportAdjustMountedArcheryPenalty(oPC);
    }

    // -------------------------------------------------------------------------
    // Generic Item Script Execution Code
    // If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
    // it will execute a script that has the same name as the item's tag
    // inside this script you can manage scripts for all events by checking against
    // GetUserDefinedItemEventNumber(). See x2_it_example.nss
    // -------------------------------------------------------------------------
    if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
    {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_EQUIP);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
            return;
        }
    }
}


Hope that is what you needed. Good luck.
               
               

               
            

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
Disarm weapon script?
« Reply #8 on: November 27, 2010, 04:41:24 am »


               You are too kind GoG... i will test this soon to make sure it works. thanks so much
               
               

               
            

Legacy_CheeseshireCat

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Disarm weapon script?
« Reply #9 on: November 27, 2010, 06:48:10 am »


               Note that it would also do funny stuff if you just try to drop a weapon from inventory in the middle of combat (imagine having to pass one over to another player if meeting a monster with resistances they need to overcome?), or equip a different weapon with your inventory cluttered enough.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Disarm weapon script?
« Reply #10 on: November 28, 2010, 04:20:41 pm »


               Why not just use item equipped right-hand then left hand, and just unequip whatever they are holding in their hands. Much simpler.  Check the right hand first, which will unequip bows, 2hnaded weapons, .and if nothing is in the right hand go to the left hand.  Of course then you would have to check if it's a shield or not.  Personally I would just leave it right hand which encompasses everything except an off-hand weapon. 
               
               

               


                     Modifié par ffbj, 28 novembre 2010 - 04:25 .
                     
                  


            

Legacy_CheeseshireCat

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Disarm weapon script?
« Reply #11 on: November 28, 2010, 05:10:12 pm »


               Because they were trying to intercept standard disarm, not replace it.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Disarm weapon script?
« Reply #12 on: November 28, 2010, 05:22:19 pm »


               It's the same difference.  As far as the delay to use the weapon (item disarmed) again that could be handled by setting a local on the weapon so that you can't re-equip it for 6 seconds or whatever and then deleting that local off the weapon with a delay. The problem though would be describing the item once it is lost as having been in the right hand.  Now there you could run into trouble, though simply describing inventory slot item first, as below, should work. The idea of setting a local would still work with the lost item. Anyway something along these lines where you could have the onequipped also check for the set local disarmed and if it is present you can't equip that item, for a few seconds. Not a complete script:

#include "x2_inc_switches"
void main()
{
     object oDisarmed = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, OBJECT_SELF);
     object oItem = GetModuleItemLost();
     if (GetIsInCombat(OBJECT_SELF) && (oItem == oDisarmed))
      {
     SetLocalInt (oDisarmed, "Disarmed", 1);
     DelayCommand (6.0, DeleteLocalInt(oDisarmed, "Disarmed"));
     }

So not sure about the difference as far as in the disarm feature the item actually gets destroyed and then recreated in the PC's inventory.  So there the local int might be lost, which should not be a problem either since when you recreate it, the item, if the int would be lost, you just set it, the int, on the recreated item. 
               
               

               


                     Modifié par ffbj, 28 novembre 2010 - 06:06 .
                     
                  


            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Disarm weapon script?
« Reply #13 on: November 28, 2010, 10:06:19 pm »


               Wouldn't there need to be a check to insure that if they unacquire an item in combat that item actually goes to the ground?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Disarm weapon script?
« Reply #14 on: November 28, 2010, 10:40:30 pm »


               It's probably worth pointing out that we actually went out of our way to put the item in inventory instead of on the ground, because players would fail to notice the disarm until they'd moved on, often after the item was wiped by our area cleaning scripts. We use a custom event hook for disarm, thanks to one of acaos' engine hacks. Here's the code, in case it's of any help (you won't be able to simply use it, since it's a script that is called from a custom 'disarm' event, but it can still provide a lot of useful code):


#include "hg_inc"
#include "ac_itemprop_inc"
#include "ac_itemenh_inc"


int ABFeat (object oPC, int nFeat, int nBonus) {
    if (nFeat > 0 && GetHasFeat(nFeat, oPC))
        return nBonus;

    return 0;
}

int GetTotalAttackBonus (object oPC) {
    /* include +20 magical bonus always */
    int nAB = GetBaseAttackBonus(oPC) + 20;

    if (GetHitDice(oPC) == 40)
        nAB = (nAB - 20) + GetLocalInt(oPC, "LegendaryBAB");

    int nBaseItem = BASE_ITEM_GLOVES;
    object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC);
    if (GetIsObjectValid(oWeapon))
        nBaseItem = GetBaseItemType(oWeapon);

    nAB += ABFeat(oPC, FEAT_EPIC_PROWESS,                 1);
    nAB += ABFeat(oPC, GetWeaponFocusFeat(nBaseItem),     1);
    nAB += ABFeat(oPC, GetWeaponEpicFocusFeat(nBaseItem), 2);
    nAB += GetAttackBonusAdjustment(oPC, oWeapon, 0);

    int nWM = GetLevelByclass(class_TYPE_WEAPON_MASTER, oPC);

    if (nWM >= 5 && ABFeat(oPC, GetWeaponOfChoiceFeat(nBaseItem), 1) > 0) {
        nAB++;

        if (nWM >= 10)
            nAB += (nWM - 10) / 3;
    }

    return nAB;
}


void main () {
    object oPC = OBJECT_SELF;
    object oTarget = GetLocalObject(oPC, "EventTarget");

    DeleteLocalObject(oPC, "EventTarget");

    if (!GetIsObjectValid(oPC) || !GetIsObjectValid(oTarget) || !GetIsTarget(oTarget))
        return;

    if (GetDistanceBetween(oPC, oTarget) > RADIUS_SIZE_LARGE) {
        FloatingTextStringOnCreature("You must be closer to your target to disarm it!", oPC, FALSE);
        return;
    }

    if (GetItemIsRangedWeapon(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC))) {
        FloatingTextStringOnCreature("You cannot disarm with a ranged weapon!", oPC, FALSE);
        return;
    }

    object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);

    if (!GetIsObjectValid(oWeapon)) {
        FloatingTextStringOnCreature("You cannot disarm that target!", oPC, FALSE);
        return;
    }

    int bDisarmable;

    if (!GetIsPC(oTarget) && !GetDroppableFlag(oWeapon)) {
        SetLocalInt(oWeapon, "REPLACED", 1);
        SetDroppableFlag(oWeapon, TRUE);
        bDisarmable = GetIsCreatureDisarmable(oTarget);
        SetDroppableFlag(oWeapon, FALSE);
    } else
        bDisarmable = GetIsCreatureDisarmable(oTarget);

    if (!bDisarmable) {
        FloatingTextStringOnCreature("You cannot disarm that target!", oPC, FALSE);
        return;
    }


    float fDelay = (GetHasFeat(HGFEAT_SUPERIOR_DISARM, oPC) ? 3.0 : 6.0);
    if (!CheckSwiftAction(oPC, fDelay))
        return;


    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_BIGBYS_FORCEFUL_HAND));

    int nAB = GetTotalAttackBonus(oPC);
    int nDC = (GetHasFeat(FEAT_IMPROVED_DISARM, oPC) ? 15 : 25);
    int nDisc = GetSkillRank(SKILL_DISCIPLINE, oTarget);
    int nDisarmAdjustment = nDisc/10;
    nDC += nDisc + d20() - nDisarmAdjustment;

    int nCheck = GetSkillCheckResult(1000, oPC, nDC, TRUE, -1, oTarget, 0.0, 0, nAB);

    if (nCheck > 0) {
        effect eDisarm = EffectDisarm(0);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDisarm, oTarget);
    }
}

Let me know if you want to see any of the subfunctions.

Funky