Author Topic: Weapon onhits/ununique properties and events to use them with  (Read 482 times)

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0


               

This has probably been asked like a thousand times buuuuut, I figure I'll just ask my own version since looking at the previous threads hasn't helped me out very much.


 


Does anyone know how to get tag based scripts to work for weapons that have unique onhits? I'm wondering if I have to use the Onhit unique ability when I do this as I know some servers don't.. they just somehow use events like, "onhit" "oncrit" "onstun" "onusefeat"


I could be wrong though, and I probably am as I've never done it myself. I'd really like to code some of my own onhits for weapons to make them special though.



               
               

               
            

Legacy_KMdS!

  • Sr. Member
  • ****
  • Posts: 364
  • Karma: +0/-0
Weapon onhits/ununique properties and events to use them with
« Reply #1 on: April 06, 2016, 03:39:37 pm »


               

Hopefully, this example will help. It si a tag based script for an weapon with a tag of electrification. It makes use of the on hit event to fire the code.


 


/*::////////////////////////////////////////////////////////////////////////////
//:: Name: KMdS PNP Hard Core Rule Set 1.0
//:: System: KMdS Magic Systems
//:: SubSystem: KMdS AD&D Magic Items
//:: FileName: Electrification
//:: Copyright: (c) 2005 Michael Careaga
//::////////////////////////////////////////////////////////////////////////////
 
    This is a tag based script for reproducing the pnp rod of electrification.
    On any successful hit the rod will do 1d4+1 points of electrical damage and
    use 1 charge to do so.  The rod may be recharged by placing the rod on the
    ground and casting a lightning bolt spell at it.  The rod will recharge 1
    point per hit die of damage done by the lightning bolt.
 
    FILES INCLUDED IN THIS SUBSYSTEM PACKAGE
    Viper             Withering             Wizardry
    KMdS_Inc_Spells   Spell_Suggestion      Diplomacy
    Electrification   Spell_Entangle        Spell_Web
    Spell_HoldMons    Flailing              Spell_MageArmor
    LordlyMight       Ranike                Spell_Resurrect
    Smiting           Splendor              Equip_A_Rod
    ThunderLightning  Spell_DeafClang       x2_s3_DeafClng
    Spell_SoundBurst  Spell_ThndrLtng       Invisibility
 
//::////////////////////////////////////////////////////////////////////////////
//:: Created By: Kilr Mik d Spik
//:: Created On: 08/19/2005
//:://////////////////////////////////////////////////////////////////////////*/
 
//  ----------------------------------------------------------------------------
//  LIBRARIES
//  ----------------------------------------------------------------------------
 
#include "X0_I0_SPELLS"
#include "x2_inc_switches"
#include "nw_i0_generic"
 
//  ----------------------------------------------------------------------------
//  PROTOTYPES
//  ----------------------------------------------------------------------------
 
// Recharges an items charges.  Defauly increase is 1 charge.
void RechargeSpellCastingItem(object oItem, int nAdditionalCharges = 1);
 
//  ----------------------------------------------------------------------------
//  FUNCTIONS
//  ----------------------------------------------------------------------------
 
void RechargeSpellCastingItem(object oItem, int nAdditionalCharges = 1)
{
    SetItemCharges(oItem, GetItemCharges(oItem) + nAdditionalCharges);
}//  ----------------------------------------------------------------------------
//  MAIN
//  ----------------------------------------------------------------------------
 
