UW2_PRC8/_module/nss/sfcs_functs.nss
Jaysyn904 5197ad9a4d Initial upload
Initial upload
2023-09-25 20:24:01 -04:00

301 lines
11 KiB
Plaintext
Raw Permalink Blame History

//::///////////////////////////////////////////////
//:: Scarface's Crafting System V1.0
//:: sfcs_functs
//::
//:://////////////////////////////////////////////
/*
All of the Main functions - DO NOT TOUCH!!!
*/
//////////////////////////////////////////////////
#include "sfcs__consts"
//:: Declair Functions
// Returns the required level for the item being crafted (From 2da file)
int GetItemLevel();
// Returns the string value of the items required level
string GetItemLevelString();
// Returns the string value of all valid properties on the item
string GetPropertiesString();
// Resets all local variables and custom tokens for the crafting system
void ResetVars();
// Sets the string text for the conversation menu
void SetMenuText();
// Gets a valid item property local var slot
// Returns "INVALID_SLOT" if there are no valid slots
string GetItemPropertySlot(string sPropName);
// Returns the item cost string
string GetItemCostString();
// Change an int into a constant for the damage bonus
int DamageBonus(int iProp);
// Get the cost value of oItem based on the constant set
int GetItemCost(object oItem);
////////////////////////////////////////////////////////////////////////////////
//:: Functions
int GetItemLevel()
{
// Get the item being crafted
object oItem = GetLocalObject(OBJECT_SELF, "ITEM");
// Get item value
int iItemCost = GetGoldPieceValue(oItem);
// Get items level based on its value from 2da file
if (iItemCost < 1000) iItemCost = 1;
else if (iItemCost < 1500) iItemCost = 2;
else if (iItemCost < 2500) iItemCost = 3;
else if (iItemCost < 3500) iItemCost = 4;
else if (iItemCost < 5000) iItemCost = 5;
else if (iItemCost < 6500) iItemCost = 6;
else if (iItemCost < 9000) iItemCost = 7;
else if (iItemCost < 12000) iItemCost = 8;
else if (iItemCost < 15000) iItemCost = 9;
else if (iItemCost < 19500) iItemCost = 10;
else if (iItemCost < 25000) iItemCost = 11;
else if (iItemCost < 30000) iItemCost = 12;
else if (iItemCost < 35000) iItemCost = 13;
else if (iItemCost < 40000) iItemCost = 14;
else if (iItemCost < 50000) iItemCost = 15;
else if (iItemCost < 65000) iItemCost = 16;
else if (iItemCost < 75000) iItemCost = 17;
else if (iItemCost < 90000) iItemCost = 18;
else if (iItemCost < 110000) iItemCost = 19;
else if (iItemCost < 130000) iItemCost = 20;
else if (iItemCost < 250000) iItemCost = 21;
else if (iItemCost < 500000) iItemCost = 22;
else if (iItemCost < 750000) iItemCost = 23;
else if (iItemCost < 1000000) iItemCost = 24;
else if (iItemCost < 1200000) iItemCost = 25;
else if (iItemCost < 1400000) iItemCost = 26;
else if (iItemCost < 1600000) iItemCost = 27;
else if (iItemCost < 1800000) iItemCost = 28;
else if (iItemCost < 2000000) iItemCost = 29;
else if (iItemCost < 2200000) iItemCost = 30;
else if (iItemCost < 2400000) iItemCost = 31;
else if (iItemCost < 2600000) iItemCost = 32;
else if (iItemCost < 2800000) iItemCost = 33;
else if (iItemCost < 3000000) iItemCost = 34;
else if (iItemCost < 3200000) iItemCost = 35;
else if (iItemCost < 3400000) iItemCost = 36;
else if (iItemCost < 3600000) iItemCost = 37;
else if (iItemCost < 3800000) iItemCost = 38;
else if (iItemCost < 4000000) iItemCost = 39;
else if (iItemCost < 4200000) iItemCost = 40;
else if (iItemCost < 4400000) iItemCost = 41;
else if (iItemCost < 4600000) iItemCost = 42;
else if (iItemCost < 4800000) iItemCost = 43;
else if (iItemCost < 5000000) iItemCost = 44;
else if (iItemCost < 5200000) iItemCost = 45;
else if (iItemCost < 5400000) iItemCost = 46;
else if (iItemCost < 5600000) iItemCost = 47;
else if (iItemCost < 5800000) iItemCost = 48;
else if (iItemCost < 6000000) iItemCost = 49;
else if (iItemCost < 6200000) iItemCost = 50;
else if (iItemCost < 6400000) iItemCost = 51;
else if (iItemCost < 6600000) iItemCost = 52;
else if (iItemCost < 6800000) iItemCost = 53;
else if (iItemCost < 7000000) iItemCost = 54;
else if (iItemCost < 7200000) iItemCost = 55;
else if (iItemCost < 7400000) iItemCost = 56;
else if (iItemCost < 7600000) iItemCost = 57;
else if (iItemCost < 7800000) iItemCost = 58;
else if (iItemCost < 8000000) iItemCost = 59;
else iItemCost = 60;
// Return the items required level
return iItemCost;
}
string GetItemLevelString()
{
// Check for ITEM_LEVEL_DISPLAY const
if (!ITEM_LEVEL_DISPLAY) return "";
// Vars
string sItemLevel;
int iPCLevel = GetLocalInt(OBJECT_SELF, "PC_LEVEL"),
iItemLevel = GetItemLevel();
// Compare players level with the items level
if (iItemLevel <= iPCLevel)
{
// Item level is within players level - (Green Text)
sItemLevel = "\n<c <20> >Item Level: " + IntToString(iItemLevel) + "</c>";
}
else
{
// Item level is higher than players level - (Red Text)
sItemLevel = "\n<c <20> >Item Level: </c><c<> >" + IntToString(iItemLevel) +
"</c><c <20> > (This item's level is too high for you)</c>";
}
return sItemLevel;
}
string GetPropertiesString()
{
// Get item properties from local vars
string sProp1 = GetLocalString(OBJECT_SELF, "PROP_1"),
sProp2 = GetLocalString(OBJECT_SELF, "PROP_2"),
sProp3 = GetLocalString(OBJECT_SELF, "PROP_3"),
sProp4 = GetLocalString(OBJECT_SELF, "PROP_4"),
sProp5 = GetLocalString(OBJECT_SELF, "PROP_5"),
sProp6 = GetLocalString(OBJECT_SELF, "PROP_6"),
sProp7 = GetLocalString(OBJECT_SELF, "PROP_7"),
sProp8 = GetLocalString(OBJECT_SELF, "PROP_8");
// Check which properties are valid
if (sProp1 != "") sProp1 = "\n" + sProp1;
if (sProp2 != "") sProp2 = "\n" + sProp2;
if (sProp3 != "") sProp3 = "\n" + sProp3;
if (sProp4 != "") sProp4 = "\n" + sProp4;
if (sProp5 != "") sProp5 = "\n" + sProp5;
if (sProp6 != "") sProp6 = "\n" + sProp6;
if (sProp7 != "") sProp7 = "\n" + sProp7;
if (sProp8 != "") sProp8 = "\n" + sProp8;
return sProp1 + sProp2 + sProp3 + sProp4 +
sProp5 + sProp6 + sProp7 + sProp8;
}
void ResetVars()
{
// Delete all local vars and tokens and items
object oItem = GetLocalObject(OBJECT_SELF, "ITEM");
DestroyObject(oItem);
DeleteLocalObject(OBJECT_SELF, "ITEM");
DeleteLocalInt(OBJECT_SELF, "PC_LEVEL");
DeleteLocalInt(OBJECT_SELF, "PC_GOLD");
DeleteLocalString(OBJECT_SELF, "BONUS");
DeleteLocalString(OBJECT_SELF, "ITEM_NAME");
DeleteLocalString(OBJECT_SELF, "ITEM_LEVEL");
DeleteLocalString(OBJECT_SELF, "ITEM_TYPE");
DeleteLocalString(OBJECT_SELF, "PROP_1");
DeleteLocalString(OBJECT_SELF, "PROP_2");
DeleteLocalString(OBJECT_SELF, "PROP_3");
DeleteLocalString(OBJECT_SELF, "PROP_4");
DeleteLocalString(OBJECT_SELF, "PROP_5");
DeleteLocalString(OBJECT_SELF, "PROP_6");
DeleteLocalString(OBJECT_SELF, "PROP_7");
DeleteLocalString(OBJECT_SELF, "PROP_8");
DeleteLocalInt(OBJECT_SELF, "PROP_1");
DeleteLocalInt(OBJECT_SELF, "PROP_2");
DeleteLocalInt(OBJECT_SELF, "PROP_3");
DeleteLocalInt(OBJECT_SELF, "PROP_4");
DeleteLocalInt(OBJECT_SELF, "PROP_5");
DeleteLocalInt(OBJECT_SELF, "PROP_6");
DeleteLocalInt(OBJECT_SELF, "PROP_7");
DeleteLocalInt(OBJECT_SELF, "PROP_8");
SetCustomToken(501, "");
}
void SetMenuText()
{
// Item name
string sItem = GetLocalString(OBJECT_SELF, "ITEM_NAME");
// Item Level
string sItemLevel = GetItemLevelString();
// Item cost
string sItemCost = GetItemCostString();
// Item properties
string sProps = GetPropertiesString();
// Set menu custom token
string sMenu = "<c <20> >Scarface's Crafting System V1.0</c>\n\n" +
"<c f<>>" + sItem + "</c>" + sItemLevel + "\n" +
sItemCost + "\n<c f<>>" + sProps +"</c>";
SetCustomToken(500, sMenu);
}
string GetItemPropertySlot(string sPropName)
{
// Get item properties from local vars
string sProp1 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_1"), 4),
sProp2 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_2"), 4),
sProp3 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_3"), 4),
sProp4 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_4"), 4),
sProp5 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_5"), 4),
sProp6 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_6"), 4),
sProp7 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_7"), 4),
sProp8 = GetStringLeft(GetLocalString(OBJECT_SELF, "PROP_8"), 4);
// Check for sProps local var slot if applicable
if (sProp1 == GetStringLeft(sPropName, 4)) return "PROP_1";
else if (MAX_ITEM_PROPERTIES >= 2 && sProp2 == GetStringLeft(sPropName, 4)) return "PROP_2";
else if (MAX_ITEM_PROPERTIES >= 3 && sProp3 == GetStringLeft(sPropName, 4)) return "PROP_3";
else if (MAX_ITEM_PROPERTIES >= 4 && sProp4 == GetStringLeft(sPropName, 4)) return "PROP_4";
else if (MAX_ITEM_PROPERTIES >= 5 && sProp5 == GetStringLeft(sPropName, 4)) return "PROP_5";
else if (MAX_ITEM_PROPERTIES >= 6 && sProp6 == GetStringLeft(sPropName, 4)) return "PROP_6";
else if (MAX_ITEM_PROPERTIES >= 7 && sProp7 == GetStringLeft(sPropName, 4)) return "PROP_7";
else if (MAX_ITEM_PROPERTIES >= 8 && sProp8 == GetStringLeft(sPropName, 4)) return "PROP_8";
else if (sProp1 == "") return "PROP_1";
else if (MAX_ITEM_PROPERTIES >= 2 && sProp2 == "") return "PROP_2";
else if (MAX_ITEM_PROPERTIES >= 3 && sProp3 == "") return "PROP_3";
else if (MAX_ITEM_PROPERTIES >= 4 && sProp4 == "") return "PROP_4";
else if (MAX_ITEM_PROPERTIES >= 5 && sProp5 == "") return "PROP_5";
else if (MAX_ITEM_PROPERTIES >= 6 && sProp6 == "") return "PROP_6";
else if (MAX_ITEM_PROPERTIES >= 7 && sProp7 == "") return "PROP_7";
else if (MAX_ITEM_PROPERTIES >= 8 && sProp8 == "") return "PROP_8";
return "INVALID";
}
string GetItemCostString()
{
// Vars
string sItemCost;
object oItem = GetLocalObject(OBJECT_SELF, "ITEM");
int iPCGold = GetLocalInt(OBJECT_SELF, "PC_GOLD"),
iItemCost = GetItemCost(oItem);
// Compare players gold with the items cost value
if (iItemCost <= iPCGold)
{
// Item level is within players level - (Green Text)
sItemCost = "<c<><63> >Item Cost: " + IntToString(iItemCost) + "</c>";
}
else
{
// Item level is higher than players level - (Red Text)
sItemCost = "<c<><63> >Item Cost: </c><c<> >" + IntToString(iItemCost) +
"</c><c<><63> > (You can't afford this)</c>";
}
return sItemCost;
}
int DamageBonus(int iProp)
{
switch(iProp)
{
case 1: iProp = IP_CONST_DAMAGEBONUS_1; break;
case 2: iProp = IP_CONST_DAMAGEBONUS_2; break;
case 3: iProp = IP_CONST_DAMAGEBONUS_3; break;
case 4: iProp = IP_CONST_DAMAGEBONUS_4; break;
case 5: iProp = IP_CONST_DAMAGEBONUS_5; break;
case 6: iProp = IP_CONST_DAMAGEBONUS_6; break;
case 7: iProp = IP_CONST_DAMAGEBONUS_7; break;
case 8: iProp = IP_CONST_DAMAGEBONUS_8; break;
case 9: iProp = IP_CONST_DAMAGEBONUS_9; break;
case 10: iProp = IP_CONST_DAMAGEBONUS_10; break;
}
return iProp;
}
int GetItemCost(object oItem)
{
// Calculate the item costbased on the COST_MULTIPLIER const
float fItemCost = COST_MULTIPLIER * IntToFloat(GetGoldPieceValue(oItem));
int iItemCost = FloatToInt(fItemCost);
if (iItemCost < 1) iItemCost = 1;
return iItemCost;
}