Initial commit
Adding all of the current content for Anphillia Unlimited.
This commit is contained in:
110
_module/nss/creature_inc.nss
Normal file
110
_module/nss/creature_inc.nss
Normal file
@@ -0,0 +1,110 @@
|
||||
/************************************************************************
|
||||
* script name : creature_inc
|
||||
* created by : eyesolated
|
||||
* date : 2018/8/28
|
||||
*
|
||||
* description : central include file for creature related functions
|
||||
*
|
||||
* changes : 2018/8/28 - eyesolated - Initial creation
|
||||
* 2019/3/6 - eyesolated - Changed how creature_GetOriginalName works
|
||||
************************************************************************/
|
||||
|
||||
#include "creature_cfg"
|
||||
#include "color_inc"
|
||||
|
||||
void creature_SetOriginalName(object oCreature, string sName);
|
||||
|
||||
string creature_GetOriginalName(object oCreature);
|
||||
|
||||
void creature_SetName(object oCreature, int nDisplay = CREATURE_NAME_DISPLAY_ORIGINAL_HEALTH);
|
||||
|
||||
void creature_SetOriginalName(object oCreature, string sName)
|
||||
{
|
||||
SetLocalString(oCreature, CREATURE_VAR_NAME_BASE, sName);
|
||||
}
|
||||
|
||||
// Retrieves the original Name of oCreature
|
||||
string creature_GetOriginalName(object oCreature)
|
||||
{
|
||||
// Had to change the method of retrieving a creature's original name because of custom renaming in
|
||||
// the onspawn process. The desired (possibly custom) base name is stored on first call of this
|
||||
// method and then retrieved subsequently.
|
||||
// return GetName(oCreature, TRUE);
|
||||
|
||||
string sBaseName = GetLocalString(oCreature, CREATURE_VAR_NAME_BASE);
|
||||
if (sBaseName == "")
|
||||
{
|
||||
sBaseName = GetName(oCreature);
|
||||
SetLocalString(oCreature, CREATURE_VAR_NAME_BASE, sBaseName);
|
||||
}
|
||||
|
||||
return sBaseName;
|
||||
}
|
||||
|
||||
void creature_SetName(object oCreature, int nDisplay = CREATURE_NAME_DISPLAY_ORIGINAL_HEALTH)
|
||||
{
|
||||
string sName = "";
|
||||
|
||||
// Original Name
|
||||
if ((nDisplay & CREATURE_NAME_DISPLAY_ORIGINAL) != 0)
|
||||
{
|
||||
sName += creature_GetOriginalName(oCreature);
|
||||
}
|
||||
|
||||
// Health Percentage
|
||||
if ((nDisplay & CREATURE_NAME_DISPLAY_HEALTH) != 0)
|
||||
{
|
||||
int nMaxHitPoints = GetMaxHitPoints(oCreature);
|
||||
int nCurrentHitPoints = GetCurrentHitPoints(oCreature);
|
||||
|
||||
float fPercentage = IntToFloat(nCurrentHitPoints) / IntToFloat(nMaxHitPoints) * 100;
|
||||
int nPercentage = FloatToInt(fPercentage);
|
||||
if (IntToFloat(nPercentage) < fPercentage)
|
||||
nPercentage++;
|
||||
|
||||
// If the calculated Percentage is the same as before, return
|
||||
string sColor;
|
||||
if (nPercentage != GetLocalInt(oCreature, CREATURE_VAR_LAST_HEALTH_PERCENTAGE_SET))
|
||||
{
|
||||
if (nCurrentHitPoints > 0 &&
|
||||
nPercentage > 0)
|
||||
{
|
||||
int nGreen;
|
||||
int nRed;
|
||||
|
||||
if (nPercentage >= 50)
|
||||
{
|
||||
nGreen = 7;
|
||||
nRed = FloatToInt(IntToFloat(100 - nPercentage) / 7);
|
||||
}
|
||||
else
|
||||
{
|
||||
nRed = 7;
|
||||
nGreen = FloatToInt(IntToFloat(nPercentage) / 7);
|
||||
}
|
||||
string sColor = IntToString(nRed) + IntToString(nGreen) + "0";
|
||||
|
||||
if (sName != "")
|
||||
sName += " - ";
|
||||
|
||||
sColor = color_ConvertString(IntToString(nPercentage) + "%", sColor);
|
||||
sName += sColor;
|
||||
SetLocalInt(oCreature, CREATURE_VAR_LAST_HEALTH_PERCENTAGE_SET, nPercentage);
|
||||
SetLocalString(oCreature, CREATURE_VAR_LAST_HEALTH_PERCENTAGE_TEXT, sColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sColor = GetLocalString(oCreature, CREATURE_VAR_LAST_HEALTH_PERCENTAGE_TEXT);
|
||||
if (sColor != "")
|
||||
{
|
||||
if (sName != "")
|
||||
sName += " - ";
|
||||
|
||||
sName += sColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetName(oCreature, sName);
|
||||
}
|
||||
Reference in New Issue
Block a user