PDA

View Full Version : Enchant item, fun function :)


Chompy
01-28-2008, 06:01 PM
function onEnchantItem(singular, prefix, suffix, ench_a, ench_b) {
temp.o_singular = singular;
temp.o_prefix = prefix;
temp.o_suffix = suffix;

temp.a = ench_a;
temp.b = ench_b;

temp.enchants = {"str", "int", "dex", "luck", "hp", "mp", "power", "dmg", "crit", "dodge", "def"};

for(temp.w : enchants) makevar("this.output_" @ w) = "";

temp.c.loadvarsfromarray(a);
temp.d.loadvarsfromarray(b);

temp.arr1 = c.getDynamicVarNames();
temp.arr2 = d.getDynamicVarNames();

temp.arr3 = 0;
for(temp.e : arr1) {
if (arr3.index(@ e) == -1) {
makevar("this.output_" @ e) = makevar("c." @ e) + makevar("d." @ e);
arr3.add(e);
}
}
for(temp.f : arr2) {
if (arr3.index(@ f) == -1) {
makevar("this.output_" @ f) = makevar("c." @ f) + makevar("d." @ f);
arr3.add(f);
}
}
temp.assign = 0;
temp.output_stats = "";
for(temp.o : arr3) {
assign = (this.(@ "output_" @ o).starts("-") ? this.(@ "output_" @ o) : "+" @ this.(@ "output_" @ o)) SPC o @ ", ";
if (o.starts("$")) assign = o.substring(1) @ ", ";
if (!(assign.starts("+0")) && !(assign.starts("-0")))
output_stats @= assign;
}
temp.enchants = output_stats.substring(0, output_stats.length() - 2);
temp.f = "s s s";
if (enchants.length() > 0) f @= " (s)";
output_result = format(f, o_prefix, o_singular, o_suffix, output_stats.substring(0, output_stats.length() - 2));
return output_result.trim();
}

(PS: Replace with percentage symbol, stupid bad request >_<)
Basicly, you give it a itemname, suffix, prefix and data for the suffix and prefix. You don't have to give prefix and/or suffix.

Basic example:


temp.item = "Pirate Shield";
temp.prefix = {"Warrior's", {"str=2", "dex=2", "crit=2"}};
temp.suffix = {"of Strength", {"str=3"}};

temp.enchanteditem = onEnchantItem(item, prefix[0], suffix[0], prefix[1], suffix[1]);

echo(enchanteditem);

Would output:

Warrior's Pirate Shield of Strength (+2 crit, +2 dex, +5 str)


To test out random items :)

