Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-28-2008, 06:01 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Enchant item, fun function :)

Graal Script Code:
function onEnchantItem(singularprefixsuffixench_aench_b) {   
  
temp.o_singular singular;
  
temp.o_prefix prefix;
  
temp.o_suffix suffix;

  
temp.ench_a;
  
temp.ench_b;
  
  
temp.enchants = {"str""int""dex""luck""hp""mp""power""dmg""crit""dodge""def"};
  
  for(
temp.enchantsmakevar("this.output_" w) = "";
  
  
temp.c.loadvarsfromarray(a);  
  
temp.d.loadvarsfromarray(b);
  
  
temp.arr1 c.getDynamicVarNames();
  
temp.arr2 d.getDynamicVarNames();
  
  
temp.arr3 0;
  for(
temp.arr1) {
    if (
arr3.index(@ e) == -1) {
      
makevar("this.output_" e) = makevar("c." e) + makevar("d." e);
      
arr3.add(e);
    }
  }
  for(
temp.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.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(0output_stats.length() - 2);
  
temp."žs žs žs";
  if (
enchants.length() > 0@= " (žs)";
  
output_result format(fo_prefixo_singularo_suffixoutput_stats.substring(0output_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:

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

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

echo(
enchanteditem); 
Would output:
NPC Code:

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



To test out random items
Graal Script Code:
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(0items.size() - 1));
  
temp.randomitem items[randomnumber][0];
  
  
temp.randomnumber int(random(0prefix.size() - 1));
  
temp.randomprefix = {prefix[randomnumber][0], prefix[randomnumber][1]};
  
  
temp.randomnumber int(random(0suffix.size() - 1));
  
temp.randomsuffix = {suffix[randomnumber][0], suffix[randomnumber][1]};
  
  echo(
onEnchantItem(randomitemrandomprefix[0], randomsuffix[0], randomprefix[1], randomsuffix[1]));

Some outputs:
NPC Code:

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:

Graal Script Code:
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(itemprefix[0], suffix[0], prefix[1], suffix[1]);

echo(
enchanteditem); 
Would output:
NPC Code:

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



Enjoy..?
__________________

Last edited by Chompy; 01-28-2008 at 11:50 PM..
Reply With Quote
  #2  
Old 01-28-2008, 06:17 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Very nice!!
__________________


ôShoot for the moon. Even if you miss, you'll land among the stars.ö
Reply With Quote
  #3  
Old 01-28-2008, 10:33 PM
Dan Dan is offline
Daniel
Join Date: Oct 2007
Posts: 383
Dan is an unknown quantity at this point
Send a message via MSN to Dan
Cool yeah!
__________________
Reply With Quote
  #4  
Old 01-28-2008, 10:47 PM
Switch Switch is offline
o.o
Switch's Avatar
Join Date: Jan 2007
Location: Philadelphia
Posts: 3,038
Switch has a spectacular aura about
Send a message via MSN to Switch
Ayesome :o
That's a like the GK one, hmm?
Would be cool to see it with another dmg/wep system.
__________________
Oh squiggly line in my eye fluid. I see you lurking there on the peripheral of my vision.
But when I try to look at you, you scurry away.
Are you shy, squiggly line?
Why only when I ignore you, do you return to the center of my eye?
Oh, squiggly line, it's alright, you are forgiven.
Reply With Quote
  #5  
Old 01-28-2008, 11:43 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Thats hot.
__________________
Reply With Quote
  #6  
Old 01-28-2008, 11:44 PM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
wow. talk about skill.

EDIT
about this part:
Graal Script Code:
function onEnchantItem(singularprefixsuffixench_aench_b) {   
  
temp.o_singular singular;
  
temp.o_prefix prefix;
  
temp.o_suffix suffix;

  
temp.ench_a;
  
temp.ench_b;
  
  
temp.enchants = {"str""int""dex""luck""hp""mp""power""dmg""crit""dodge""def"};
  
  for(
temp.enchantsmakevar("this.outut_" w) = "";
  
  
temp.c.loadvarsfromarray(a);  
  
temp.d.loadvarsfromarray(b);
  
  
temp.arr1 c.getDynamicVarNames();
  
temp.arr2 d.getDynamicVarNames();
  
  
temp.arr3 0;
  for(
temp.arr1) {
    if (
arr3.index(@ e) == -1) {
      
makevar("this.output_" e) = makevar("c." e) + makevar("d." e);
      
arr3.add(e);
    }
  }
  for(
temp.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.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(0output_stats.length() - 2);
  
temp."žs žs žs";
  if (
enchants.length() > 0@= " (žs)";
  
output_result format(fo_prefixo_singularo_suffixoutput_stats.substring(0output_stats.length() - 2));
  return 
output_result.trim();

i noticed somthing, is this:
Graal Script Code:
  for(temp.enchantsmakevar("this.outut_" w) = ""
supposed to be this
Graal Script Code:
  for(temp.enchantsmakevar("this.output_" w) = ""
__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #7  
Old 01-28-2008, 11:50 PM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Knightmare1 View Post
wow. talk about skill.

EDIT
about this part:
Graal Script Code:
... 
i noticed somthing, is this:
Graal Script Code:
  for(temp.enchantsmakevar("this.outut_" w) = ""
supposed to be this
Graal Script Code:
  for(temp.enchantsmakevar("this.output_" w) = ""
Err, yeah you're right, typo xD
__________________
Reply With Quote
  #8  
Old 01-28-2008, 11:55 PM
Knightmare1 Knightmare1 is offline
Billy Allan
Knightmare1's Avatar
Join Date: Apr 2007
Posts: 804
Knightmare1 can only hope to improve
Quote:
Originally Posted by Chompy View Post
Err, yeah you're right, typo xD
__________________
I am the devil, I am here to do to devils work.
Reply With Quote
  #9  
Old 01-29-2008, 12:03 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Very nice, would be cool to see this added to your mudlib system on Symphonia (you work there, yes?)
__________________
Reply With Quote
  #10  
Old 01-29-2008, 12:08 AM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
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
__________________
Reply With Quote
  #11  
Old 06-12-2008, 01:09 AM
Chompy Chompy is offline
»\(║_o)/»
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Little update..
This one is more based on objects instead of text based ;o

Put this in a class:
Graal Script Code:
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(ccad) {
  
// c = type (1 = loadvarsfromarray, 2 = loadvarsfromfile)
  // cad = what to load (1 = array with vars, 2 = filename)
  
  
temp.cd 0;
  
  if (
== 2cd.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(valuethis.(@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.(@cvarin <0,1>) { // true = 1, false = 0
        
this.(@cvar) = vars.(@cvar);
      }
    }
  }


And here's an example of usage:

Graal Script Code:
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(1enchant);
  
  echo(
this.item.fullname); // 'Broken Wooden Sword'


Suggestions and ideas on how to improve are welcome :-)
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:14 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.