Author Sticky: Post Working Scripts Here
mindtakerr Posted: Saturday, 20 July 04:06AM
Here is an update to my include file that is on page 27. Mods, feel free to add the info from the new functions to what's already there.

New Functions Added:

GetAreaCreatureCount
Usage: GetAreaCreatureCount(object oArea); Returns the number of creatures in the area, including the PCs.

GetCreatureHPPercentage
Usage: GetCreatureHPPercentage(object oTarget); Returns a float with the percentage of hit points oTarget out of 100.

NWScript:
//::///////////////////////////////////////////////

//:: Name: Mindtakerr's Include File

//:: FileName: mindtakerr_inc

//:: Copyright (c) 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

//  GetNearestPC returns the nearest PC to the caller or to object oNearest if given.

//  Created by: mindtakerr  Date: 07/16/02

object GetNearestPC(object oNearest = OBJECT_SELF)

{

    return GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oNearest);

}

//  GetNearestNPC returns the nearest NPC to the caller or to object oNearest if given.

//  Created by: mindtakerr  Date: 07/16/02

object GetNearestNPC(object oNearest = OBJECT_SELF)

{

    return GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC, oNearest);

}

//  GiveGoldToParty gives nGP gold pieces to each member of the current party.

//  Created by: mindtakerr  Date: 07/16/02

void GiveGoldToParty(int nGP)

{

    object oPC = GetNearestPC();

    object oParty = GetFirstFactionMember(oPC);

    while(GetIsObjectValid(oParty)) {

        GiveGoldToCreature(oParty, nGP);

        oParty = GetNextFactionMember(oPC);

    }

}

//  GiveXPToParty gives nXP experience points to each member of the current party.

//  Created by: mindtakerr  Date: 07/16/02

void GiveXPToParty(int nXP)

{

    object oPC = GetNearestPC();

    object oParty = GetFirstFactionMember(oPC);

    while(GetIsObjectValid(oParty)) {

        GiveXPToCreature(oParty, nXP);

        oParty = GetNextFactionMember(oPC);

    }

}

/*

    TransportPartyToDestination will transport every member of the party

    to the waypoint with the given tag, sDestinationWaypointTag, after a delay

    of fWait seconds.

*/

//  Created by: mindtakerr  Date: 07/16/02

void TransportPartyToDestination(string sDestinationWaypointTag, float fWait)

{

    object oDestination = GetWaypointByTag(sDestinationWaypointTag);

    object oPC = GetNearestPC();

    object oParty = GetFirstFactionMember(oPC);

    while(GetIsObjectValid(oParty)) {

        AssignCommand(oParty, ActionWait(fWait));

        AssignCommand(oParty, ActionJumpToObject(oDestination));

        oParty = GetNextFactionMember(oPC);

    }

}

/*

    GetIsArmed will return TRUE if the passed in oCreature is armed with

    a weapon.  It will return FALSE if the creature is not armed.

*/

//  Created by: mindtakerr  Date: 07/17/02

int GetIsArmed(object oCreature)

{

    return (GetIsObjectValid(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oCreature)));

}



/*

    GetTotalLevel returns the sum of the levels of all three classes of

    the passed in oCreature.

*/

//  Created by: mindtakerr  Date: 07/17/02

int GetTotalLevel(object oCreature)

{

    int nTotal = 0;

    int nCounter;

    for (nCounter = 1; nCounter <= 3; nCounter++)

        nTotal += GetLevelByPosition(nCounter, oCreature);

    return nTotal;

}



/*

    GetAreaCreatureCount returns the number of creatures in area oArea,

    including the PCs

*/

//  Created by: mindtakerr  Date: 07/19/02

int GetAreaCreatureCount(object oArea)

{

    int nCreatureCount = 0;

    object oCreature = GetNearestObject(OBJECT_TYPE_CREATURE);

    while(GetIsObjectValid(oCreature) && GetArea(oCreature) == oArea) {

        nCreatureCount++;

        oCreature = GetNearestObject(OBJECT_TYPE_CREATURE, OBJECT_SELF, nCreatureCount);

    }

    return nCreatureCount - 1;

}



/*

    GetCreatureHPPercentage returns the percentage of hit points remaining on the

    creature out of a possible 100%

*/

//  Created by: mindtakerr Date: 07/19/02

float GetCreatureHPPercentage(object oCreature = OBJECT_SELF)

{

    float fHP = IntToFloat(GetCurrentHitPoints(oCreature));

    float fMaxHP = IntToFloat(GetMaxHitPoints(oCreature));

    float fHPPercentage = (fHP / fMaxHP) * 100.0;

    return fHPPercentage;

}



_________________
Michael Ham
Check out The Six Realms of Bel'Abourd; a fantasy RPG work in progress.
www.bakedhamgames.com