function onCreated() {
temp.suffix = {
{"of Strength", {"str=2"}},
{"of Dexterity", {"dex=2"}},
{"of Intelligence", {"int=1", "$Attuned Magic"}},
{"of Luck", {"luck=1", "dex=1", "dodge=1"}},
{"of Love", {"luck=2", "dodge=4", "crit=1"}},
{"of Light", {"$Attuned Light", "int=4"}},
{"of Fire", {"$Attuned Fire", "int=1", "str=1"}},
{"of Darkness", {"$Attuned Dark", "crit=4", "dodge=-1"}},
{"of Water", {"$Attuned Water", "int=4"}},
{"of Ice", {"int=2", "dodge=1", "crit=1"}},
{"of Air", {"dex=2", "dodge=6"}},
{"of Nature", {"$Attuned Earth", "dodge=4"}},
{"of Sound", {"dex=3", "dodge=8", "crit=-1"}},
{"of Pain", {"power=3", "crit=4", "dmg=4"}},
{"of Magic", {"int=5", "$Attuned Magic"}},
{"of Fighting", {"power=4", "crit=4", "str=1"}},
{"of Time", {"dex=7", "power=1"}},
{"of Power", {"power=3", "dmg=10"}}
};
temp.prefix = {
{"Warrior's", {"str=2", "dex=2", "crit=2"}},
{"Spellcaster's", {"int=3", "luck=1", "$Attuned Magic"}},
{"Mountaineer's", {"str=6", "$Attuned Earth"}},
{"Druid's", {"int=5", "str=3", "$Attuned Earth"}},
{"Dragon's", {"str=3", "dex=2", "int=4", "$Attuned Fire"}},
{"Shadow's", {"int=6", "luck=4", "dex=6", "$Attuned Dark"}},
{"Conjurer's", {"int=9", "luck=2"}},
{"Thief's", {"dex=8", "dodge=5", "crit=2"}},
{"Scout's", {"dex=7", "dodge=6", "crit=1"}},
{"Fighter's", {"str=9", "power=4", "dmg=8"}},
{"Soldier's", {"str=6", "int=1", "dmg=9"}},
{"Crusader's", {"str=11", "dmg=19", "crit=3", "dodge=-1"}},
{"Warlock's", {"int=11", "luck=4", "$Attuned Dark"}},
{"Joker's", {"dodge=11", "crit=1"}},
{"Archer's", {"dex=12", "luck=4"}},
{"Berserker's", {"str=10", "power=7", "crit=5", "dodge=-4"}},
{"Defender's", {"def=20", "dodge=5", "crit=1"}},
{"Fool's", {"dodge=10", "luck=-5"}},
{"Gladiator's", {"power=6", "crit=6", "dodge=-5"}},
{"Cleric's", {"dodge=4", "luck=8"}},
{"Behemoth's", {"def=42", "crit=2", "dodge=-1"}},
{"Beast's", {"str=14", "crit=3", "dodge=-7"}},
{"Captains'", {"int=4", "dex=9", "dodge=7", "crit=-2"}},
{"Knight's", {"str=9", "int=4", "crit=6", "dodge=-3"}},
{"Monk's", {"int=9", "crit=1", "dodge=-1", "$Attuned Light"}},
{"Masters'", {"str=12", "dex=11", "dodge=17", "crit=-2", "dmg=15"}},
{"Pirate's", {"str=-4", "dex=16", "dodge=13", "crit=1"}},
{"Rogue's", {"dex=10", "dodge=11", "crit=-1"}},
{"Sage's", {"int=15", "luck=2", "crit=-1"}},
{"Priest's", {"int=11", "crit=3", "$Attuned Light"}},
{"Necromancer's", {"int=9", "crit=1", "dodge=2", "luck=3", "$Attuned Fire"}},
{"Valkyrie's", {"int=9", "luck=-5", "crit=9", "dodge=2"}},
{"Summoner's", {"int=10", "crit=3", "dodge=1", "$Attuned Magic"}},
{"Shaman's", {"int=6", "str=3", "dodge=3"}},
{"Witch's", {"int=9", "luck=-1", "dodge=2", "$Attuned Dark"}},
{"Newcomer's", {"str=1", "crit=1"}},
{"Adventurer's", {"dex=15", "luck=5", "dodge=21", "crit=5"}},
{"Forester's", {"$Attuned Earth", "dodge=11", "int=2"}}

};
temp.items = {
"Wooden Sword",
"Inferno Blade",
"Cursed Blade",
"Iron Plate",
"Blaze Helmet",
"Fenix Sword",
"Zhar Blade",
"Blaze Wand",
"Flare Blade",
"Rusted Iron Sword",
"Pirate Shield",
"Spider Fang",
"Zitter"
};

temp.randomnumber = int(random(0, items.size() - 1));
temp.randomitem = items[randomnumber][0];

temp.randomnumber = int(random(0, prefix.size() - 1));
temp.randomprefix = {prefix[randomnumber][0], prefix[randomnumber][1]};

temp.randomnumber = int(random(0, suffix.size() - 1));
temp.randomsuffix = {suffix[randomnumber][0], suffix[randomnumber][1]};

echo(onEnchantItem(randomitem, randomprefix[0], randomsuffix[0], randomprefix[1], randomsuffix[1]));
}

Some outputs:

