EZ 1 script Magic Equipment buffs
Posted: Sat Jul 01, 2023 3:46 pm
I wrote this to make having magic items a little easier in the game.
You'll have to update the script number in the script or set it to 5052 in your jsfileassociations script.
but all you should have to do is set script trigger to the script number on any piece of equipment and it will randomly roll magic properties for it, from the handful that I currently have working. which is buffs to str,dex,int,health,stam,mana, and a new thorns effect.
For artifact grade items, you will have to manually edit the buffList tag to set the values for each effect you want either through a command like set,a new script or through the DFNs and also manually set the flavorText tag to add the little quip at the end of the tooltip that gives the item some character/backstory.
Edit [ Feel free to respond to this with any suggestions for effects or updates or hit me up on discord in the scripting chat]
You'll have to update the script number in the script or set it to 5052 in your jsfileassociations script.
but all you should have to do is set script trigger to the script number on any piece of equipment and it will randomly roll magic properties for it, from the handful that I currently have working. which is buffs to str,dex,int,health,stam,mana, and a new thorns effect.
For artifact grade items, you will have to manually edit the buffList tag to set the values for each effect you want either through a command like set,a new script or through the DFNs and also manually set the flavorText tag to add the little quip at the end of the tooltip that gives the item some character/backstory.
Edit [ Feel free to respond to this with any suggestions for effects or updates or hit me up on discord in the scripting chat]
// Stat-boosting Equipment Humility, 7-1-2023
function onEquip(pEquipper, iEquipped) {
var buffMan = new characterBuffInterface(pEquipper, iEquipped); // Instantiate interface object
if (iEquipped.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
buffMan.Strength.Increment(ItemBuffArray[0]); //strength
buffMan.Dexterity.Increment(ItemBuffArray[1]); //dex
buffMan.Intelligence.Increment(ItemBuffArray[2]); //int
buffMan.Thorns.Increment(ItemBuffArray[3]); //thorns
buffMan.MaxHealth.Increment(ItemBuffArray[6]); //maxhealth
buffMan.MaxStam.Increment(ItemBuffArray[7]); //maxstamina
buffMan.MaxMana.Increment(ItemBuffArray[8]); //maxmana
buffMan.charObj.AddScriptTrigger(5052);
Console.Print(buffMan.charObj.scripttrigger.length)
//if (indexof(5052) != -1) { Console.Print("Trigger 5052 found"); }
return true;
}
function onUnequip(pUnequipper, iUnequipped) {
var buffMan = new characterBuffInterface(pUnequipper, iUnequipped); // Instantiate interface object
if (iUnequipped.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
buffMan.Strength.Decrement(ItemBuffArray[0]); //strength
buffMan.Dexterity.Decrement(ItemBuffArray[1]); //dex
buffMan.Intelligence.Decrement(ItemBuffArray[2]); //int
buffMan.Thorns.Decrement(ItemBuffArray[3]); //thorns
buffMan.MaxHealth.Decrement(ItemBuffArray[6]); //maxhealth
buffMan.MaxStam.Decrement(ItemBuffArray[7]); //maxstamina
buffMan.MaxMana.Decrement(ItemBuffArray[8]); //maxmana
// check all equipment to see if any of them have script trigger 5052
if (!buffMan.OneOfUs()) { //no other scripts found with 5052 magic item script remove it from player.
buffMan.charObj.RemoveScriptTrigger(5052);
}
return true;
}
function onTooltip(myObj) {
if (typeof myObj.accountNum != "undefined" || myObj.npc) { return myObj.name; } else {
var buffMan = new characterBuffInterface(null, myObj); // Instantiate interface object
if (myObj.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
if (typeof ItemBuffArray == "undefined") { return false; } // missing tags wreaking havoc
// Setup our template colors
var buffGreen = "<BASEFONT COLOR=#008000>";
var debuffRed = "<BASEFONT COLOR=#FF0000>";
var statWhite = "<BASEFONT COLOR=#D0D0F0 size= 2>";
var flavorGold = "<BASEFONT COLOR=#FFD700 size= 5 >";
var clBase = "</BASEFONT>"; // close the basefont tag
var flags = buffMan.GetFlags(myObj.GetTag("statBonusFlags"));
var Stats = [
"Strength", "Dexterity", "Intelligence", "Thorns",
"Faster Casting", "Faster Cast Recovery", "Health",
"Stamina", "Mana", "Health Regeneration", "Mana Regeneration",
"Stamina Regeneration", "Resist All Elements",
"Damage Reduction", "Luck", "Gold Find"
];
var tooltipText = "";
Stats.forEach(function (stat, index) {
if (ItemBuffArray[index] > 0) {
tooltipText += (parseInt(ItemBuffArray[index]) > 0 ? buffGreen + " " : debuffRed);
tooltipText += (index > 0 ? "\n+":"+") + ItemBuffArray[index].toString() + statWhite + " " + stat + clBase; //aesthetics
}
});
var myFlayvah = myObj.GetTag("flavorText");
if (myFlayvah != "0") { tooltipText += flavorGold + "\n"+ myFlayvah+clBase +"\n"; }
tooltipText += statWhite;
return tooltipText;
}
}
//B></B> <BIG></BIG> <SMALL></SMALL> <EM></EM> <I></I> <U></U> <H1></H1> <H2></H2> <H3></H3> <H4></H4> <H5></H5> <H6></H6>
//<a href=""></a> <div align="right"><div align="left"></DIV> <left></left> <P> <CENTER></CENTER> <BR></BR> <BASEFONT color=#ffffff size=1-7></BASEFONT>
function onNameRequest(myObj, requestedBy) {
if (typeof myObj.accountNum != "undefined" || myObj.npc) {
//Console.Print(requestedBy.name.toString());
return myObj.name //+ "\n" + "thorns: xAmount"; //testing whether it will screw up the status bar and such.
} else {
return "<BASEFONT COLOR=#00BFFF size=7>" + myObj.name + "</BASEFONT>"; //magic item blue
}
}
//o------------------------------------------------------------------------------------------------o
//| Function - characterBuffInterface(buffChar)
//| Date - 06/29/2023
//o------------------------------------------------------------------------------------------------o
//| Purpose - Constructor to supply API functions and interface to apply complex equipment buffs
//| Changes -
//|
//|
//|
//|
//o------------------------------------------------------------------------------------------------o
function characterBuffInterface(pChar, myObj) {
var self = this;
this.itemObj = myObj;
this.charObj = pChar;
// initialize player variables.
// ACHTUNG!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.strength = 0; // the strength value variable
this.Strength = {}; // the Strength function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Strength.Get = function () { // Gets the current values from the character object and sets them to JS object
self.strength = self.charObj.strength;
}
this.Strength.Set = function () { // updates character object with JS object changes
self.charObj.strength = self.strength;
}
this.Strength.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Strength.Get();
self.strength += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Strength.Set();
}
this.Strength.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Strength.Get();
self.strength -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Strength.Set();
}
this.dexterity = 0; // the dex value variable
this.Dexterity = {}; // the Dex function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Dexterity.Get = function () { // Gets the current values from the character object and sets them to JS object
self.dexterity = self.charObj.dexterity;
}
this.Dexterity.Set = function () { // updates character object with JS object changes
self.charObj.dexterity = self.dexterity;
}
this.Dexterity.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Dexterity.Get();
self.dexterity += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Dexterity.Set();
}
this.Dexterity.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Dexterity.Get();
self.dexterity -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Dexterity.Set();
}
this.intelligence = 0; // the intelligence value variable
this.Intelligence = {}; // the Intelligence function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Intelligence.Get = function () { // Gets the current values from the character object and sets them to JS object
self.intelligence = self.charObj.intelligence;
}
this.Intelligence.Set = function () { // updates character object with JS object changes
self.charObj.intelligence = self.intelligence;
}
this.Intelligence.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Intelligence.Get();
self.intelligence += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Intelligence.Set();
}
this.Intelligence.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Intelligence.Get();
self.intelligence -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Intelligence.Set();
}
this.thorns = 0; // the thorns value variable
this.Thorns = {}; // the Thorns function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Thorns.Get = function () { // Gets the current values from the character object's tag and sets them to JS object
self.thorns = parseInt(self.charObj.GetTag("thorns"));
}
this.Thorns.Set = function () { // updates character object's Tag with JS object changes
if (self.thorns < 1) { // if we somehow get bugged out and go negative we will delete the tag so re-equipping the items will correct it.
self.charObj.SetTag("thorns", null);
} else {
self.charObj.SetTag("thorns", self.thorns.toString());
}
Console.Print("Thorns: " + self.charObj.GetTag("thorns").toString());
}
this.Thorns.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Thorns.Get();
self.thorns += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Thorns.Set();
}
this.Thorns.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Thorns.Get();
self.thorns -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Thorns.Set();
}
this.fCasting = 0;
this.fCasting.Get = function () { // nonexistant character variable - unimplemented
self.fCasting = self.charObj.fCasting;
}
this.fCasting.Set = function (newStr) {
self.charObj.fCasting = newStr;
}
this.fCasting.Increment = function (valuePlus) {
self.fCasting = self.charObj.fCasting;
self.fCasting += valuePlus;
}
this.fCasting.Decrement = function (valueMinus) {
self.fCasting = self.charObj.fCasting;
self.fCasting -= valueMinus;
}
this.fCastRecover = 0;
this.fCastRecover.Get = function () { // nonexistant character variable - unimplemented
self.fCastRecover = self.charObj.fCastRecover;
}
this.fCastRecover.Set = function (newStr) {
self.charObj.fCastRecover = newStr;
}
this.fCastRecover.Increment = function (valuePlus) {
self.fCastRecover = self.charObj.fCastRecover;
self.fCastRecover += valuePlus;
}
this.fCastRecover.Decrement = function (valueMinus) {
self.fCastRecover = self.charObj.fCastRecover;
self.fCastRecover -= valueMinus;
}
this.maxhp = 0; // the health value variable
this.MaxHealth = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxHealth.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxhp = self.charObj.maxhp;
}
this.MaxHealth.Set = function () { // updates character object with JS object changes
self.charObj.maxhp = self.maxhp;
}
this.MaxHealth.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxHealth.Get();
self.maxhp += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxHealth.Set();
}
this.MaxHealth.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxHealth.Get();
self.maxhp -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxHealth.Set();
}
this.maxmana = 0; // the health value variable
this.MaxMana = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxMana.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxmana = self.charObj.maxhp;
}
this.MaxMana.Set = function () { // updates character object with JS object changes
self.charObj.maxmana = self.maxmana;
}
this.MaxMana.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxMana.Get();
self.maxmana += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxMana.Set();
}
this.MaxMana.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxMana.Get();
self.maxmana -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxMana.Set();
}
this.maxstamina = 0; // the health value variable
this.MaxStam = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxStam.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxstamina = self.charObj.maxstamina;
}
this.MaxStam.Set = function () { // updates character object with JS object changes
self.charObj.maxstamina = self.maxstamina;
}
this.MaxStam.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxStam.Get();
self.maxstamina += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxStam.Set();
}
this.MaxStam.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxStam.Get();
self.maxstamina -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxStam.Set();
}
this.healthRegen = 0;
this.healthRegen.Get = function () { // nonexistant character variable - unimplemented
self.healthRegen = self.charObj.healthRegen;
}
this.healthRegen.Set = function (newStr) {
self.charObj.healthRegen = newStr;
}
this.healthRegen.Increment = function (valuePlus) {
self.healthRegen = self.charObj.healthRegen;
self.healthRegen += valuePlus;
}
this.healthRegen.Decrement = function (valueMinus) {
self.healthRegen = self.charObj.healthRegen;
self.healthRegen -= valueMinus;
}
this.manaRegen = 0;
this.manaRegen.Get = function () { // nonexistant character variable - unimplemented
self.manaRegen = self.charObj.manaRegen;
}
this.manaRegen.Set = function (newStr) {
self.charObj.manaRegen = newStr;
}
this.manaRegen.Increment = function (valuePlus) {
self.manaRegen = self.charObj.manaRegen;
self.manaRegen += valuePlus;
}
this.manaRegen.Decrement = function (valueMinus) {
self.manaRegen = self.charObj.manaRegen;
self.manaRegen -= valueMinus;
}
this.stamRegen = 0;
this.stamRegen.Get = function () { // nonexistant character variable - unimplemented
self.stamRegen = self.charObj.stamRegen;
}
this.stamRegen.Set = function (newStr) {
self.charObj.stamRegen = newStr;
}
this.stamRegen.Increment = function (valuePlus) {
self.stamRegen = self.charObj.stamRegen;
self.stamRegen += valuePlus;
}
this.stamRegen.Decrement = function (valueMinus) {
self.stamRegen = self.charObj.stamRegen;
self.stamRegen -= valueMinus;
}
this.resistAllElem = 0;
this.resistAllElem.Get = function () { // nonexistant character variable - unimplemented
self.resistAllElem = self.charObj.resistAllElem;
}
this.resistAllElem.Set = function (newStr) {
self.charObj.resistAllElem = newStr;
}
this.resistAllElem.Increment = function (valuePlus) {
self.resistAllElem = self.charObj.resistAllElem;
self.resistAllElem += valuePlus;
}
this.resistAllElem.Decrement = function (valueMinus) {
self.resistAllElem = self.charObj.resistAllElem;
self.resistAllElem -= valueMinus;
}
this.physDamReduct = 0;
this.physDamReduct.Get = function () { // nonexistant character variable - unimplemented
self.physDamReduct = self.charObj.physDamReduct;
}
this.physDamReduct.Set = function (newStr) {
self.charObj.physDamReduct = newStr;
}
this.physDamReduct.Increment = function (valuePlus) {
self.physDamReduct = self.charObj.physDamReduct;
self.physDamReduct += valuePlus;
}
this.physDamReduct.Decrement = function (valueMinus) {
self.physDamReduct = self.charObj.physDamReduct;
self.physDamReduct -= valueMinus;
}
this.goldFind = 0;
this.goldFind.Get = function () { // nonexistant character variable - unimplemented
self.goldFind = self.charObj.goldFind;
}
this.goldFind.Set = function (newStr) {
self.charObj.goldFind = newStr;
}
this.goldFind.Increment = function (valuePlus) {
self.goldFind = self.charObj.goldFind;
self.goldFind += valuePlus;
}
this.goldFind.Decrement = function (valueMinus) {
self.goldFind = self.charObj.goldFind;
self.goldFind -= valueMinus;
}
this.GetFlags = function (string) {
bits = parseInt(string);
return [
bits & 1, bits >>> 1 & 1, bits >>> 2 & 1, bits >>> 3 & 1, bits >>> 4 & 1, bits >>> 5 & 1, bits >>> 6 & 1, bits >>> 7 & 1,
bits >>> 8 & 1, bits >>> 9 & 1, bits >>> 10 & 1, bits >>> 11 & 1, bits >>> 12 & 1, bits >>> 13 & 1, bits >>> 14 & 1, bits >>> 15 & 1, bits >>> 16 & 1
]
}
this.GetItemBuffs = function () {
var flags = self.GetFlags(self.itemObj.GetTag("statBonusFlags").toString()); //[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536]
//self.SerializeTag(self.itemObj);
var buffString = self.itemObj.GetTag("buffList").toString();
Console.Print("buffList [" + buffString + "]\n");
return self.DeserializeTag(buffString);
}
this.SerializeTag = function (myObject) { // for debug quick setting the buffs tag
var buffString = "1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0"
myObject.SetTag("buffList", buffString);
}
this.DeserializeTag = function (tagString) {
if (typeof tagString != "undefined") {
var buffArray = tagString.split(",");
return buffArray
} else {
Console.Print("Magic Item Script - Deserialize passed undefined variable instead of string.\n")
return false;
}
}
this.OneOfUs = function () {
myObj = self.itemObj;
//search for other items with script "5052"
for (i = 0; i != 25; i++) {
mItem = self.charObj.FindItemLayer(i);
if (ValidateObject(mItem) && i != 15 && i != 16 && i != 21) {
l = mItem.scriptTriggers.length;
for (j = 0; j != l; j++) {
if (mItem.scriptTriggers[j] == 5052 && mItem.serial != myObj.serial) {
Console.Print("found one!\n");
return true;
}
}
}
}
return false; //no other items with this script exist in equipment list
}
this.NewLoot = function () {
Console.Print("Running New Loot function.\n");
var flags = 0;
var bitTotals = 0;
var buffList = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var availablePowers = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768];
var availablePotency = [5, 5, 5, 500, 0, 0, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0];
var maxPowers = 5; // Maximum number of powers to apply
var probabilityMultiplier = 1; // Initial probability multiplier
// Generate random values for flags and buffList
for (var i = 0; i < maxPowers; i++) {
var randomIndex = Math.floor(Math.random() * availablePowers.length);
var randomPower = availablePowers.splice(randomIndex, 1)[0];
var randomPotency = Math.round(Math.random() * availablePotency[randomIndex]);
buffList[randomIndex]=randomPotency;
bitTotals += randomPower;
Console.Print(bitTotals.toString() + "\n");
// Reduce the probability for the next power
probabilityMultiplier *= 0.8; // Adjust the diminishing factor as desired
// Adjust the availablePowers array based on the reduced probability
availablePowers = availablePowers.filter(function (power) {
return Math.random() < probabilityMultiplier;
});
}
// Set the flags and buffList
self.itemObj.SetTag("statBonusFlags", bitTotals.toString());
self.itemObj.SetTag("buffList", buffList.join(","));
}
}
// character stuff for when the character processes the buffs after the script is applied to them.
function onSpellCast(pUser, SpellID) { // add faster casting code here
return 500;
}
function onDamage(pAttacked, pAttacker, dValue, dType) {
var myThorns = parseInt(pAttacked.GetTag("thorns").toString()); // thorns
if (ValidateObject(pAttacker)) {
pAttacker.Damage((myThorns > 0 ? ((RandomInt(pAttacked.hidamage - pAttacked.lodamage) + pAttacked.loDamage) * .01) * myThorns : 0), 0, pAttacked, false); //check this math.
}
var mydReflect = parseInt(pAttacked.GetTag("dReflect").toString()); //damage Reflection
if (ValidateObject(pAttacker)) {
pAttacker.Damage((mydReflect > 0 ? (dValue * .01) * myThorns : 0), 0, pAttacked, false);
}
}
function onDeathBlow(pKilled, pKiller) {
return false; //debug immortality.
}
// myChar.SetTimer( timer.SPELLRECOVERYTIME, 500 );
function RandomInt(rvalue) {
//returns random integer with maximum given
return Math.floor(Math.random() * rvalue);
}
function _restorecontext_() { }
function onEquip(pEquipper, iEquipped) {
var buffMan = new characterBuffInterface(pEquipper, iEquipped); // Instantiate interface object
if (iEquipped.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
buffMan.Strength.Increment(ItemBuffArray[0]); //strength
buffMan.Dexterity.Increment(ItemBuffArray[1]); //dex
buffMan.Intelligence.Increment(ItemBuffArray[2]); //int
buffMan.Thorns.Increment(ItemBuffArray[3]); //thorns
buffMan.MaxHealth.Increment(ItemBuffArray[6]); //maxhealth
buffMan.MaxStam.Increment(ItemBuffArray[7]); //maxstamina
buffMan.MaxMana.Increment(ItemBuffArray[8]); //maxmana
buffMan.charObj.AddScriptTrigger(5052);
Console.Print(buffMan.charObj.scripttrigger.length)
//if (indexof(5052) != -1) { Console.Print("Trigger 5052 found"); }
return true;
}
function onUnequip(pUnequipper, iUnequipped) {
var buffMan = new characterBuffInterface(pUnequipper, iUnequipped); // Instantiate interface object
if (iUnequipped.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
buffMan.Strength.Decrement(ItemBuffArray[0]); //strength
buffMan.Dexterity.Decrement(ItemBuffArray[1]); //dex
buffMan.Intelligence.Decrement(ItemBuffArray[2]); //int
buffMan.Thorns.Decrement(ItemBuffArray[3]); //thorns
buffMan.MaxHealth.Decrement(ItemBuffArray[6]); //maxhealth
buffMan.MaxStam.Decrement(ItemBuffArray[7]); //maxstamina
buffMan.MaxMana.Decrement(ItemBuffArray[8]); //maxmana
// check all equipment to see if any of them have script trigger 5052
if (!buffMan.OneOfUs()) { //no other scripts found with 5052 magic item script remove it from player.
buffMan.charObj.RemoveScriptTrigger(5052);
}
return true;
}
function onTooltip(myObj) {
if (typeof myObj.accountNum != "undefined" || myObj.npc) { return myObj.name; } else {
var buffMan = new characterBuffInterface(null, myObj); // Instantiate interface object
if (myObj.GetTag("statBonusFlags") < 1) { buffMan.NewLoot(); }
var ItemBuffArray = buffMan.GetItemBuffs();
if (typeof ItemBuffArray == "undefined") { return false; } // missing tags wreaking havoc
// Setup our template colors
var buffGreen = "<BASEFONT COLOR=#008000>";
var debuffRed = "<BASEFONT COLOR=#FF0000>";
var statWhite = "<BASEFONT COLOR=#D0D0F0 size= 2>";
var flavorGold = "<BASEFONT COLOR=#FFD700 size= 5 >";
var clBase = "</BASEFONT>"; // close the basefont tag
var flags = buffMan.GetFlags(myObj.GetTag("statBonusFlags"));
var Stats = [
"Strength", "Dexterity", "Intelligence", "Thorns",
"Faster Casting", "Faster Cast Recovery", "Health",
"Stamina", "Mana", "Health Regeneration", "Mana Regeneration",
"Stamina Regeneration", "Resist All Elements",
"Damage Reduction", "Luck", "Gold Find"
];
var tooltipText = "";
Stats.forEach(function (stat, index) {
if (ItemBuffArray[index] > 0) {
tooltipText += (parseInt(ItemBuffArray[index]) > 0 ? buffGreen + " " : debuffRed);
tooltipText += (index > 0 ? "\n+":"+") + ItemBuffArray[index].toString() + statWhite + " " + stat + clBase; //aesthetics
}
});
var myFlayvah = myObj.GetTag("flavorText");
if (myFlayvah != "0") { tooltipText += flavorGold + "\n"+ myFlayvah+clBase +"\n"; }
tooltipText += statWhite;
return tooltipText;
}
}
//B></B> <BIG></BIG> <SMALL></SMALL> <EM></EM> <I></I> <U></U> <H1></H1> <H2></H2> <H3></H3> <H4></H4> <H5></H5> <H6></H6>
//<a href=""></a> <div align="right"><div align="left"></DIV> <left></left> <P> <CENTER></CENTER> <BR></BR> <BASEFONT color=#ffffff size=1-7></BASEFONT>
function onNameRequest(myObj, requestedBy) {
if (typeof myObj.accountNum != "undefined" || myObj.npc) {
//Console.Print(requestedBy.name.toString());
return myObj.name //+ "\n" + "thorns: xAmount"; //testing whether it will screw up the status bar and such.
} else {
return "<BASEFONT COLOR=#00BFFF size=7>" + myObj.name + "</BASEFONT>"; //magic item blue
}
}
//o------------------------------------------------------------------------------------------------o
//| Function - characterBuffInterface(buffChar)
//| Date - 06/29/2023
//o------------------------------------------------------------------------------------------------o
//| Purpose - Constructor to supply API functions and interface to apply complex equipment buffs
//| Changes -
//|
//|
//|
//|
//o------------------------------------------------------------------------------------------------o
function characterBuffInterface(pChar, myObj) {
var self = this;
this.itemObj = myObj;
this.charObj = pChar;
// initialize player variables.
// ACHTUNG!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.strength = 0; // the strength value variable
this.Strength = {}; // the Strength function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Strength.Get = function () { // Gets the current values from the character object and sets them to JS object
self.strength = self.charObj.strength;
}
this.Strength.Set = function () { // updates character object with JS object changes
self.charObj.strength = self.strength;
}
this.Strength.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Strength.Get();
self.strength += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Strength.Set();
}
this.Strength.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Strength.Get();
self.strength -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Strength.Set();
}
this.dexterity = 0; // the dex value variable
this.Dexterity = {}; // the Dex function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Dexterity.Get = function () { // Gets the current values from the character object and sets them to JS object
self.dexterity = self.charObj.dexterity;
}
this.Dexterity.Set = function () { // updates character object with JS object changes
self.charObj.dexterity = self.dexterity;
}
this.Dexterity.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Dexterity.Get();
self.dexterity += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Dexterity.Set();
}
this.Dexterity.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Dexterity.Get();
self.dexterity -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Dexterity.Set();
}
this.intelligence = 0; // the intelligence value variable
this.Intelligence = {}; // the Intelligence function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Intelligence.Get = function () { // Gets the current values from the character object and sets them to JS object
self.intelligence = self.charObj.intelligence;
}
this.Intelligence.Set = function () { // updates character object with JS object changes
self.charObj.intelligence = self.intelligence;
}
this.Intelligence.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Intelligence.Get();
self.intelligence += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Intelligence.Set();
}
this.Intelligence.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Intelligence.Get();
self.intelligence -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Intelligence.Set();
}
this.thorns = 0; // the thorns value variable
this.Thorns = {}; // the Thorns function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.Thorns.Get = function () { // Gets the current values from the character object's tag and sets them to JS object
self.thorns = parseInt(self.charObj.GetTag("thorns"));
}
this.Thorns.Set = function () { // updates character object's Tag with JS object changes
if (self.thorns < 1) { // if we somehow get bugged out and go negative we will delete the tag so re-equipping the items will correct it.
self.charObj.SetTag("thorns", null);
} else {
self.charObj.SetTag("thorns", self.thorns.toString());
}
Console.Print("Thorns: " + self.charObj.GetTag("thorns").toString());
}
this.Thorns.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.Thorns.Get();
self.thorns += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.Thorns.Set();
}
this.Thorns.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.Thorns.Get();
self.thorns -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.Thorns.Set();
}
this.fCasting = 0;
this.fCasting.Get = function () { // nonexistant character variable - unimplemented
self.fCasting = self.charObj.fCasting;
}
this.fCasting.Set = function (newStr) {
self.charObj.fCasting = newStr;
}
this.fCasting.Increment = function (valuePlus) {
self.fCasting = self.charObj.fCasting;
self.fCasting += valuePlus;
}
this.fCasting.Decrement = function (valueMinus) {
self.fCasting = self.charObj.fCasting;
self.fCasting -= valueMinus;
}
this.fCastRecover = 0;
this.fCastRecover.Get = function () { // nonexistant character variable - unimplemented
self.fCastRecover = self.charObj.fCastRecover;
}
this.fCastRecover.Set = function (newStr) {
self.charObj.fCastRecover = newStr;
}
this.fCastRecover.Increment = function (valuePlus) {
self.fCastRecover = self.charObj.fCastRecover;
self.fCastRecover += valuePlus;
}
this.fCastRecover.Decrement = function (valueMinus) {
self.fCastRecover = self.charObj.fCastRecover;
self.fCastRecover -= valueMinus;
}
this.maxhp = 0; // the health value variable
this.MaxHealth = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxHealth.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxhp = self.charObj.maxhp;
}
this.MaxHealth.Set = function () { // updates character object with JS object changes
self.charObj.maxhp = self.maxhp;
}
this.MaxHealth.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxHealth.Get();
self.maxhp += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxHealth.Set();
}
this.MaxHealth.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxHealth.Get();
self.maxhp -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxHealth.Set();
}
this.maxmana = 0; // the health value variable
this.MaxMana = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxMana.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxmana = self.charObj.maxhp;
}
this.MaxMana.Set = function () { // updates character object with JS object changes
self.charObj.maxmana = self.maxmana;
}
this.MaxMana.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxMana.Get();
self.maxmana += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxMana.Set();
}
this.MaxMana.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxMana.Get();
self.maxmana -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxMana.Set();
}
this.maxstamina = 0; // the health value variable
this.MaxStam = {}; // the health function container
// Danger will robinson!!!! pay close attention to the casing!! to keep it in line with the server and to allow for function casing we are using both!
this.MaxStam.Get = function () { // Gets the current values from the character object and sets them to JS object
self.maxstamina = self.charObj.maxstamina;
}
this.MaxStam.Set = function () { // updates character object with JS object changes
self.charObj.maxstamina = self.maxstamina;
}
this.MaxStam.Increment = function (valuePlus) { // increments value in JS object (defaults to 1)
self.MaxStam.Get();
self.maxstamina += (typeof valuePlus == "undefined" ? 1 : parseInt(valuePlus));
self.MaxStam.Set();
}
this.MaxStam.Decrement = function (valueMinus) { // decrements value in JS object (defaults to 1)
self.MaxStam.Get();
self.maxstamina -= (typeof valueMinus == "undefined" ? 1 : parseInt(valueMinus));
self.MaxStam.Set();
}
this.healthRegen = 0;
this.healthRegen.Get = function () { // nonexistant character variable - unimplemented
self.healthRegen = self.charObj.healthRegen;
}
this.healthRegen.Set = function (newStr) {
self.charObj.healthRegen = newStr;
}
this.healthRegen.Increment = function (valuePlus) {
self.healthRegen = self.charObj.healthRegen;
self.healthRegen += valuePlus;
}
this.healthRegen.Decrement = function (valueMinus) {
self.healthRegen = self.charObj.healthRegen;
self.healthRegen -= valueMinus;
}
this.manaRegen = 0;
this.manaRegen.Get = function () { // nonexistant character variable - unimplemented
self.manaRegen = self.charObj.manaRegen;
}
this.manaRegen.Set = function (newStr) {
self.charObj.manaRegen = newStr;
}
this.manaRegen.Increment = function (valuePlus) {
self.manaRegen = self.charObj.manaRegen;
self.manaRegen += valuePlus;
}
this.manaRegen.Decrement = function (valueMinus) {
self.manaRegen = self.charObj.manaRegen;
self.manaRegen -= valueMinus;
}
this.stamRegen = 0;
this.stamRegen.Get = function () { // nonexistant character variable - unimplemented
self.stamRegen = self.charObj.stamRegen;
}
this.stamRegen.Set = function (newStr) {
self.charObj.stamRegen = newStr;
}
this.stamRegen.Increment = function (valuePlus) {
self.stamRegen = self.charObj.stamRegen;
self.stamRegen += valuePlus;
}
this.stamRegen.Decrement = function (valueMinus) {
self.stamRegen = self.charObj.stamRegen;
self.stamRegen -= valueMinus;
}
this.resistAllElem = 0;
this.resistAllElem.Get = function () { // nonexistant character variable - unimplemented
self.resistAllElem = self.charObj.resistAllElem;
}
this.resistAllElem.Set = function (newStr) {
self.charObj.resistAllElem = newStr;
}
this.resistAllElem.Increment = function (valuePlus) {
self.resistAllElem = self.charObj.resistAllElem;
self.resistAllElem += valuePlus;
}
this.resistAllElem.Decrement = function (valueMinus) {
self.resistAllElem = self.charObj.resistAllElem;
self.resistAllElem -= valueMinus;
}
this.physDamReduct = 0;
this.physDamReduct.Get = function () { // nonexistant character variable - unimplemented
self.physDamReduct = self.charObj.physDamReduct;
}
this.physDamReduct.Set = function (newStr) {
self.charObj.physDamReduct = newStr;
}
this.physDamReduct.Increment = function (valuePlus) {
self.physDamReduct = self.charObj.physDamReduct;
self.physDamReduct += valuePlus;
}
this.physDamReduct.Decrement = function (valueMinus) {
self.physDamReduct = self.charObj.physDamReduct;
self.physDamReduct -= valueMinus;
}
this.goldFind = 0;
this.goldFind.Get = function () { // nonexistant character variable - unimplemented
self.goldFind = self.charObj.goldFind;
}
this.goldFind.Set = function (newStr) {
self.charObj.goldFind = newStr;
}
this.goldFind.Increment = function (valuePlus) {
self.goldFind = self.charObj.goldFind;
self.goldFind += valuePlus;
}
this.goldFind.Decrement = function (valueMinus) {
self.goldFind = self.charObj.goldFind;
self.goldFind -= valueMinus;
}
this.GetFlags = function (string) {
bits = parseInt(string);
return [
bits & 1, bits >>> 1 & 1, bits >>> 2 & 1, bits >>> 3 & 1, bits >>> 4 & 1, bits >>> 5 & 1, bits >>> 6 & 1, bits >>> 7 & 1,
bits >>> 8 & 1, bits >>> 9 & 1, bits >>> 10 & 1, bits >>> 11 & 1, bits >>> 12 & 1, bits >>> 13 & 1, bits >>> 14 & 1, bits >>> 15 & 1, bits >>> 16 & 1
]
}
this.GetItemBuffs = function () {
var flags = self.GetFlags(self.itemObj.GetTag("statBonusFlags").toString()); //[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536]
//self.SerializeTag(self.itemObj);
var buffString = self.itemObj.GetTag("buffList").toString();
Console.Print("buffList [" + buffString + "]\n");
return self.DeserializeTag(buffString);
}
this.SerializeTag = function (myObject) { // for debug quick setting the buffs tag
var buffString = "1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0"
myObject.SetTag("buffList", buffString);
}
this.DeserializeTag = function (tagString) {
if (typeof tagString != "undefined") {
var buffArray = tagString.split(",");
return buffArray
} else {
Console.Print("Magic Item Script - Deserialize passed undefined variable instead of string.\n")
return false;
}
}
this.OneOfUs = function () {
myObj = self.itemObj;
//search for other items with script "5052"
for (i = 0; i != 25; i++) {
mItem = self.charObj.FindItemLayer(i);
if (ValidateObject(mItem) && i != 15 && i != 16 && i != 21) {
l = mItem.scriptTriggers.length;
for (j = 0; j != l; j++) {
if (mItem.scriptTriggers[j] == 5052 && mItem.serial != myObj.serial) {
Console.Print("found one!\n");
return true;
}
}
}
}
return false; //no other items with this script exist in equipment list
}
this.NewLoot = function () {
Console.Print("Running New Loot function.\n");
var flags = 0;
var bitTotals = 0;
var buffList = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var availablePowers = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768];
var availablePotency = [5, 5, 5, 500, 0, 0, 25, 25, 25, 0, 0, 0, 0, 0, 0, 0];
var maxPowers = 5; // Maximum number of powers to apply
var probabilityMultiplier = 1; // Initial probability multiplier
// Generate random values for flags and buffList
for (var i = 0; i < maxPowers; i++) {
var randomIndex = Math.floor(Math.random() * availablePowers.length);
var randomPower = availablePowers.splice(randomIndex, 1)[0];
var randomPotency = Math.round(Math.random() * availablePotency[randomIndex]);
buffList[randomIndex]=randomPotency;
bitTotals += randomPower;
Console.Print(bitTotals.toString() + "\n");
// Reduce the probability for the next power
probabilityMultiplier *= 0.8; // Adjust the diminishing factor as desired
// Adjust the availablePowers array based on the reduced probability
availablePowers = availablePowers.filter(function (power) {
return Math.random() < probabilityMultiplier;
});
}
// Set the flags and buffList
self.itemObj.SetTag("statBonusFlags", bitTotals.toString());
self.itemObj.SetTag("buffList", buffList.join(","));
}
}
// character stuff for when the character processes the buffs after the script is applied to them.
function onSpellCast(pUser, SpellID) { // add faster casting code here
return 500;
}
function onDamage(pAttacked, pAttacker, dValue, dType) {
var myThorns = parseInt(pAttacked.GetTag("thorns").toString()); // thorns
if (ValidateObject(pAttacker)) {
pAttacker.Damage((myThorns > 0 ? ((RandomInt(pAttacked.hidamage - pAttacked.lodamage) + pAttacked.loDamage) * .01) * myThorns : 0), 0, pAttacked, false); //check this math.
}
var mydReflect = parseInt(pAttacked.GetTag("dReflect").toString()); //damage Reflection
if (ValidateObject(pAttacker)) {
pAttacker.Damage((mydReflect > 0 ? (dValue * .01) * myThorns : 0), 0, pAttacked, false);
}
}
function onDeathBlow(pKilled, pKiller) {
return false; //debug immortality.
}
// myChar.SetTimer( timer.SPELLRECOVERYTIME, 500 );
function RandomInt(rvalue) {
//returns random integer with maximum given
return Math.floor(Math.random() * rvalue);
}
function _restorecontext_() { }