Author Topic: Magic Weapon on a Ranged Weapon  (Read 311 times)

Legacy_Evelath

  • Full Member
  • ***
  • Posts: 108
  • Karma: +0/-0
Magic Weapon on a Ranged Weapon
« on: June 25, 2013, 05:22:39 am »


               How would one go about doing this?

I attempted modifying the individual script  but haven't had any luck. Any insight would be appreciated.
               
               

               


                     Modifié par Evelath, 25 juin 2013 - 04:22 .
                     
                  


            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Magic Weapon on a Ranged Weapon
« Reply #1 on: June 25, 2013, 05:39:54 am »


               x2_s0_magcweap or x2_s0_grmagweap are the scripts to edit.

You need a check if the weapon is a ranged weapon.  If it is, then add an attack bonus instead of a weapon enhancement... unless that's not what you want to do.

object oMyWeapon   =  IPGetTargetedOrEquippedMeleeWeapon();
if( GetWeaponRanged(oMyWeapon) )
{
 iEnh = 1;
IPSafeAddItemProperty(oMyWeapon,ItemPropertyAttackBonus(iEnh),HoursToSeconds(nDuration),
X2_IP_ADDPROP_POLICY_IGNORE_EXISTING);
}


The above is a heavily stripped down section out of my version of magic weapon.

*Edit*
oops, IPGetTargetedOrEquippedMeleeWeapon() would return OBJECT_INVALID and wouldn't work if you were holding a ranged weapon.  Sorry, I'll come back and adjust this later on my day off.
               
               

               


                     Modifié par Terrorble, 25 juin 2013 - 04:50 .
                     
                  


            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Magic Weapon on a Ranged Weapon
« Reply #2 on: June 26, 2013, 07:09:38 pm »


               Maybe something like


//::///////////////////////////////////////////////
//:: Greater Magic Weapon
//:: X2_S0_GrMagWeap
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
  Grants a +1 enhancement bonus per 3 caster levels
  (min +1, maximum of +5).
  lasts 1 hour per level
*/
//:://////////////////////////////////////////////
//:: Created By: Andrew Nobbs
//:: Created On: Nov 28, 2002
//:://////////////////////////////////////////////
//:: Updated by Andrew Nobbs May 08, 2003
//:: 2003-07-07: Stacking Spell Pass, Georg Zoeller
//:: 2003-07-17: Complete Rewrite to make use of Item Property System

#include "nw_i0_spells"
#include "x2_i0_spells"
#include "x2_inc_spellhook"

// MEB 2013/06/26: Variant of x2_inc_itemprop's IPGetTargetedOrEquippedMeleeWeapon()
// that returns ranged weapons as well, intended for use in
// scripts that are interested in any equipped or targeted weapon.
// Compatible with changes to IPGetIsMeleeWeapon() that accommodate CEP
// melee weapons. As per BW version, when a creature is targeted, returns
// offhand weapon, if no mainhand weapon is equipped, and creature weapons
// if neither mainhand nor offhand are equipped.
object IPGetTargetedOrEquippedWeapon()
{
  object oTarget = GetSpellTargetObject();
  if(GetIsObjectValid(oTarget) && GetObjectType(oTarget) == OBJECT_TYPE_ITEM)
  {
    if (IPGetIsMeleeWeapon(oTarget) || IPGetIsRangedWeapon(oTarget))
    {
        return oTarget;
    }
    else
    {
        return OBJECT_INVALID;
    }

  }

  object oWeapon1 = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oTarget);
  if (GetIsObjectValid(oWeapon1) && (IPGetIsMeleeWeapon(oTarget) || IPGetIsRangedWeapon(oTarget)))
  {
    return oWeapon1;
  }

  oWeapon1 = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oTarget);
  if (GetIsObjectValid(oWeapon1) && (IPGetIsMeleeWeapon(oTarget) || IPGetIsRangedWeapon(oTarget)))
  {
    return oWeapon1;
  }

  oWeapon1 = GetItemInSlot(INVENTORY_SLOT_CWEAPON_R, oTarget);
  if (GetIsObjectValid(oWeapon1))
  {
    return oWeapon1;
  }

  oWeapon1 = GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oTarget);
  if (GetIsObjectValid(oWeapon1))
  {
    return oWeapon1;
  }

  return OBJECT_INVALID;
}

void main()
    {
    /*Spellcast Hook Code
      Added 2003-07-07 by Georg Zoeller
      If you want to make changes to all spells,
      check x2_inc_spellhook.nss to find out more    */
    if (!X2PreSpellCastCode())
        {   // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
        }
    // End of Spell Cast Hook

    //Declare major variables
    int nSpellID = GetSpellId();
    effect eVis = EffectVisualEffect(VFX_IMP_SUPER_HEROISM);
    effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
    int nDuration = GetCasterLevel(OBJECT_SELF);
    int nBonus;
    int nMetaMagic = GetMetaMagicFeat();

    object oMyWeapon = IPGetTargetedOrEquippedWeapon();
    if (!GetIsObjectValid(oMyWeapon) )
        {
           FloatingTextStringOnCreature("* Spell Failed - Target must be a weapon or creature with an equipped weapon *", OBJECT_SELF);
           return;
        }

    if ( nSpellID == SPELL_GREATER_MAGIC_WEAPON )
        {
        nBonus = nDuration / 3;
        if(nBonus > 5)  // Cap nBonus at +5
            {
            nBonus = 5;
            }
        }
    else if ( nSpellID == SPELL_MAGIC_WEAPON )
        {
        nBonus = 1;
        }

    if (nBonus<1)   // sanity check
        {
        nBonus = 1;
        }


    if (nMetaMagic == METAMAGIC_EXTEND)
        {
        nDuration = nDuration * 2; //Duration is +100%
        }

    if(GetWeaponRanged(oMyWeapon) )
        {
        SignalEvent(GetItemPossessor(oMyWeapon), EventSpellCastAt(OBJECT_SELF, GetSpellId(), FALSE));

        if (nDuration>0)
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, GetItemPossessor(oMyWeapon));
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDur, GetItemPossessor(oMyWeapon), HoursToSeconds(nDuration));
            IPSafeAddItemProperty(oMyWeapon,ItemPropertyAttackBonus(nBonus), IntToFloat(nDuration), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
            }
        return;
        }
    else
        {
        SignalEvent(GetItemPossessor(oMyWeapon), EventSpellCastAt(OBJECT_SELF, GetSpellId(), FALSE));

        if (nDuration>0)
            {
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, GetItemPossessor(oMyWeapon));
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDur, GetItemPossessor(oMyWeapon), HoursToSeconds(nDuration));
            IPSafeAddItemProperty(oMyWeapon,ItemPropertyEnhancementBonus(nBonus), IntToFloat(nDuration), X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE);
            }
        return;
        }
    }