Pirate's Flare Blade of Darkness (+5 crit, +16 dex, +12 dodge, -4 str, Attuned Dark)
Rogue's Spider Fang of Nature (-1 crit, +10 dex, +15 dodge, Attuned Earth)
Scout's Spider Fang of Ice (+2 crit, +7 dex, +7 dodge, +2 int)
Mountaineer's Fenix Sword of Sound (Attuned Earth, +6 str, -1 crit, +3 dex, +8 dodge)
Joker's Blaze Helmet of Air (+1 crit, +17 dodge, +2 dex)
Scout's Cursed Blade of Dexterity (+1 crit, +9 dex, +6 dodge)
Beast's Wooden Sword of Water (+3 crit, -7 dodge, +14 str, Attuned Water, +4 int)
Warlock's Zhar Blade of Luck (Attuned Dark, +11 int, +5 luck, +1 dex, +1 dodge)
Cleric's Rusted Iron Sword of Dexterity (+4 dodge, +8 luck, +2 dex)


How it works:

Define all enchants that it will plus/minus together in 'temp.enchants' in the onEnchantItem() function. It also supports, 'text based enchants'. For example in some of the outputs above you see "Attuned Water" or "Attuned Dark". There vars are added to the () if in the function params (2 last params) the vars to be added contains $ as prefix, for example:


temp.item = "Gravitron Mace";
temp.suffix = {"of Reality", {"str=-11", "dex=-5", "crit=12"}};
temp.prefix = {"Halo's", {"int=27", "dex=8", "$Effect: Gravity"}};

temp.enchanteditem = onEnchantItem(item, prefix[0], suffix[0], prefix[1], suffix[1]);

echo(enchanteditem);

Would output:

Halo's Gravitron Mace of Reality (Effect: Gravity, +3 dex, +27 int, +12 crit, -11 str)


Enjoy..? ^^

Tigairius
01-28-2008, 06:17 PM
Very nice!! :)

Dan
01-28-2008, 10:33 PM
Cool yeah! :)

Switch
01-28-2008, 10:47 PM
Ayesome :o
That's a like the GK one, hmm?
Would be cool to see it with another dmg/wep system.

Inverness
01-28-2008, 11:43 PM
Thats hot.

Knightmare1
01-28-2008, 11:44 PM
wow. talk about skill.

EDIT
about this part:
function onEnchantItem(singular, prefix, suffix, ench_a, ench_b) {
temp.o_singular = singular;
temp.o_prefix = prefix;
temp.o_suffix = suffix;

temp.a = ench_a;
temp.b = ench_b;

temp.enchants = {"str", "int", "dex", "luck", "hp", "mp", "power", "dmg", "crit", "dodge", "def"};

for(temp.w : enchants) makevar("this.outut_" @ w) = "";

temp.c.loadvarsfromarray(a);
temp.d.loadvarsfromarray(b);

temp.arr1 = c.getDynamicVarNames();
temp.arr2 = d.getDynamicVarNames();

temp.arr3 = 0;
for(temp.e : arr1) {
if (arr3.index(@ e) == -1) {
makevar("this.output_" @ e) = makevar("c." @ e) + makevar("d." @ e);
arr3.add(e);
}
}
for(temp.f : arr2) {
if (arr3.index(@ f) == -1) {
makevar("this.output_" @ f) = makevar("c." @ f) + makevar("d." @ f);
arr3.add(f);
}
}
temp.assign = 0;
temp.output_stats = "";
for(temp.o : arr3) {
assign = (this.(@ "output_" @ o).starts("-") ? this.(@ "output_" @ o) : "+" @ this.(@ "output_" @ o)) SPC o @ ", ";
if (o.starts("$")) assign = o.substring(1) @ ", ";
if (!(assign.starts("+0")) && !(assign.starts("-0")))
output_stats @= assign;
}
temp.enchants = output_stats.substring(0, output_stats.length() - 2);
temp.f = "s s s";
if (enchants.length() > 0) f @= " (s)";
output_result = format(f, o_prefix, o_singular, o_suffix, output_stats.substring(0, output_stats.length() - 2));
return output_result.trim();
}
i noticed somthing, is this:
for(temp.w : enchants) makevar("this.outut_" @ w) = ""; supposed to be this
for(temp.w : enchants) makevar("this.output_" @ w) = "";

