MMD_PRC8/_module/nss/inc_util.nss
Jaysyn904 8c530509fe Increased HP of Practice Dummy
Increased HP of Practice Dummy.  Added instanced player room with persistent storage in Inn.  Full compile.  Updated release archive.
2024-09-21 14:31:54 -04:00

130 lines
4.9 KiB
Plaintext

/*
Utility Functions
Created By: Daz
*/
#include "nw_inc_gff"
#include "nw_inc_nui"
string Util_GetIconResref(object oItem, json jItem, int nBaseItem);
string Util_GetIconResref(object oItem, json jItem, int nBaseItem)
{
if (nBaseItem == BASE_ITEM_CLOAK) // Cloaks use PLTs so their default icon doesn't really work
return "iit_cloak";
else if (nBaseItem == BASE_ITEM_SPELLSCROLL || nBaseItem == BASE_ITEM_ENCHANTED_SCROLL)
{// Scrolls get their icon from the cast spell property
if (GetItemHasItemProperty(oItem, ITEM_PROPERTY_CAST_SPELL))
{
itemproperty ip = GetFirstItemProperty(oItem);
while (GetIsItemPropertyValid(ip))
{
if (GetItemPropertyType(ip) == ITEM_PROPERTY_CAST_SPELL)
return Get2DAString("iprp_spells", "Icon", GetItemPropertySubType(ip));
ip = GetNextItemProperty(oItem);
}
}
}
else if (Get2DAString("baseitems", "ModelType", nBaseItem) == "0")
{// Create the icon resref for simple modeltype items
json jSimpleModel = GffGetByte(jItem, "ModelPart1");
if (JsonGetType(jSimpleModel) == JSON_TYPE_INTEGER)
{
string sSimpleModelId = IntToString(JsonGetInt(jSimpleModel));
while (GetStringLength(sSimpleModelId) < 3)// Padding...
{
sSimpleModelId = "0" + sSimpleModelId;
}
string sDefaultIcon = Get2DAString("baseitems", "DefaultIcon", nBaseItem);
switch (nBaseItem)
{
case BASE_ITEM_MISCSMALL:
case BASE_ITEM_CRAFTMATERIALSML:
sDefaultIcon = "iit_smlmisc_" + sSimpleModelId;
break;
case BASE_ITEM_MISCMEDIUM:
case BASE_ITEM_CRAFTMATERIALMED:
case 112:/* Crafting Base Material */
sDefaultIcon = "iit_midmisc_" + sSimpleModelId;
break;
case BASE_ITEM_MISCLARGE:
sDefaultIcon = "iit_talmisc_" + sSimpleModelId;
break;
case BASE_ITEM_MISCTHIN:
sDefaultIcon = "iit_thnmisc_" + sSimpleModelId;
break;
}
int nLength = GetStringLength(sDefaultIcon);
if (GetSubString(sDefaultIcon, nLength - 4, 1) == "_")// Some items have a default icon of xx_yyy_001, we strip the last 4 symbols if that is the case
sDefaultIcon = GetStringLeft(sDefaultIcon, nLength - 4);
string sIcon = sDefaultIcon + "_" + sSimpleModelId;
if (ResManGetAliasFor(sIcon, RESTYPE_TGA) != "")// Check if the icon actually exists, if not, we'll fall through and return the default icon
return sIcon;
}
}
// For everything else use the item's default icon
return Get2DAString("baseitems", "DefaultIcon", nBaseItem);
}
json Util_GetModelPart(string sDefaultIcon, string sType, json jPart)
{
if (JsonGetType(jPart) == JSON_TYPE_INTEGER)
{
string sModelPart = IntToString(JsonGetInt(jPart));
while (GetStringLength(sModelPart) < 3)
{
sModelPart = "0" + sModelPart;
}
string sIcon = sDefaultIcon + sType + sModelPart;
if (ResManGetAliasFor(sIcon, RESTYPE_TGA) != "")
return JsonString(sIcon);
}
return JsonString("");
}
json Util_GetComplexIconData(json jItem, int nBaseItem);
json Util_GetComplexIconData(json jItem, int nBaseItem)
{
if (Get2DAString("baseitems", "ModelType", nBaseItem) == "2")
{
string sDefaultIcon = Get2DAString("baseitems", "DefaultIcon", nBaseItem);
json jComplexIcon = JsonObject();
jComplexIcon = JsonObjectSet(jComplexIcon, "top", Util_GetModelPart(sDefaultIcon, "_t_", GffGetByte(jItem, "ModelPart3")));
jComplexIcon = JsonObjectSet(jComplexIcon, "middle", Util_GetModelPart(sDefaultIcon, "_m_", GffGetByte(jItem, "ModelPart2")));
jComplexIcon = JsonObjectSet(jComplexIcon, "bottom", Util_GetModelPart(sDefaultIcon, "_b_", GffGetByte(jItem, "ModelPart1")));
return jComplexIcon;
}
return JsonNull();
}
string Util_Get2DAStringByStrRef(string s2DA, string sColumn, int nRow);
string Util_Get2DAStringByStrRef(string s2DA, string sColumn, int nRow)
{
return GetStringByStrRef(StringToInt(Get2DAString(s2DA, sColumn, nRow)));
}
string Util_GetItemName(object oItem, int bIdentified);
string Util_GetItemName(object oItem, int bIdentified)
{
return bIdentified ? GetName(oItem) : Util_Get2DAStringByStrRef("baseitems", "Name", GetBaseItemType(oItem)) + " (Unidentified)";
}
void Util_SendDebugMessage(string sMessage);
void Util_SendDebugMessage(string sMessage)
{
object oPlayer = GetFirstPC();
while (oPlayer != OBJECT_INVALID)
{
SendMessageToPC(oPlayer, sMessage);
oPlayer = GetNextPC();
}
}