void main()
{
    int nEvent = GetUserDefinedItemEventNumber(), nCharges;
    object oPC, oItem, oTarget;
    effect eVis, eBad;
 
//   SendMessageToPC(GetFirstPC(),IntToString(nEvent));
 
    // * This code runs when the item has the OnHitCastSpell: Unique power property
    // * and it hits a target(weapon) or is being hit (armor)
    // * Note that this event fires for non PC creatures as well.
    if (nEvent ==X2_ITEM_EVENT_ONHITCAST)
    {
        // The item casting triggering this spellscript
        oItem  =  GetSpellCastItem();
        object oSpellOrigin = OBJECT_SELF ;
        object oSpellTarget = GetSpellTargetObject();
        oPC = OBJECT_SELF;
 
        eVis = EffectVisualEffect(VFX_IMP_LIGHTNING_S);
        eBad = EffectDamage(d4()+1, DAMAGE_TYPE_ELECTRICAL);
        nCharges =  GetItemCharges(oItem);
 
        object oKMdS = GetLocalObject(GetModule(),"KMdS") ;
        if(oKMdS != OBJECT_INVALID && GetLocalInt(GetModule(),"DEBUG"))
            SendMessageToPC(oKMdS ,"The onhitcast event fired for the rod of electrification.  Item charges were "+IntToString(nCharges));
 
        if(nCharges)
        {
            SetItemCharges(oItem, nCharges -1);
            SignalEvent(oTarget, EventSpellCastAt(oPC, SPELL_ELECTRIC_JOLT));
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oSpellTarget);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eBad, oSpellTarget);
        }
    }
 
    // * This code runs when the Unique Power property of the item is used
    // * Note that this event fires PCs only
    else if (nEvent ==  X2_ITEM_EVENT_ACTIVATE)
    {
 
        oPC   = GetItemActivator();
        oItem = GetItemActivated();
        oTarget = GetItemActivatedTarget();
 
    }
 
    // * This code runs when the item is equipped
    // * Note that this event fires PCs only
    else if (nEvent ==X2_ITEM_EVENT_EQUIP)
    {
 
        oPC = GetPCItemLastEquippedBy();
        oItem = GetPCItemLastEquipped();
        object oPlayerSkin = GetItemInSlot(17, oPC);
 
        itemproperty ipProp1 = ItemPropertyBonusFeat(IP_CONST_FEAT_WEAPON_PROF_SIMPLE);
        IPSafeAddItemProperty(oPlayerSkin, ipProp1);
    }
 
    // * This code runs when the item is unequipped
    // * Note that this event fires PCs only
    else if (nEvent ==X2_ITEM_EVENT_UNEQUIP)
    {
 
        oPC    = GetPCItemLastUnequippedBy();
        oItem  = GetPCItemLastUnequipped();
        object oPlayerSkin = GetItemInSlot(17, oPC);
 
        IPRemoveMatchingItemProperties(oPlayerSkin, ITEM_PROPERTY_BONUS_FEAT, DURATION_TYPE_PERMANENT, IP_CONST_FEAT_WEAPON_PROF_SIMPLE);
    }
 
    // * This code runs when the item is acquired
    // * Note that this event fires PCs only
    else if (nEvent == X2_ITEM_EVENT_ACQUIRE)
    {
        oPC = GetModuleItemAcquiredBy();
        oItem  = GetModuleItemAcquired();
 
    }
 
 
    // * This code runs when the item is unaquired
    // * Note that this event fires PCs only
    else if (nEvent == X2_ITEM_EVENT_UNACQUIRE)
    {
 
        oPC = GetModuleItemLostBy();
        oItem  = GetModuleItemLost();
        object oPlayerSkin = GetItemInSlot(17, oPC);
 
        IPRemoveMatchingItemProperties(oPlayerSkin, ITEM_PROPERTY_BONUS_FEAT, DURATION_TYPE_PERMANENT, IP_CONST_FEAT_WEAPON_PROF_SIMPLE);
    }
 
    //* This code runs when a PC or DM casts a spell from one of the
    //* standard spellbooks on the item
    else if (nEvent == X2_ITEM_EVENT_SPELLCAST_AT)
    {
 
        oPC = GetModuleItemLostBy();
        oItem  = GetModuleItemLost();
        nCharges =  GetItemCharges(oItem);
        int nMaxCharges = 50 - nCharges;
        if(GetSpellId() == 101 && GetItemPossessor(oItem) == OBJECT_INVALID)
        {
            int nCasterLevel = GetCasterLevel(oPC);
            if(nCasterLevel >10) nCasterLevel = 10;
 
            nCharges = GetCasterLevel(oPC);
            if(nCharges > nMaxCharges) nCharges = nMaxCharges;
 
            RechargeSpellCastingItem(oItem, nCharges);
        }
    }
}

               
               

               
            

Legacy_Imperator

  • Full Member
  • ***
  • Posts: 128
  • Karma: +0/-0
Weapon onhits/ununique properties and events to use them with
« Reply #2 on: April 06, 2016, 04:06:13 pm »


               

sorry, nevermind I finally figured it out. Thanks for the reply though.