Author Topic: Custom weapon on hit  (Read 254 times)

Legacy_Sploded

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Custom weapon on hit
« on: October 06, 2014, 03:41:01 am »


               

Hello,


 


I've just started trying to mod NWN, and one of the things I'm trying to do is give a weapon a custom "on hit death" effect with a fortitude based DC. I've been looking through a lot of tutorials, but for someone who isn't terribly familiar with scripting, it seems like there really isn't a way to get this effect to occur. Any help/advice?


 


Thanks.



               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Custom weapon on hit
« Reply #1 on: October 08, 2014, 06:25:05 pm »


               You Must Give the Item the Tagname of the item to "tbsi_dev_onhit" (without the "") & change the nDA_DC to the DC you want to give for the item...


///////////////////////////  Copy everything below this line /////////////////////////////

//

// tbsi_dev_onhit

//

int nDA_DC = 20; // Enter the DC for the Death Attack Here...

//

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

// Created By Genisys / Guile

// Created On 10/08/2014

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

//############################################

// Script Originally Designed By: The Krit

//############################################

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


// This is intended to be a starting point for writing an item's tag-based script.

// Copy this to a script whose name is the tag of the item in question.

// Edit the event handlers (scroll down to find them) as desired.

// -----------------------------------------------------------------------------

//Required Include (DO NOT TOUCH!)

#include "x2_inc_switches"

//------------------------------------------------------------------------------



// -----------------------------------------------------------------------------

// Event handlers

// -----------------------------------------------------------------------------

// This second part is where you add your desired functionality. Each event

// has its own function with relavant information passed as parameters.

// -----------------------------------------------------------------------------



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

// A Custom Prototype To Create (Spawn In) New Object

// NOTE: This is usable with the function  DelayCommand(...):


void CreatObjectVoid(string sResRef, location lLocation);

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



// -----------------------------------------------------------------------------

// oItem was acquired (by a PC or an NPC).

// Run by the module.

void OnAcquire(object oItem, object oAcquiredBy, object oTakenFrom, int nStackSize)

{

    // Enter code to execute when this event happens

}



// -----------------------------------------------------------------------------

// oItem was activated ("activate item" or "unique power").

// Run by the module.

void OnActivate(object oItem, object oActTarget, location lActTarget, object oActivator)

{


 // Enter code to execute when this event happens


}



// -----------------------------------------------------------------------------

// oItem was equipped by a PC.

// Run by the module.

void OnEquip(object oItem, object oEquippedBy)

{

    // Enter code to execute when this event happens

}



// -----------------------------------------------------------------------------

// oItem is a weapon that just hit a target, or it is the armor of someone who

// was just hit by someone else's weapon.

// Run by the caster.

void OnHit(object oItem, object oHitTarget, object oCaster)

{

  if(!FortitudeSave(oHitTarget, nDA_DC, SAVING_THROW_TYPE_NONE))

  {

   ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDeath(TRUE), oHitTarget);

  }

}



// -----------------------------------------------------------------------------

// Someone cast a spell at oItem.


// Run by the caster.

int OnSpellCast(object oItem, int nSpell, object oCaster)

{

   // Enter code to execute when this event happens


   return FALSE; //Necessary return (Do this !)

}



// -----------------------------------------------------------------------------

// oItem was unacquired/lost (by a PC or NPC).

// Run by the module.

void OnUnacquire(object oItem, object oLostBy)

{

    // Enter code to execute when this event happens

}



// -----------------------------------------------------------------------------

// oItem was unequipped by a PC.

// Run by the module.

void OnUnequip(object oItem, object oUnequippedBy)

{

    // Enter code to execute when this event happens

}



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

// ##### WARNINING:: DON'T TOUCH ANYTHING BELOW THIS LINE!!! #### ///////////

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


// The main function.

void main()

{

    int nEvent = GetUserDefinedItemEventNumber();


    // Spells might continue to their spell scripts. All other events are

    // completely handled by this script.

    if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT )

        SetExecutedScriptReturnValue();


    // Determine which event triggered this script's execution.

    switch ( nEvent )

    {

        // Item was acquired.

        case X2_ITEM_EVENT_ACQUIRE:

                OnAcquire(GetModuleItemAcquired(), GetModuleItemAcquiredBy(),

                          GetModuleItemAcquiredFrom(), GetModuleItemAcquiredStackSize());

                break;


        // Item was activated ("activate item" or "unique power").

        case X2_ITEM_EVENT_ACTIVATE:

                OnActivate(GetItemActivated(), GetItemActivatedTarget(),

                           GetItemActivatedTargetLocation(), GetItemActivator());

                break;


        // Item was equipped by a PC.

        case X2_ITEM_EVENT_EQUIP:

                OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy());

                break;


        // Item is a weapon that just hit a target, or it is the armor of someone

        // who was just hit.

        case X2_ITEM_EVENT_ONHITCAST:

                OnHit(GetSpellCastItem(), GetSpellTargetObject(), OBJECT_SELF);

                break;


        // A PC (or certain NPCs) cast a spell at the item.

        case X2_ITEM_EVENT_SPELLCAST_AT:

                if ( OnSpellCast(GetSpellTargetObject(), GetSpellId(), OBJECT_SELF) )

                    SetExecutedScriptReturnValue();

                break;


        // Item was unacquired.

        case X2_ITEM_EVENT_UNACQUIRE:

                OnUnacquire(GetModuleItemLost(), GetModuleItemLostBy());

                break;


        // Item was unequipped by a PC.

        case X2_ITEM_EVENT_UNEQUIP:

                OnUnequip(GetPCItemLastUnequipped(), GetPCItemLastUnequippedBy());

                break;

    }

}



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

//Define Custom Prototype


void CreatObjectVoid(string sResRef, location lLocation)

{

 object oNew = CreateObject(OBJECT_TYPE_CREATURE, sResRef, lLocation, FALSE);

}