Author Sticky: Post Working Scripts Here
Knox Promethean Posted: Wednesday, 10 July 03:17AM
1. SummonLastHostileActor

2. Summons the last hostile actor to the mob so that the mob can attack them with melee. I know, I know, I play too much EQ, but this was a fun first script to write. Want to have some fun, and add a little shocker for those rangers and wizards that like to attack from a distance? Call this baby in your OnDamaged event script. BE SURE to leave your script that makes the mob determine what to do, just call this to let the mob get someone in close to beat on.

3. Just to make it fair, the attacker does get a WillSave of type Chaos so that they hve a chance at possibly not getting summoned. So call the function with the DC for the WillSave...the script explains it more in the comments.

4. The script itself
NWScript:
#include "NW_I0_GENERIC"

// **********************************************

// * SummonLastHostileActor(int nDC)

// *  nDC is the Difficulty Check of the WillSave, of type CHAOS, 

// *	that the HostileActor will have to maybe avoid the summon

// *

// *  nDC must be greater than or equal to 0

// *  Passing a 0 would mean the mob would never summon

// *  Passing a 100 would mean the mob would almost surely summon

// *  d20(2) is a fun one to pass in as nDC

// *

void SummonLastHostileActor(int nDC)

{

    object  oMe             = OBJECT_SELF;

    object  oHostileMob;

    string  sSummonString;

    effect  eVis;

    // Make sure this is a valid object

    if(GetIsObjectValid(oMe))

    {

        // Get who the last hostile actor was

        oHostileMob = GetLastHostileActor(oMe);

        // Make sure it is valid

        if(GetIsObjectValid(oHostileMob))

        {

            // If they are out of melee range, then summon them to me

            if(GetDistanceToObject(oHostileMob) > 5.0)

            {

                // Do a will save of type chaos against the DC passed in

                // If you want to have some fun, call this function with

                // nDC = a dice roll like d20(2) or something

                // So yes it is possible that the attacker will not get summoned

                // If nDC = 0 then you will never summon, so why have this?

                // If nDC is extraordinarily high, like 100, then he will most

                // likely always summon

                if(nDC < 0) nDC = 0;

                if(WillSave(oHostileMob, nDC, SAVING_THROW_TYPE_CHAOS, oMe) == 0)

                {

                    // Say something

                    sSummonString = "Get over here " + GetName(oHostileMob);

                    SpeakString(sSummonString);

                    // Create a puff of smoke where the attacker was

                    eVis = EffectVisualEffect(VFX_FNF_SMOKE_PUFF);

                    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis,

                        GetLocation(oHostileMob));

                    // Make the attacker jump to him

                    AssignCommand(oHostileMob, JumpToObject(oMe));

                }

            }

        }

    }

}

// ***********************************************

// * This is the example main that comes in nw_c2_default6

// * to show how SummonLastHostileActor may be called and used.

void main()

{

    if(!GetFleeToExit())

    {

        if(!GetSpawnInCondition(NW_FLAG_SET_WARNINGS))

        {

            SummonLastHostileActor(d20(2));

            if(!GetIsObjectValid(GetAttemptedAttackTarget()) && !GetIsObjectValid(GetAttemptedSpellTarget()))

            {

                if(GetBehaviorState(NW_FLAG_BEHAVIOR_SPECIAL))

                {

                    DetermineSpecialBehavior(GetLastDamager());

                }

                else if(GetIsObjectValid(GetLastDamager()))

                {

                    DetermineCombatRound();

                    if(!GetIsFighting(OBJECT_SELF))

                    {

                        object oTarget = GetLastDamager();

                        if(!GetObjectSeen(oTarget) && GetArea(OBJECT_SELF) == GetArea(oTarget))

                        {

                            ActionMoveToLocation(GetLocation(oTarget), TRUE);

                            ActionDoCommand(DetermineCombatRound());

                        }

                    }

                }

            }

            else if (!GetIsObjectValid(GetAttemptedSpellTarget()))

            {

                object oTarget = GetAttackTarget();

                if(!GetIsObjectValid(oTarget))

                {

                    oTarget = GetAttemptedAttackTarget();

                }

                object oAttacker = GetLastHostileActor();

                if (GetIsObjectValid(oAttacker) && oTarget != oAttacker && GetIsEnemy(oAttacker) &&

                   (GetTotalDamageDealt() > (GetMaxHitPoints(OBJECT_SELF) / 4) ||

                    (GetHitDice(oAttacker) - 2) > GetHitDice(oTarget) ) )

                {

                    DetermineCombatRound(oAttacker);

                }

            }

        }

    }

    if(GetSpawnInCondition(NW_FLAG_DAMAGED_EVENT))

    {

        SignalEvent(OBJECT_SELF, EventUserDefined(1006));

    }

}