Chompy
01-28-2008, 11:50 PM
wow. talk about skill.

EDIT
about this part:
...
i noticed somthing, is this:
for(temp.w : enchants) makevar("this.outut_" @ w) = ""; supposed to be this
for(temp.w : enchants) makevar("this.output_" @ w) = "";

Err, yeah you're right, typo xD

Knightmare1
01-28-2008, 11:55 PM
Err, yeah you're right, typo xD
:D

cbk1994
01-29-2008, 12:03 AM
Very nice, would be cool to see this added to your mudlib system on Symphonia (you work there, yes?)

Chompy
01-29-2008, 12:08 AM
Very nice, would be cool to see this added to your mudlib system on Symphonia (you work there, yes?)

Yeah, I'm gonna make a new one tho, a little more complicated/different one so it will fit my mudlib (This atm is only visual (the name of the item))

But yeah, I'll add something like this to Symp :)

Chompy
06-12-2008, 01:09 AM
Little update..
This one is more based on objects instead of text based ;o

Put this in a class:

function onCreated() {
this.filepath = "files/templates/";
// Filepath used when type of parsing is 2

this.at = {
"fullname", "description"
};
/* All variables in the 'at' array can be attached to existing text or
made equal something else. Also supports format (%s)
var = @text --> var @= " "@ text
var = "Lion's %s of Strength" -- > var = format("Lion's %s of Strength", var) */

this.as = {
"icon", "image", "script", "params", "clientscript"
};
/* All vars is 'this.as' can only be overwritten with an other value
var = val */

this.pm = {
"strength", "intelligence", "dexterity", "wisdom",
"luck", "attackspeed", "armor"
};
/* These variables have support for 'plus_', 'minus_' prefixes
var = plus_5 --> var += 5
var = minus_5 --> var -= 5 */

this.bl = {
"equipable", "unique"
};
/* These are booleans, can only set these to 0 or 1 (false or true) */

// For more info, check out the examples
}

public function parseobject(c, cad) {
// c = type (1 = loadvarsfromarray, 2 = loadvarsfromfile)
// cad = what to load (1 = array with vars, 2 = filename)

temp.cd = 0;

if (c == 2) cd.loadlines(this.filepath @ cad);
else cd = cad;

temp.vars.loadvarsfromarray(cd);
for(temp.cvar : vars.getdynamicvarnames()) {
if (cvar in this.at) {
temp.value = vars.(@cvar);
if (value.starts("@")) {
this.(@cvar) @= " "@ value.substring(1);

}else if (value.pos("%s") > -1) {
this.(@cvar) = format(value, this.(@cvar));

}else{
this.(@cvar) = value;
}

}else if (cvar in this.as) {
this.(@cvar) = vars.(@cvar);

}else if (cvar in this.pm) {
temp.value = vars.(@cvar);
if (value.starts("plus_")) {
this.(@cvar) += int(float(value.substring(5)));

}else if (value.starts("minus_")) {
if ((this.(@cvar)-int(float(value.substring(6)))) < 1) {
this.(@cvar) = 0;

}else{
this.(@cvar) -= int(float(value.substring(6)));
}

}else{
this.(@cvar) = int(float(value));
}

}else if (cvar in this.bl) {
if (vars.(@cvar) in <0,1>) { // true = 1, false = 0
this.(@cvar) = vars.(@cvar);
}
}
}
}



And here's an example of usage:


function onCreated() {
this.item = new TStaticVar("WoodenSword");
this.item.strength = 4;
this.item.dexterity = 3;
this.item.value = 45;
this.item.equipable = 1;
this.item.unique = 0;
this.item.script = "";
this.item.params = "";
this.item.clientscript = "";
this.item.fullname = "Wooden Sword";
this.item.description = "A sword made out of wood.";
this.item.join("test_parse"); // The class that you put the function in

temp.enchant = {
"fullname=Broken %s",
"equipable=0",
"value=minus_20",
"[email protected] item is broken."
};

this.item.parseobject(1, enchant);

echo(this.item.fullname); // 'Broken Wooden Sword'
}



Suggestions and ideas on how to improve are welcome :-)