Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 49.95 KB | None | 0 0
  1.         ¤ pokemon ¤
  2.  
  3. #pokemon on
  4. on *:start:{ start_pokedb }
  5. on *:exit:{ close_pokedb }
  6. alias start_pokedb {  
  7.   set %poke.db $sqlite_open(txt/pokemon/pokemon.db3)
  8.   hmake pokemon
  9. }
  10. alias close_pokedb {
  11.   sqlite_close %poke.db
  12.   unset %poke.db
  13.   hfree pokemon
  14. }
  15. alias sql_esc { return $replace($1-,$chr(32),_32,$chr(39),_39,$chr(40),_40,$chr(41),_41,$chr(44),_44,$chr(45),_45,$chr(46),_46,$chr(91),_91,$chr(93),_93,$chr(94),_94,$chr(96),_96,$chr(124),_124) }
  16. alias sql_re { return $regsubex($1-,/(_(\d{2}))/g,$chr( \2 )) }
  17. on *:text:!catch:#:{
  18.   if (%poke.db) {
  19.     var %a = $p_active($.nick), %status = $p_status($.nick)
  20.     if (%status == none) {
  21.       .notice $nick You don't have any pokemon yet, Please choose from the following by typing !choose <pokemon>
  22.       .notice $nick Bulbasaur, Charmander, Squirtle, Pidgey, Weedle, Pichu, Machop, Abra, Geodude, Staryu, Chikorita, Cyndaquil, Totodile
  23.       if (!$.nick($nick).check) { .notice $nick NOTE: You either aren't logged in or you don't have mode +x set. If you change your name it wont know who you are. Do not create a second account if you change nicks. }
  24.     }
  25.     elseif ($hget(pokemon,$.nick)) { .notice $nick All the pokemon ran away, Try again later. ( $+ $v1 sec $+ ) }
  26.     elseif (%status == learn) { .notice $nick %a has too many moves! $+([,$p_mark($.nick),]) Type !forget <move> }
  27.     elseif (%status == replace) { .notice $nick You need to choose which pokemon to keep, but i havent wrote a message for this yet, scroll up and see what you need to do }
  28.     elseif (%status == ready) {
  29.       hadd -z pokemon $.nick $iif($istok(%punish,$.nick,44),150,$iif($p_item($.nick,Bicycle),45,60))
  30.       p_ps $.nick attempts
  31.       var %x = $rand(0,100000) % 100, %q = $dupe($p_get(20)), %p = $gettok(%q,1,44), %lvl = $p_stat($.nick,%a).lvl, %loc = $p_loc($.nick).num
  32.       if ($rand(1,100) <= $p_noncom(%loc)) {
  33.         var %tf = txt/pokemon/ $+ $ticks , %cadv, %a
  34.         filter -ffg txt/pokemon/noncom.txt %tf /\x09(%loc|\*)\x09/
  35.         while (!%cadv) {
  36.           %a = $read(%tf)
  37.           if (!$gettok(%a,3,9)) || ($rand(1,100) > $gettok(%a,3,9)) { %cadv = $gettok(%a,1,9) }
  38.         }
  39.         choiceadv %cadv
  40.         .remove %tf
  41.       }
  42.       else {
  43.         :redo
  44.         var %n = 1, %a, %c, %u, %r, %y = $rand(1,100), %catch, %npc, %npcvs, %vs, %cash
  45.         while (%n <= $numtok(%q,44)) {
  46.           %a = $regsubex($gettok(%q,%n,44),/(^\x20)/,)
  47.           if ($read(txt/pokemon/rare.txt,r,/\x09( $regescape(%a) )$/xi)) { %r = $addtok(%r,%a,44) }
  48.           if ($has_pokemon($.nick,%a) == has) { %c = $addtok(%c,%a,44) }
  49.           else { %u = $addtok(%u,%a,44) }
  50.           inc %n
  51.         }
  52.         %n = $calc(100 / ($numtok(%q,44) / $numtok(%u,44)))
  53.         if (%x == 0) {
  54.           %p = $p_rare
  55.           if (%r) && ($istok(%r,%p,44)) {
  56.             if ($istok(%u,%p,44)) { %catch = 1 }
  57.           }
  58.           else {
  59.             msg $chan $nick $+ : You see a rare %p in the distance, but it's gone before you can get to it.
  60.             see_pokemon $.nick %p
  61.             return
  62.           }
  63.         }
  64.         elseif (%n) && (%y <= %n) {
  65.           %p = $.rand(%u)
  66.           while ($istok(%r,%p,44)) {
  67.             %u = $remtok(%u,%p,1,44)
  68.             %p = $.rand(%u)
  69.           }
  70.           if (%p) { %catch = 1 }
  71.           else { var %p = $.rand(%c), %catch = 1 }
  72.         }
  73.         else { var %p = $.rand(%c), %catch = 1  }
  74.         if (!%p) {
  75.           msg $chan Error: no pokemon selected, sorry.
  76.           return
  77.         }
  78.         if ($p_uncom(%p)) {
  79.           if ($rand(1,10) < 7) {
  80.             %x = 1
  81.             %q = $dupe($p_get(20))
  82.             goto redo
  83.           }
  84.         }
  85.         var %min = $bottom($floor($calc(%lvl * .85 - 1)),1), %max = $ceil($calc(%lvl * 1.20 + 1)), %lvl = $bottom($cap($rand(%min,%max),$iif($p_el(%p),$calc($p_el(%p) - 1),99)),$p_ml(%p))
  86.         var %npc = $p_npc(%p,%lvl), %pv = $gettok(%npc,2,9)
  87.         %npcvs = $pokemon($gettok(%npc,1,9)).type $+ $chr(9) $+ $gettok(%npc,12-17,9)
  88.         %vs = $p_vs($p_stat($.nick,$p_active($.nick)).vs,%npcvs)
  89.         %cash = $ceil($calc(%lvl ^ 1.7 + (%lvl + $rand(1,%lvl) - $rand(1,%lvl)) * 1.5 + (%lvl * 2)))
  90.         if (%vs == 1) {
  91.           var %cr = $calc($p_cr(%p) * $p_bmod($p_cug($.nick).ball)), %crp = $calc(100 - (100 / (256 / %cr) + $rand($calc(10 - (%cr ^ .7 ^ .5)),50) - $rand($sqrt(%cr),50))), %crr = $rand(1,100)
  92.           echo -s $.nick %p Natural catch rate: %cr - After calc: %crp - Roll: %crr
  93.           if (%crr < %crp) { var %catch = 0 }
  94.           if (%catch) && ($p_item($.nick,Pokeball) > 0) {
  95.             p_item $.nick Pokeball -1
  96.             msg $chan $nick $+ : You encounter a $iif($p_rare(%p),rare,wild) $p_shiny($.nick,%pv) %p ( $+ %lvl $+ ) - After a long battle you are the victor. You just caught %p $+ ! (+$ $+ %cash cash)
  97.             if ($p_item($.nick,Pokeball) == 0) { .notice $nick You just used your last pokeball! You need to buy more or you wont be able to catch any more pokemon. }
  98.             add_pokemon $.nick %npc
  99.             p_item $.nick Cash + $+ %cash
  100.           }
  101.           else {
  102.             msg $chan $nick $+ : You encounter a $iif($p_rare(%p),rare,wild) $p_shiny($.nick,%pv) %p ( $+ %lvl $+ ) - After a long battle you are the victor. $iif($p_item($.nick,Pokeball) < 1,You realize you are out of pokeballs so you can't catch %p $+ !) (+$ $+ %cash cash)
  103.             p_item $.nick Cash + $+ %cash
  104.             if ($p_item($.nick,Pokeball) > 0) {
  105.               if (!$has_pokemon($.nick,%p)) || ($has_pokemon($.nick,%p) == seen) {
  106.                 if (%catch) { p_item $.nick Pokeball -1 }
  107.               }
  108.               if ($p_item($.nick,Pokeball) == 0) { .notice $nick You just used your last pokeball! You need to buy more or you wont be able to catch any more pokemon. }
  109.             }
  110.             noop $p_+exp(%p,%lvl)
  111.           }
  112.         }
  113.         else {
  114.           msg $chan $nick $+ : You encounter a $iif($p_rare(%p),rare,wild) $p_shiny($.nick,%pv) %p ( $+ %lvl $+ ) - He was too strong for you, You lose.
  115.           see_pokemon $.nick %p
  116.         }
  117.       }
  118.     }
  119.   }
  120. }
  121. alias choiceadv {
  122.   var %x, %q = $dupe($p_get(20)), %p = $gettok(%q,1,44), %lvl = $p_stat($.nick,$p_active($.nick)).lvl, %loc = $p_loc($.nick).num
  123.   if ($1 == 1) { msg $chan $nick $+ : You wander around, but don't really find anything of interest. }
  124.   if ($1 == 2) {
  125.     %x = $ceil($calc($rand(5,10) * $rand(10,50) * (%lvl ^ .4)))
  126.     msg $chan $nick $+ : You get sidetracked while looking for pokemon, but you find some buried treasure, score! (+$ $+ %x cash)
  127.     p_item $.nick cash + $+ %x
  128.   }
  129.   if ($1 == 3) {
  130.     %x = $rand(1,10) $iif($rand(1,10) > 8, * 2)
  131.     msg $chan $nick $+ : You don't have any luck looking for pokemon, but you stumble across a stash of $p_cug($.nick).ball $+ 's! (+ $+ %x $p_cug($.nick).ball $+ 's!)
  132.     p_item $.nick pokeball + $+ %x
  133.   }
  134.   if ($1 == 4) {
  135.     %x = $rand(1,25)
  136.     if (%x == 25) {
  137.       msg $chan $nick $+ : You chase after %p but it gets away, but you spot some Rare candy, sweet! (+1 Rare candy)
  138.       p_item $.nick $sql_esc(Rare candy)
  139.       see_pokemon $.nick %p
  140.     }
  141.     elseif (%x == 1) {
  142.       msg $chan $nick $+ : You chase after %p but trip. You look back to see what it was and realize you tripped over a Gold nugget! (+1 Gold nugget)
  143.       p_item $.nick $sql_esc(Gold nugget)
  144.       see_pokemon $.nick %p
  145.     }
  146.     else {
  147.       var %x = $rand(1,100), %t = $iif(%x <= 25,battle,hold), %x = $p_getitem(%t), %n = 1, %i = $p_item($.nick,%x)
  148.       if (%t == hold) {
  149.         while ($rand(1,100) < $calc(%i * 20)) && (%n <= 10) {
  150.           var %x = $p_getitem(%t)
  151.           var %i = $p_item($.nick,%x)
  152.           inc %n
  153.         }
  154.       }
  155.       if (*potion* iswm %x) { %x = $p_cug($.nick).potion }
  156.       msg $chan $nick $+ : You start battling with %p $+ . It gets away, but it drops a %x $+ . (+1 %x $+ )
  157.       p_item $.nick $sql_esc(%x)
  158.       see_pokemon $.nick %p
  159.     }
  160.   }
  161.   if ($1 == 5) {
  162.     var %i1 = $p_getitem(hold), %i2 = $p_getitem(hold), %i3 = $p_getitem(hold)
  163.     msg $chan $nick $+ : You find a stash of sweet loot! (+1 %i1 $+ , %i2 $+ , %i3 $+ )
  164.     p_item $.nick $sql_esc(%i1)
  165.     p_item $.nick $sql_esc(%i2)
  166.     p_item $.nick $sql_esc(%i3)
  167.   }
  168.   if ($1 == 6) {
  169.     msg $chan $nick $+ : %p spots you and attacks! You just got ownd, you need some time to rest before you can go out again.
  170.     hadd -z pokemon $.nick 180
  171.     see_pokemon $.nick %p
  172.   }
  173. }
  174. on $1000:text:$(/^( $p_mark($.nick) )$/xi):#:{
  175.   if ($p_status($.nick) == choiceadv) {
  176.  
  177.   }
  178. }
  179. on *:text:!choose*:#:{
  180.   var %a = $p_active($.nick), %p = $pokemon($2-).name, %status = $p_status($.nick)
  181.   if (!%p) { .notice $nick Unrecognized pokemon }
  182.   elseif ($2) {
  183.     if (%status == none) {
  184.       if ($istok(Bulbasaur Charmander Squirtle Pidgey Weedle Pichu Machop Abra Geodude Staryu Chikorita Cyndaquil Totodile Absol,%p,32)) {
  185.         sqlite_begin %poke.db
  186.         sqlite_exec %poke.db INSERT INTO p_inventory VALUES (' $+ $sql_esc($.nick) $+ ', 500, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
  187.         sqlite_exec %poke.db INSERT INTO p_badges (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  188.         sqlite_exec %poke.db INSERT INTO p_pokemon (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  189.         sqlite_exec %poke.db INSERT INTO p_players VALUES (' $+ $sql_esc($.nick) $+ ', $rand(1,65535) , $rand(1,65535) , ' $+ 3 3 $+ ', ' $+ %p $+ ', ' $+ ready $+ ', 0, 0, 0, '')
  190.         sqlite_exec %poke.db CREATE TABLE $sql_esc($.nick) (pokemon varchar(20), pv varchar(10), ability varchar(20), nature varchar(10), traded varchar(1), item varchar(20), m1 varchar(20), m2 varchar(20), m3 varchar(20), m4 varchar(20), lvl varchar(3), exp varchar(10), hp varchar(4), atk varchar(4), def varchar(4), spatk varchar(4), spdef varchar(4), spd varchar(4), ivhp varchar(2), ivatk varchar(2), ivdef varchar(2), ivspatk varchar(2), ivspdef varchar(2), ivspd varchar(2), evhp varchar(3), evatk varchar(3), evdef varchar(3), evspatk varchar(3), evspdef varchar(3), evspd varchar(3))
  191.         sqlite_commit %poke.db
  192.         add_pokemon $.nick $p_npc(%p,1)
  193.         hadd -z pokemon $+($.nick,.travel) 900
  194.         .notice $nick Congrats! You are now a pokemon trainer. %p is now your active pokemon. As you catch more you can change them out with !choose
  195.       }
  196.       else { .notice $nick That isn't a valid option. }
  197.     }
  198.     elseif (%status == ready) {
  199.       if (%a == %p) { .notice $nick %p is already your active pokemon! }
  200.       elseif ($has_pokemon($.nick,%p) == has) {
  201.         if ($p_stat($.nick,%p).lvl >= $p_loc($.nick).lvl) {
  202.           .notice $nick %p is now your active pokemon.
  203.           p_active $.nick %p
  204.         }
  205.         else { .notice $nick %p is too weak to be out here. }
  206.       }
  207.       else { .notice $nick You don't have a %p }
  208.     }
  209.   }
  210. }
  211. on *:text:!give *:#:{
  212.   if ($p_status($.nick) == ready) {
  213.     var %p = $pokemon($iif($5,$2 $3,$2)).name, %i = $p_item($iif($5,$4-,$3-)).name
  214.     if (!%i) { .notice $nick That isn't an item! }
  215.     elseif ($p_item(%i).type != hold) { .notice $nick You can't give that to him! }
  216.     elseif (!%p) { .notice $nick I think you misspelled the pokemon name, or have the name and item in the wrong order. }
  217.     else {
  218.       if ($has_pokemon($.nick,%p) == has) {
  219.         if ($p_item($.nick,%i)) {
  220.           set -l %sql SELECT item FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  221.           set -l %query $sqlite_query(%poke.db,%sql)
  222.           set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  223.           sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET item=' $+ $sql_esc(%i) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  224.           p_item $.nick $sql_esc(%i) -1
  225.           if ($hget(pitem,item)) {
  226.             var %new = $v1
  227.             .notice $nick You exchange %p $+ 's $sql_re(%new) for your %i
  228.             p_item $.nick $sql_esc(%new)
  229.           }
  230.           else { .notice $nick You give the %i to %p }
  231.         }
  232.         else { .notice $nick You don't have a %i }
  233.       }
  234.       else { .notice $nick You don't have a %p }
  235.     }
  236.     sqlite_free %query
  237.   }
  238. }
  239. on $*:text:/^!travel\s(north|south|east|west)/i:#:{
  240.   if ($p_status($.nick) == ready) {
  241.     if ($hget(pokemon,$+($.nick,.travel))) { .notice $nick You cant travel yet, You need to wait $duration($v1) }
  242.     else {
  243.       tokenize 32 $($+($!p_loc($.nick),.,$2),2)
  244.       if ($p_loc($1,$2)) && ($p_loc($.nick) != $1 $2) {
  245.         if ($p_stat($.nick,$p_active($.nick)).lvl >= $p_loc($1,$2).lvl) {
  246.           hadd -z pokemon $+($.nick,.,travel) $iif($p_item($.nick,bicycle),600,900)
  247.           p_loc $.nick $1 $2
  248.           .notice $nick You travel to $p_loc($.nick).name
  249.         }
  250.         else { .notice $nick You should wait until you are stronger before going to $p_loc($1,$2).name ( $+ $p_loc($1,$2).lvl $+ ) }
  251.       }
  252.       else { .notice $nick You cant travel there! }
  253.     }
  254.   }
  255. }
  256. on $*:text:/^!(location|map)/:#:{
  257.   if ($p_status($.nick) == ready) { .notice $nick $p_loc($.nick).map }
  258. }
  259. alias p_loc {
  260.   if ($isid) {
  261.     if ($1 !isnum) {
  262.       set -l %sql SELECT loc FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  263.       set -l %query $sqlite_query(%poke.db,%sql)
  264.       set -l %fetch $sqlite_fetch_row(%query,loc,$SQLITE_ASSOC)
  265.       sqlite_free %query
  266.       tokenize 32 $hget(loc,loc)
  267.       if ($hget(loc)) { hfree loc }
  268.     }
  269.     var %x = $iif(!$2,$1,$gettok($p_ini(loc,$1),$2,44)), %n = $iif($1 > 1,$gettok($p_ini(loc,$calc($1 - 1)),$2,44),0), %e = $iif($2 < 5,$gettok($p_ini(loc,$1),$calc($2 + 1),44),0), %s = $iif($1 < 5,$gettok($p_ini(loc,$calc($1 + 1)),$2,44),0), %w = $iif($2 > 1,$gettok($p_ini(loc,$1),$calc($2 - 1),44),0)
  270.     if (%x == 0) || (!%x) { return 0 }
  271.     if ($prop == name) { return $p_ini(area,%x) }
  272.     if ($prop == num) { return %x }
  273.     if ($prop == map) { return [Current Location: $p_ini(area,%x) $+ ] $iif(%n,[North: $p_ini(area,%n) $+ ]) $iif(%e,[East: $p_ini(area,%e) $+ ]) $iif(%s,[South: $p_ini(area,%s) $+ ]) $iif(%w,[West: $p_ini(area,%w) $+ ])  }
  274.     if ($prop == lvl) { return $p_ini(level,%x) }
  275.     if ($prop == north) && (%n) { return $calc($1 - 1) $2 }
  276.     if ($prop == east) && (%e) { return $1 $calc($2 + 1) }
  277.     if ($prop == south) && (%s) { return $calc($1 + 1) $2 }
  278.     if ($prop == west) && (%w) { return $1 $calc($2 - 1) }
  279.     return $1-
  280.   }
  281.   sqlite_exec %poke.db UPDATE p_players SET loc=' $+ $2- $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  282. }
  283. alias pokemon {
  284.   if (!$1) {
  285.     if ($prop) { return }
  286.     return $gettok($read(txt/pokemon/pokemon.txt),2,9)
  287.   }
  288.   var %x = $read(txt/pokemon/pokemon.txt,r,/^\d{3}\x09[^\x09]* $replace($sql_re($1-),$chr(32),\s,$chr(40),.,$chr(41),.) .*\x09/ix)
  289.   if ($prop == num) { return $gettok(%x,1,9) }
  290.   if ($prop == name) { return $gettok(%x,2,9) }
  291.   if ($prop == type) { return $gettok(%x,3,9) }
  292.   if ($prop == hp) { return $gettok(%x,4,9) }
  293.   if ($prop == atk) { return $gettok(%x,5,9) }
  294.   if ($prop == def) { return $gettok(%x,6,9) }
  295.   if ($prop == satk) { return $gettok(%x,7,9) }
  296.   if ($prop == sdef) { return $gettok(%x,8,9) }
  297.   if ($prop == spd) { return $gettok(%x,9,9) }
  298.   if ($prop == total) { return $gettok(%x,10,9) }
  299.   if ($prop == fmt) { return ( $+ $gettok(%x,1,9) $+ ) $gettok(%x,2,9) [Type: $gettok(%x,3,9) $+ ] }
  300.   if (stat* iswm $prop) { return $gettok(%x,3-9,9) }
  301.   else { return %x }
  302. }
  303. alias p_get {
  304.   var %f = txt/pokemon/ $+ $ticks, %a = $p_loc($.nick).num, %m
  305.   filter -ffg txt/pokemon/area.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  306.   %m = $($str( $+ $!gettok( $+ $!read( $+ %f $+ ),2,9) $!+ $!chr(44) $chr(32) ,$iif($1,$1,1)),2)
  307.   .remove %f
  308.   return %m
  309. }
  310. alias p_rare {
  311.   if ($1) {
  312.     var %x = $pokemon($1-).name
  313.     return $iif($read(txt/pokemon/rare.txt,r,/(\x09 $regescape(%x) )$/ix),$true,$false)
  314.   }
  315.   var %f = txt/pokemon/ $+ $ticks, %a = $p_loc($.nick).num
  316.   filter -ffg txt/pokemon/rare.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  317.   .timerrare 1 1 .remove %f
  318.   return $gettok($read(%f),2,9)
  319. }
  320. alias p_uncom {
  321.   if ($1) {
  322.     var %x = $pokemon($1-).name
  323.     return $iif($read(txt/pokemon/uncommon.txt,w,%x $+ *),$true,$false)
  324.   }
  325. }
  326. alias p_traded {
  327.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $2 $+ '
  328.   set -l %query $sqlite_query(%poke.db,%sql)
  329.   set -l %fetch $sqlite_fetch_row(%query,traded,$SQLITE_ASSOC)
  330.   var %x = $iif($hget(traded,traded) == 1,$true,$false)
  331.   sqlite_free %query
  332.   if ($hget(traded)) { hfree traded }
  333.   return %x
  334. }
  335. alias p_exp { return $ceil($calc((7 * $1 ^ 3) / 5)) }
  336. alias p_+exp {
  337.   sqlite_begin %poke.db
  338.   if ($1 == rare candy) {
  339.     var %p = $2, %exp = $calc($p_exp($calc($p_stat($.nick,%p).lvl + 1)) - $p_stat($.nick,%p).exp)
  340.     sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET exp=exp+ %exp WHERE pokemon=' $+ $sql_esc(%p) $+ '
  341.   }
  342.   else {
  343.     var %p = $p_active($.nick), %exp = $ceil($calc($iif($p_traded($.nick,%p),1.5,1) * $p_bexp($1).exp * $2 / 7))
  344.     sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET exp=exp+ %exp , evhp=evhp+ $p_bexp($1).hp , evatk=evatk+ $p_bexp($1).atk , evdef=evdef+ $p_bexp($1).def , evspatk=evspatk+ $p_bexp($1).spatk , evspdef=evspdef+ $p_bexp($1).spdef , evspd=evspd+ $p_bexp($1).spd WHERE pokemon=' $+ $sql_esc(%p) $+ '
  345.   }
  346.   set -l %sql SELECT * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  347.   set -l %query $sqlite_query(%poke.db,%sql)
  348.   set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  349.   if ($p_exp($calc($hget(pkexp,lvl) + 1)) <= $hget(pkexp,exp)) && ($hget(pkexp,lvl) < 99) {
  350.     var %lvl = $hget(pkexp,lvl) + 1, %e = $p_path(%p), %n = $gettok(%e,$calc($findtok(%e,%p,1,9) + 1),9)
  351.     if (%lvl >= $p_el(%p)) && (%lvl != 99) && ($has_pokemon($.nick,%n) != has) {
  352.       if (| isin %n) {
  353.         if (%p == Wurmple) { %n = $iif($calc($hget(pkexp,pv) % 10) < 5,Silcoon,Cascoon) }
  354.         elseif ($regex(%p,/^(Silcoon|Cascoon)$/i)) { %n = $iif(%p == Silcoon,Beautifly,Dustox) }
  355.         else {
  356.           var %x = 1, %y = $numtok(%n,124), %a, %s
  357.           while (%x <= %y) {
  358.             var %a = $gettok(%n,%x,124)
  359.             if ($sql_re($hget(pkexp,item)) == $p_ei(%a)) { %s = %a }
  360.             inc %x
  361.           }
  362.           if (!%s) { goto level }
  363.           else { %n = %s }
  364.         }
  365.       }
  366.       elseif ($p_ei(%n)) {
  367.         if ($sql_re($hget(pkexp,item)) != $p_ei(%n)) { goto level }
  368.         else { sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET item=' $+ $null $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ ' }
  369.       }
  370.       var %pv = $hget(pkexp,pv), %ability = $gettok($read(txt/pokemon/abilitylist.txt,w,%n $+ *),2,9), %ability = $iif($numtok(%ability,44) == 2 && $odd(%pv),$gettok(%ability,2,44),$gettok(%ability,1,44))
  371.       msg $chan %p is Evolving! %p evolved in to %n
  372.       sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET pokemon=' $+ $sql_esc(%n) $+ ', ability=' $+ $sql_esc(%ability) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  373.       sqlite_exec %poke.db UPDATE p_pokemon SET $sql_esc(%n) $+ ='1' WHERE name=' $+ $sql_esc($.nick) $+ '
  374.       sqlite_exec %poke.db DELETE * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  375.       lock_pokemon $.nick %p
  376.       hadd pkexp pokemon %n
  377.       if ($p_active($.nick) == %p) { p_active $.nick %n }
  378.     }
  379.     :level
  380.     var %p = $hget(pkexp,pokemon), %n = $read(txt/pokemon/nature.txt,w,$hget(pkexp,nature) $+ *), %ps = $pokemon($hget(pkexp,pokemon)).stat, %hp = $gettok(%ps,2,9), %atk = $gettok(%ps,3,9), %def = $gettok(%ps,4,9), %spatk = $gettok(%ps,5,9), %spdef = $gettok(%ps,6,9), %spd = $gettok(%ps,7,9)
  381.     var %hp = $iif(%p == Shedinja,1,$calc(($hget(pkexp,ivhp) + (2 * %hp) + ($hget(pkexp,evhp) / 4)) * (%lvl / 100) + 10 + %lvl)), %atk = $calc((($hget(pkexp,ivatk) + (2 * %atk) + ($hget(pkexp,evatk) / 4)) * (%lvl / 100) + 5)), %def = $calc((($hget(pkexp,ivdef) + (2 * %def) + ($hget(pkexp,evdef) / 4)) * (%lvl / 100) + 5)), %spatk = $calc((($hget(pkexp,ivspatk) + (2 * %spatk) + ($hget(pkexp,evspatk) / 4)) * (%lvl / 100) + 5)), %spdef = $calc((($hget(pkexp,ivspdef) + (2 * %spdef) + ($hget(pkexp,evspdef) / 4)) * (%lvl / 100) + 5)), %spd = $calc((($hget(pkexp,ivspd) + (2 * %spd) + ($hget(pkexp,evspd) / 4)) * (%lvl / 100) + 5))
  382.     if ($gettok(%n,2,32)) {
  383.       inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  384.       dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  385.     }
  386.     msg $chan %p gained a level ( $+ %lvl $+ ) $+([HP: +,$floor($calc(%hp - $hget(pkexp,hp))),]) $+([ATK: +,$floor($calc(%atk - $hget(pkexp,atk))),]) $+([DEF: +,$floor($calc(%def - $hget(pkexp,def))),]) $+([SP.ATK: +,$floor($calc(%spatk - $hget(pkexp,spatk))),]) $+([SP.DEF: +,$floor($calc(%spdef - $hget(pkexp,spdef))),]) $+([SPD: +,$floor($calc(%spd - $hget(pkexp,spd))),])
  387.     sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET lvl=' $+ %lvl $+ ', hp=' $+ $floor(%hp) $+ ', atk=' $+ $floor(%atk) $+ ', def=' $+ $floor(%def) $+ ', spatk=' $+ $floor(%spatk) $+ ', spdef=' $+ $floor(%spdef) $+ ', spd=' $+ $floor(%spd) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  388.     var %m1 = $hget(pkexp,m1), %m2 = $hget(pkexp,m2), %m3 = $hget(pkexp,m3), %m4 = $hget(pkexp,m4), %mlist = $+(%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4)
  389.     if ($p_move(%p,%lvl)) {
  390.       var %nm = $v1
  391.       if ($numtok(%mlist,44) < 4) {
  392.         msg $chan $sql_re(%p) learned %nm $+ !
  393.         sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET $+(m,$calc($numtok(%mlist,44) + 1)) =' $+ $sql_esc(%nm) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  394.       }
  395.       else {
  396.         msg $chan $sql_re(%p wants to learn %nm [Current moves: %m1 $+ $chr(44) %m2 $+ $chr(44) %m3 $+ $chr(44) %m4 $+ ] - Type !forget <name> and !pokemove <name> to see stats.)
  397.         p_mark $.nick $+(%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4,$chr(44),%nm)
  398.         p_status $.nick learn
  399.       }
  400.     }
  401.   }
  402.   sqlite_commit %poke.db
  403.   sqlite_free %query
  404.   if ($hget(pkexp)) { hfree pkexp }
  405. }
  406. on *:text:!forget*:#:{
  407.   if ($p_status($.nick) == learn) {
  408.     var %x = $p_mark($.nick)
  409.     if ($istok(%x,$pokemove($2-).name,44)) { %x = $remtok(%x,$pokemove($2-).name,1,44)
  410.       .notice $nick $p_active($.nick) forgot $pokemove($2-).name $+ . $+([,$gettok(%x,1,44),$chr(44) , $gettok(%x,2,44),$chr(44) , $gettok(%x,3,44),$chr(44) , $gettok(%x,4,44),])
  411.       sqlite_exec %poke.db UPDATE $sql_esc($.nick) SET m1=' $+ $sql_esc($gettok(%x,1,44)) $+ ', m2=' $+ $sql_esc($gettok(%x,2,44)) $+ ', m3=' $sql_esc($+ $gettok(%x,3,44)) $+ ', m4=' $+ $sql_esc($gettok(%x,4,44)) $+ ' WHERE pokemon=' $+ $p_active($.nick) $+ '
  412.       p_status $.nick ready
  413.     }
  414.     else { .notice $nick That isn't a valid option. }
  415.   }
  416. }
  417. alias p_bexp {
  418.   tokenize 9 $read(txt/pokemon/ev.txt,r,/\x09 $replace($pokemon($1-).name,$chr(32),\s,$chr(40),.,$chr(41),.) \s\x09/xi)
  419.   if ($prop == exp) { return $3 }
  420.   if ($prop == hp) { return $4 }
  421.   if ($prop == atk) { return $5 }
  422.   if ($prop == def) { return $6 }
  423.   if ($prop == spatk) { return $7 }
  424.   if ($prop == spdef) { return $8 }
  425.   if ($prop == spd) { return $9 }
  426. }
  427. alias p_cr {
  428.   var %x = $read(txt/pokemon/cr.txt,w,$pokemon($1).name $+ *)
  429.   return $gettok(%x,2,9)
  430. }
  431. alias p_el {
  432.   if ($1) {
  433.     var %x = $read(txt/pokemon/level.txt,w,$pokemon($1).name $+ *)
  434.     return $iif(%x,$calc($gettok(%x,2,9) + 1),$null)
  435.   }
  436. }
  437. alias p_path {
  438.   var %p = $pokemon($1).name, %x = $read(txt/pokemon/path.txt,w,* $+ %p $+ *), %t = $calc($findtok(%x,%p,1,9) $prop 1)
  439.   if ($prop) { return $gettok(%x,%t,9) }
  440.   return %x
  441. }
  442. alias p_ml {
  443.   if ($1) {
  444.     var %x = $pokemon($1).name, %p = $p_path(%x), %t = $findtok(%p,%x,1,9) - 1
  445.     return $iif(%t,$p_el($gettok(%p,%t,9)),1)
  446.   }
  447. }
  448. alias p_ei {
  449.   if ($1) {
  450.     var %x = $pokemon($1).name
  451.     if %x { %x = $read(txt/pokemon/evolve.item.txt,w,%x $+ *) }
  452.     return $iif(%x,$gettok(%x,2,9),$null)
  453.   }
  454. }
  455. alias p_ep {
  456.   var %p = $read(txt/pokemon/path.txt,w,* $+ $pokemon($1).name $+ * )
  457.   return $($regsubex(%p,/([^\|]+?)(\x09)/g,\1->( $!+ $!p_el( $+ \1 $+ ) $!+ $!iif( $!+ $!read(txt/pokemon/evolve.item.txt,w,* $!+ $!p_path( $+ \1 $+ ).+ $!+ *) $!+ ,*) $!+ )->),3)
  458. }
  459. alias p_vs {
  460.   var %x = 1, %a1, %d1, %dam1, %a2, %d2, %dam2, %h, %m, %hp1, %hp2
  461.   var %apm1 = $ceil($calc(($gettok($1,7,9) + 1) ^ .6 + 3)), %apm2 = $ceil($calc(($gettok($2,7,9) + 1) ^ .6 + 3)), %mod1 = $p_type($gettok($1,1,9),$gettok($2,1,9)), %mod2 = $p_type($gettok($2,1,9),$gettok($1,1,9))
  462.   while (%x <= %apm1) {
  463.     var %h = $rand(1,20), %m = $rand(1,20)
  464.     if (%m > %h) || (%h < 3) { dec %apm1 }
  465.     elseif (%h == 20) { inc %apm1 }
  466.     inc %x
  467.   }
  468.   %a1 = $calc($bottom($floor($calc(1 $($str( $!chr(32) + $!chr(32) $!chr(40) $!+ $!gettok($1, $!.rand(3,5).str ,9) ^ . $!+ $!.rand(6,8) $!+ $!chr(41) $!chr(32) ,%apm1),2))),1) * %mod1)
  469.   %d1 = $bottom($floor($calc(1 $($str( $!chr(32) + $!chr(32) $!chr(40) $!+ $!gettok($2, $!.rand(4,6).str ,9) ^ . $!+ $!.rand(2,4) $!+ $!chr(41) $!chr(32) ,%apm1),2))),1)
  470.   %x = 1
  471.   while (%x <= %apm2) {
  472.     var %h = $rand(1,20), %m = $rand(1,20)
  473.     if (%m > %h) || (%h < 3) { dec %apm2 }
  474.     elseif (%h == 20) { inc %apm2 }
  475.     inc %x
  476.   }
  477.   %a2 = $calc($bottom($floor($calc(1 $($str( $!chr(32) + $!chr(32) $!chr(40) $!+ $!gettok($2, $!.rand(3,5).str ,9) ^ . $!+ $!.rand(6,8) $!+ $!chr(41) $!chr(32) ,%apm2),2))),1) * %mod2)
  478.   %d2 = $bottom($floor($calc(1 $($str( $!chr(32) + $!chr(32) $!chr(40) $!+ $!gettok($1, $!.rand(4,6).str ,9) ^ . $!+ $!.rand(2,4) $!+ $!chr(41) $!chr(32) ,%apm2),2))),1)
  479.   %dam1 = $bottom($calc(%a1 - %d1),1)
  480.   %dam2 = $bottom($calc(%a2 - %d2),1)
  481.   %hp1 = $calc($gettok($1,2,9) - %dam2)
  482.   %hp2 = $calc($gettok($2,2,9) - %dam1)
  483.   return $iif(%hp1 > %hp2,1,2)
  484. }
  485. alias p_npc {
  486.   var %x, %y = $lines(txt/pokemon/ev.txt), %p = $pokemon($1).stat, %l = 1, %exp = 1, %pv = $rand(0,4294967295)
  487.   var %hp = $gettok(%p,2,9), %atk = $gettok(%p,3,9), %def = $gettok(%p,4,9), %spatk = $gettok(%p,5,9), %spdef = $gettok(%p,6,9), %spd = $gettok(%p,7,9), %ivhp = $rand(1,32), %ivatk = $rand(1,32), %ivdef = $rand(1,32), %ivspatk = $rand(1,32), %ivspdef = $rand(1,32), %ivspd = $rand(1,32), %evhp = 0, %evatk = 0, %evdef = 0, %evspatk = 0, %evspdef = 0, %evspd = 0
  488.   var %ability = $gettok($read(txt/pokemon/abilitylist.txt,w,$1 $+ *),2,9), %ability = $iif($numtok(%ability,44) == 2 && $odd(%pv),$gettok(%ability,2,44),$gettok(%ability,1,44)), %nature = $read(txt/pokemon/nature.txt,s,$calc(%pv % 25)), %n = $read(txt/pokemon/nature.txt,nw,%nature $+ *)
  489.   .fopen npc txt/pokemon/ev.txt
  490.   while (%l < $2) {
  491.     .fseek -l npc $rand(1,%y)
  492.     %x = $fread(npc)
  493.     inc %exp $floor($calc($gettok(%x,3,9) * %l / 7))
  494.     inc %evhp $gettok(%x,4,9)
  495.     inc %evatk $gettok(%x,5,9)
  496.     inc %evdef $gettok(%x,6,9)
  497.     inc %evspatk $gettok(%x,7,9)
  498.     inc %evspdef $gettok(%x,8,9)
  499.     inc %evspd $gettok(%x,9,9)
  500.     while (%exp > $p_exp($calc(%l + 1))) { inc %l }
  501.   }
  502.   set -l %sql SELECT * FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  503.   set -l %query $sqlite_query(%poke.db,%sql)
  504.   set -l %fetch $sqlite_fetch_row(%query,npcmove,$SQLITE_ASSOC)
  505.   var %n = 1, %m, %physical, %status, %special, %all
  506.   while (%n <= $2) {
  507.     if ($hget(npcmove,$+(l,%n))) {
  508.       %m = $hget(npcmove,$+(l,%n))
  509.       %all = $addtok(%all,%m,9)
  510.       var % $+ $pokemove(%m).cat $addtok($($+(%,$pokemove(%m).cat),2),%m,9)
  511.     }
  512.     inc %n
  513.   }
  514.   var %m
  515.   if ($numtok(%all,9) <= 4) { var %c = $numtok(%all,9), %m = %all $+ $str($chr(9),$calc(4 - %c)) }
  516.   else {
  517.     while ($numtok(%m,9) < 4) { %m = $addtok(%m,$p_movesel($1,%all),9) }
  518.   }
  519.   var %hp = $iif($1 == Shedinja,1,$calc((%ivhp + (2 * %hp) + (%evhp / 4)) * (%l / 100) + 10 + %l)), %atk = $calc(((%ivatk + (2 * %atk) + (%evatk / 4)) * (%l / 100) + 5)), %def = $calc(((%ivdef + (2 * %def) + (%evdef / 4)) * (%l / 100) + 5)), %spatk = $calc(((%ivspatk + (2 * %spatk) + (%evspatk / 4)) * (%l / 100) + 5)), %spdef = $calc(((%ivspdef + (2 * %spdef) + (%evspdef / 4)) * (%l / 100) + 5)), %spd = $calc(((%ivspd + (2 * %spd) + (%evspd / 4)) * (%l / 100) + 5))
  520.   if ($gettok(%n,2,32)) {
  521.     inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  522.     dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  523.   }
  524.   .fclose npc
  525.   sqlite_free %query
  526.   if ($hget(npcmove)) { hfree npcmove }
  527.   return $+($1,$chr(9),%pv,$chr(9),%ability,$chr(9),%nature,$chr(9),0,$chr(9),,$chr(9),%m,$chr(9),%l,$chr(9),%exp,$chr(9),$floor(%hp),$chr(9),$floor(%atk),$chr(9),$floor(%def),$chr(9),$floor(%spatk),$chr(9),$floor(%spdef),$chr(9),$floor(%spd),$chr(9),%ivhp,$chr(9),%ivatk,$chr(9),%ivdef,$chr(9),%ivspatk,$chr(9),%ivspdef,$chr(9),%ivspd,$chr(9),%evhp,$chr(9),%evatk,$chr(9),%evdef,$chr(9),%evspatk,$chr(9),%evspdef,$chr(9),%evspd)
  528. }
  529. alias p_move {
  530.   set -l %sql SELECT l $+ $2 FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  531.   set -l %query $sqlite_query(%poke.db,%sql)
  532.   set -l %fetch $sqlite_fetch_row(%query,pkmove,$SQLITE_ASSOC)
  533.   var %x = $hget(pkmove,l $+ $2)
  534.   sqlite_free %query
  535.   if ($hget(pkmove)) { hfree pkmove }
  536.   return $iif(%x,$v1,$null)
  537. }
  538. alias add_pokemon {
  539.   var %x = $replace($sql_esc($2-),$chr(9),' $+ $chr(44) $+ '), %e = $read(txt/pokemon/path.txt,r,/ $gettok($2,1,9) /ix), %n = $findtok(%e,$gettok($2,1,9),1,9), %a = 1, %p
  540.   sqlite_begin %poke.db
  541.   if ($has_pokemon($1,$gettok($2-,1,9)) == has) {
  542.     .notice $nick You caught $gettok($2-,1,9) but you already have a $gettok($2-,1,9) $+ ! Do you want to !keep or !release the new one?
  543.     .notice $nick Old: $p_statfmt($1,$p_stat($.nick,$gettok($2-,1,9)))
  544.     .notice $nick New: $p_statfmt($1,$2-)
  545.     p_mark $1 $replace($2-,$chr(9),*)
  546.     p_status $1 replace
  547.     return
  548.   }
  549.   noop $p_+exp($gettok($2-,1,9),$gettok($filltok($2-,-,9),11,9))
  550.   sqlite_exec %poke.db UPDATE p_pokemon SET $sql_esc($gettok($2,1,9)) $+ ='1' WHERE name=' $+ $sql_esc($1) $+ '
  551.   sqlite_exec %poke.db INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  552.   sqlite_commit %poke.db
  553. }
  554. on *:text:!keep:#:{
  555.   if ($p_status($.nick) == replace) {
  556.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  557.     .notice $nick You keep the new %p and set your old one free.
  558.     p_status $.nick ready
  559.     replace_pokemon $.nick %x
  560.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  561.   }
  562. }
  563. on *:text:!release:#:{
  564.   if ($p_status($.nick) == replace) {
  565.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  566.     .notice $nick You keep your %p and let the new one go.
  567.     p_status $.nick ready
  568.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  569.   }
  570. }
  571. alias replace_pokemon {
  572.   var %p = $gettok($2-,1,42), %x = $replace($sql_esc($2-),$chr(42),' $+ $chr(44) $+ ')
  573.   sqlite_exec %poke.db DELETE FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  574.   sqlite_exec %poke.db INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  575.   noop $p_+exp(%p,$gettok($filltok($2-,-,42),11,42))
  576. }
  577. alias see_pokemon {
  578.   if (!$has_pokemon($1,$2)) {
  579.     sqlite_exec %poke.db UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='s' WHERE name=' $+ $sql_esc($1) $+ '
  580.   }
  581. }
  582. alias lock_pokemon {
  583.   sqlite_exec %poke.db UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='x' WHERE name=' $+ $sql_esc($1) $+ '
  584. }
  585. alias has_pokemon {
  586.   set -l %sql SELECT $sql_esc($2) FROM p_pokemon WHERE name=' $+ $sql_esc($1) $+ '
  587.   set -l %query $sqlite_query(%poke.db,%sql)
  588.   set -l %fetch $sqlite_fetch_row(%query,haspkm,$SQLITE_ASSOC)
  589.   sqlite_free %query
  590.   var %x = $replacex($hget(haspkm,$sql_esc($2)),1,has,x,had,s,seen)
  591.   if ($hget(haspkm)) { hfree haspkm }
  592.   return %x
  593. }
  594. alias trade_pokemon { }
  595.  
  596. on *:text:!pokemart*:#:{
  597.   if ($p_status($.nick) == ready) {
  598.     var %b = $p_cug($.nick).ball, %p = $p_cug($.nick).potion
  599.     .notice $nick Welcome to Pokemart! Commands: !buy, !upgrade and !sell
  600.     .notice $nick %b $+ : $ $+ $bytes($p_item(%b).cost,b) $iif($p_iug(%b),(Upgrade to $p_iug(%b) $+ : $ $+ $bytes($p_iug(%b).cost,b) +$ $+ $calc($p_item($p_iug(%b)).cost - $p_item(%b).cost) per %b $+ ) ) - %p $+ : $ $+ $bytes($p_item(%p).cost,b) $iif($p_iug(%P),(Upgrade to $p_iug(%p) $+ : $ $+ $bytes($p_iug(%p).cost,b) +$ $+ $calc($p_item($p_iug(%p)).cost - $p_item(%p).cost) per %p $+ ) )
  601.     .notice $nick Antidote: $!100 - Paralyze heal: $!200 -  Awakening: $!200 -  Burn heal: $!500 -  Ice heal: $!500 -  Full heal: $!1,000 -  Full restore: $!5,000
  602.     if (!$p_item($.nick,Bicycle)) { .notice $nick Bicycle: $!100,000 }
  603.   }
  604. }
  605.  
  606. on *:text:!buy*:#:{
  607.   if ($p_status($.nick) == ready) {
  608.     var %t = $iif($2 isnum,$3-,$2-), %c
  609.     if ($regex($2-,/((poke|great|ultra)?\s?ball|(super|hyper|max)?\s?potion|full\srestore|antidote|paralyze\sheal|awakening|burn\sheal|ice\sheal|full\sheal|bicycle)\s?/i)) {
  610.       if (*ball* iswm %t) { %t = $p_cug($.nick).ball }
  611.       if (*potion* iswm %t) { %t = $p_cug($.nick).potion }
  612.       %c = $iif($2 isnum,$calc($p_item(%t).cost * $2),$p_item(%t).cost)
  613.       if ($p_item($.nick,cash) >= %c) {
  614.         if (%t == bicycle) && ($p_item($.nick,bicycle)) { .notice $nick You already have a Bicycle! }
  615.         else {
  616.           .notice $nick You buy $iif($2 isnum,$2 %t $+ s,a %t)
  617.           if (*ball* iswm %t) { p_item $.nick Pokeball $iif($2 isnum,+ $+ $2) }
  618.           elseif (*potion* iswm %t) { p_item $.nick Potion $iif($2 isnum,+ $+ $2) }
  619.           else { p_item $.nick $sql_esc($p_item(%t).name) $iif($2 isnum,+ $+ $2) }
  620.           p_item $.nick cash - $+ %c
  621.         }
  622.       }
  623.       else { .notice $nick You don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  624.     }
  625.     else { .notice $nick You can't buy that! }
  626.   }
  627. }
  628. on $*:text:/^!upgrade\s(.*)(ball|potion)(.*)/:#:{
  629.   var %x, %c
  630.   if (*ball* iswm $2) { %x = $p_cug($.nick).ball }
  631.   elseif (*potion* iswm $2) { %x = $p_cug($.nick).potion }
  632.   %c = $calc($p_iug(%x).cost + $p_item($.nick,$iif(*ball* iswm $2,pokeball,potion)) * $p_item($iif(*ball* iswm $2,pokeball,potion)).cost)
  633.   if ($p_iug(%x)) {
  634.     if ($p_item($.nick,cash) >= %c) {
  635.       p_item $.nick $sql_esc($p_iug(%x))
  636.       p_item $.nick cash - $+ %c
  637.       .notice $nick You upgrade your %x to $p_iug(%x)
  638.     }
  639.     else { .notice $nick you don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  640.   }
  641.   else { .notice $nick You can't upgrade that! }
  642. }
  643. on *:text:!sell*:#:{
  644.   if ($p_status($.nick) == ready) {
  645.     var %i = $p_item($iif($2 isnum,$3-,$2-)).name, %n = $iif($2 isnum,$2,1), %c = $calc(($p_item(%i).cost * .1) * %n)
  646.     if ($p_item($.nick,%i) >= %n) {
  647.       .notice $nick You sell %n %i $+ $iif(%n > 1,$+ 's) for $ $+ %c $+ .
  648.       p_item $.nick $sql_esc(%i) - $+ %n
  649.       p_item $.nick cash + $+ %c
  650.     }
  651.     else { .notice $nick You don't have that many! }
  652.   }
  653. }
  654. on *:text:!inventory*:#:{
  655.   if ($p_status($.nick) == ready) {
  656.     set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($.nick) $+ '
  657.     set -l %query $sqlite_query(%poke.db,%sql)
  658.     set -l %fetch $sqlite_fetch_row(%query,pinv,$SQLITE_ASSOC)
  659.     sqlite_free %query
  660.     if (!$2) {
  661.       .notice $nick Cash $ $+ $bytes($hget(pinv,cash),b) - $p_cug($.nick).ball ( $+ $hget(pinv,pokeball) $+ ) - $p_cug($.nick).potion ( $+ $hget(pinv,potion) $+ )
  662.       .notice $nick Antidote ( $+ $hget(pinv,Antidote) $+ ) - Paralyze heal ( $+ $hget(pinv,Paralyze_32heal) $+ ) - Awakening ( $+ $hget(pinv,Awakening) $+ ) - Burn heal ( $+ $hget(pinv,Burn_32heal) $+ ) - Ice heal ( $+ $hget(pinv,Ice_32heal) $+ ) - Full heal ( $+ $hget(pinv,Full_32heal) $+ ) - Full restore ( $+ $hget(pinv,Full_32restore) $+ )
  663.       var %m = $iif($hget(pinv,bicycle),Bicycle ( $+ $v1 $+ ) ) $iif($hget(pinv,Rare_32candy),Rare Candy ( $+ $v1 $+ ) ) $iif($hget(pinv,Gold_32Nugget),Gold Nugget ( $+ $v1 $+ ) )
  664.       if (%m) { .notice $nick $regsubex(%m,/(\x29)\s(.)/,\1 - \2) }
  665.     }
  666.     elseif ($istok(hold.equip.equipment,$2,46)) {
  667.       var %x = 1, %n, %m, %i = Thunder_32stone,Fire_32stone,Water_32stone,Leaf_32stone,Sun_32stone,Moon_32stone,Oval_32stone,Dusk_32stone,Dawn_32stone,Shiny_32stone,Dragon_32scale,Metal_32coat,King_39s_32Rock,Attack_32up,Defense_32up,Special_32up,Black_32belt,BlackGlasses,Magnet,Spell_32tag,Poison_32Barb,Sharp_32beak,Silk_32Scarf,SilverPowder,Soft_32Sand,TwistedSpoon,NeverMeltIce,Hard_32Stone,Leftovers,Shell_32Bell,Muscle_32band,Scope_32lens,Wide_32lens,Wise_32Glasses,Quick_32claw,Amulet_32Coin
  668.       while (%x <= $numtok(%i,44)) {
  669.         %n = $gettok(%i,%x,44)
  670.         if ($hget(pinv,%n)) { %m = $addtok(%m,$chr(32) %n ( $+ $v1 $+ ) $chr(32),45) }
  671.         if ($numtok(%m,45) > 6) {
  672.           .notice $nick $sql_re(%m)
  673.           %m = $null
  674.         }
  675.         inc %x
  676.       }
  677.       if (%m) { .notice $nick $sql_re(%m) }
  678.     }
  679.     elseif ($regex($2,/(T|H)Ms?/i)) {
  680.       return
  681.     }
  682.   }
  683. }
  684. on *:text:!use*:#:{
  685.   if ($p_status($.nick) == ready) {
  686.     var %p = $pokemon($iif($4,$4-,$3-)).name, %i = $p_item($iif($4,$2 $3,$2)).name
  687.     if (!%p) { .notice $nick That isn't a pokemon! }
  688.     elseif (!%i) { .notice $nick That isn't an item! }
  689.     else {
  690.       if ($has_pokemon($.nick,%p)) && ($p_item($.nick,%i) > 0) {
  691.         if ($2 $3 == rare candy) {
  692.           noop $p_+exp(rare candy,%p)
  693.           p_item $.nick Rare_32candy -1          
  694.         }
  695.         elseif ($regex($2,/(T|H)M\d\d/i)) { .notice $nick TMs/HMs arent in yet, soon! }
  696.         else { .notice $nick You can't give %i to %p $+ ! }
  697.       }
  698.       else { .notice $nick You either don't have a %p or a %i $+ ! }
  699.     }
  700.   }
  701. }
  702. on *:text:!pokeitem*:#:{
  703.   if ($p_status($.nick) == ready) {
  704.     if ($p_item($2-).name) {
  705.       tokenize 9 $p_item($2-).desc
  706.       msg $chan $1 [Type: $2 $+ ] $6
  707.     }
  708.   }
  709. }
  710. alias p_getitem {
  711.   set -l %sql SELECT name FROM p_items WHERE type LIKE $+('%,$1,$(%',0)) ORDER BY RANDOM() LIMIT 1
  712.   set -l %query $sqlite_query(%poke.db,%sql)
  713.   set -l %fetch $sqlite_fetch_row(%query,pgitem,$SQLITE_ASSOC)
  714.   sqlite_free %query
  715.   var %x = $sql_re($hget(pgitem,name))
  716.   if ($hget(pgitem)) { hfree pgitem }
  717.   return %x
  718. }
  719. alias p_item {
  720.   if ($isid) {
  721.     if ($regex($1,/(T|H)M\d\d/i)) { return $1 }
  722.     if ($prop == name) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),1,9) }
  723.     if ($prop == type) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),2,9) }
  724.     if ($prop == cost) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),3,9) }
  725.     if ($prop == desc) { return $read(txt/pokemon/items.txt,w,* $+ $1 $+ *) }
  726.     set -l %sql SELECT $sql_esc($2) FROM p_inventory WHERE name=' $+ $sql_esc($1) $+ '
  727.     set -l %query $sqlite_query(%poke.db,%sql)
  728.     set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  729.     sqlite_free %query
  730.     var %x = $hget(pitem,$sql_esc($2))
  731.     if ($hget(pitem)) { hfree pitem }
  732.     return %x
  733.   }
  734.   sqlite_exec %poke.db UPDATE p_inventory SET $sql_esc($2) $+ = $sql_esc($2) $iif($3,$3,+1) WHERE name=' $+ $sql_esc($1) $+ '
  735. }
  736. alias p_iug {
  737.   if ($prop == cost) { var %x = $replacex($1,Pokeball,10000,Greatball,20000,Potion,5000,Super Potion,25000,Hyper Potion,50000) }
  738.   else { var %x = $replacex($1,Pokeball,Greatball,Greatball,Ultraball,Ultraball,$null,Potion,Super Potion,Super Potion,Hyper Potion,Hyper Potion,Max Potion,Max Potion,$null) }
  739.   return %x
  740. }
  741. alias p_cug {
  742.   set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($1) $+ '
  743.   set -l %query $sqlite_query(%poke.db,%sql)
  744.   set -l %fetch $sqlite_fetch_row(%query,pcug,$SQLITE_ASSOC)
  745.   var %x = $iif($prop == ball,Pokeball,Potion)
  746.   while ($hget(pcug,$sql_esc($p_iug(%x)))) { %x = $p_iug(%x) }
  747.   if ($hget(pcug)) { hfree pcug }
  748.   sqlite_free %query
  749.   return %x
  750. }
  751. alias p_bmod {
  752.   set -l %sql SELECT mod FROM p_items WHERE name=" $+ $sql_esc($1) $+ "
  753.   set -l %query $sqlite_query(%poke.db,%sql)
  754.   set -l %fetch $sqlite_fetch_row(%query,pbmod,$SQLITE_ASSOC)
  755.   var %x = $hget(pbmod,mod)
  756.   if ($hget(pcug)) { hfree pcug }
  757.   sqlite_free %quest
  758.   return %x
  759. }
  760. alias p_type {
  761.   if (/ isin $1) { return $max($p_typex($gettok($1,1,47),$2),$p_typex($gettok($1,2,47),$2)) }
  762.   else { return $p_typex($1,$2) }
  763. }
  764. alias p_typex {
  765.   set -l %sql SELECT * FROM p_types WHERE type=' $+ $1 $+ '
  766.   set -l %query $sqlite_query(%poke.db,%sql)
  767.   set -l %fetch $sqlite_fetch_row(%query,ptype,$SQLITE_ASSOC)
  768.   sqlite_free %query
  769.   tokenize 47 $2
  770.   if ($2) {
  771.     var %x = $calc($hget(ptype,$1) + $hget(ptype,$2))
  772.     return $p_typec(%x).dual
  773.   }
  774.   else { return $p_typec($hget(ptype,$1)) }
  775. }
  776. alias p_typec {
  777.   if ($prop == dual) { return $replacex($1,2,0,3,0,5,0,9,0,4,.25,6,.5,10,1,8,1,12,2,16,4) }
  778.   return $replacex($1,1,0,2,.5,4,1,8,2)
  779. }
  780. on *:text:!pokemon:#:{
  781.   var %a
  782.   set -l %sql SELECT pokemon, lvl, pv FROM $sql_esc($.nick) ORDER BY lvl
  783.   set -l %query $sqlite_query(%poke.db,%sql)
  784.   while ($sqlite_fetch_row(%query,listp,$SQLITE_ASSOC)) {
  785.     whilefix
  786.     %a = $p_shiny($.nick,$hget(listp,pv)) $addtok(%a,$sql_re($hget(listp,pokemon) $iif($p_rare($hget(listp,pokemon)),[Rare]) $+ $iif($p_uncom($hget(listp,pokemon)),[Uncommon]) ( $+ $hget(listp,lvl) $+ )),44)
  787.     if ($numtok(%a,44) > 24) {
  788.       .notice $nick %a
  789.       %a = $null
  790.     }
  791.   }
  792.   if (%a) { .notice $nick %a }
  793.   sqlite_free %query
  794. }
  795. on $*:text:/^!(poke)?dex(stat)?\s/:#:{
  796.   var %x = $pokemon($2-), %e = $p_ep($pokemon($2-).name), %l = $regsubex($($regsubex($gettok($read(txt/pokemon/area.txt,w,* $+ $pokemon($2-).name),1,9),/(\d+)/g,$!p_loc( $+ \1 $+ ).name $!+ $!chr(44)),2),/(\x2C$)/,)
  797.   if (%x) {
  798.     if (*stat* iswm $1) { msg $chan $pokemon($2-).fmt Base stats - [HP: $gettok(%x,4,9) Atk: $gettok(%x,5,9) Def: $gettok(%x,6,9) Sp.Atk: $gettok(%x,7,9) Sp.Def: $gettok(%x,8,9) Spd: $gettok(%x,9,9) $+ ]  }
  799.     else { msg $chan $iif($p_rare($2-),[Rare]) $iif($p_uncom($2-),[Uncommon]) $pokemon($2-).fmt [Height: $p_height($2-) $+ ] [Weight: $p_weight($2-) $+ ] [Evolution: $iif(%e,%e,Does not evolve) $+ ] $iif($has_pokemon($.nick,$2-),[Locations: %l $+ ]) }
  800.   }
  801. }
  802. on *:text:!pokestat*:#:{
  803.   if ($p_status($.nick)) {
  804.     if ($2) && ($has_pokemon($.nick,$2) != has) { .notice $nick You don't have a $2 $+ , $.nick $+ . }
  805.     else { msg $chan $p_statfmt($.nick,$p_stat($.nick,$iif($2,$pokemon($2).name,$p_active($.nick)))) }
  806.   }
  807. }
  808. alias p_statfmt {
  809.   tokenize 9 $1 $chr(9) $sql_re($filltok($replace($2,*,$chr(9)),-,9))
  810.   return $p_shiny($1,$3) $2 ( $+ $12 $+ ) [Exp: $13 $+ / $+ $p_exp($calc($12 + 1)) $+ ] [Type: $pokemon($2).type $+ ] [Nature: $5 $+ ] [Ability: $4 $+ ] [HP: $14 $+ ] [Atk: $15 $+ ] [Def: $16 $+ ] [Sp.Atk: $17 $+ ] [Sp.Def: $18 $+ ] [Spd: $19 $+ ] [Attacks: $8 $+ $iif($9 != -,$chr(44) $9) $+ $iif($10 != -,$chr(44) $10,) $+ $iif($11 != -,$chr(44) $11) $+ ] $iif($7 != -,[Holding: $sql_re($7) $+ ])
  811. }
  812. alias p_stat {
  813.   var %x = $pokemon($2).name, %t = txt/pokemon/ $+ $ticks
  814.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%x) $+ '
  815.   set -l %query $sqlite_query(%poke.db,%sql)
  816.   set -l %fetch $sqlite_fetch_all(%query,%t)
  817.   if (!%fetch) { return error %sqlite_errstr }
  818.   sqlite_free %query
  819.   .timer 1 1 .remove %t
  820.   %x = $filltok($read(%t,1),-,9)
  821.   if ($prop == lvl) { return $gettok(%x,11,9) }
  822.   if ($prop == exp) { return $gettok(%x,12,9) }
  823.   if ($prop == vs) { return $pokemon($gettok(%x,1,9)).type $+ $chr(9) $+ $gettok(%x,13-18,9) }
  824.   return %x
  825. }
  826. on *:text:!pokemove*:#:{
  827.   tokenize 44 $replace($2-,*,.+?)
  828.   if ($len($1) >= 3) {
  829.     filter -cffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($1,/(\s)/g,.*) )(.+?)/ix
  830.     if ($len($2) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($2,/(\s)/g,.*) )(.+?)/ix }
  831.     if ($len($3) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($3,/(\s)/g,.*) )(.+?)/ix }
  832.     if ($len($4) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($4,/(\s)/g,.*) )(.+?)/ix }
  833.     .fopen pmove txt/pokemon/temp.txt
  834.     while ($fread(pmove)) { msg $chan $pokemove($v1) }
  835.     .fclose pmove
  836.   }
  837. }
  838. alias pokemove {
  839.   if ($2) { var %t = $2 }
  840.   tokenize 9 $read(txt/pokemon/attacks.txt,w,$1 $+ *)
  841.   if ($prop == name) { return $1 }
  842.   if ($prop == type) { return $2 }
  843.   if (cat* iswm $prop) { return $3 }
  844.   if ($prop == power) { return $4 }
  845.   if (acc* iswm $prop) { return $5 }
  846.   if ($prop == pp) { return $6 }
  847.   if ($prop == effect) { return $7 }
  848.   if (prob* iswm $prop) { return $8 }
  849.   if ($prop == rating) {
  850.     return $calc(((3 + $rand(1,3) - $rand(1,3)) + ($replace($3,status,1,physical,1.5,special,2) * $+(1.,$rand(0,5))) + (((50 - $6) * .1) + $rand(1,5) - $rand(1,5)) $iif($4 != -,+ ($+(.,$rand(1,2)) * $4)) $iif($5 != -,+ ($+(.,$rand(1,15)) * $5)) $iif($8 != -,+ ($8 * .1))) $iif($2 isin %t,* 1.5))
  851.   }
  852.   if ($1) {
  853.     return $1 [Type: $2 $+ ] [Catagory: $3 $+ ] $iif($4 != -,[Power: $4 $+ ]) $iif($5 != -,[Accuracy: $5 $+ ]) [PP: $6 $+ ] $iif($7 != -,[Effect: $iif($8 != -,$8 $+ % chance -) $7 $+ ])
  854.   }
  855. }
  856. on $*:text:/^!((T|H)M\d\d)$/i:#:{
  857.   msg $chan ( $+ $upper($regml(1)) $+ ) $pokemove($tm($regml(1)))
  858. }
  859. alias tm {
  860.   tokenize 9 $read(txt/pokemon/tms.txt,w,$1 $+ *)
  861.   if ($1) { return $2 }
  862. }
  863. on *:text:!ability*:#:{
  864.   tokenize 9 $read(txt/pokemon/ability.txt,w,$2- $+ *)
  865.   if ($1) { msg $chan $1 $+ : $2 }
  866. }
  867. on *:text:!nature*:#:{
  868.   tokenize 32 $replace($read(txt/pokemon/nature.txt,wn,$2- $+ *),%,$null)
  869.   if ($1) { msg $chan $1 $+ : $iif($2,+ $+ $2 - $+ $3,No effect) }
  870. }
  871. alias p_movesel {
  872.   var %x = 1, %y = $numtok($2-,9), %t = $pokemon($1).type, %a, %cr, %m, %r = 0
  873.   while (%x <= %y) {
  874.     %a = $gettok($2-,%x,9)
  875.     %cr = $pokemove(%a,%t).rating
  876.     if (%cr > %r) { var %m = %a, %r = %cr }
  877.     inc %x
  878.   }
  879.   return %m
  880. }
  881. alias p_shiny {
  882.   if (!$3) {
  883.     set -l %sql SELECT id, sid FROM p_players WHERE name=" $+ $sql_esc($1) $+ "
  884.     set -l %query $sqlite_query(%poke.db,%sql)
  885.     set -l %fetch $sqlite_fetch_row(%query,pshiny,$SQLITE_ASSOC)
  886.     tokenize 32 $hget(pshiny,id) $hget(pshiny,sid) $2
  887.   }
  888.   var %x = $xor($xor($1,$2),$xor($base($left($base($3,10,2),16),2,10),$base($right($base($3,10,2),16),2,10)))
  889.   if (%x < 8) { msg #Flip shiny! }
  890.   return $iif(%x < 8,Shiny)
  891. }
  892. alias p_height {
  893.   noop $read(txt/pokemon/height.txt,w,* $+ $1- $+ *)
  894.   return $gettok($read(txt/pokemon/height.txt,$readn),1,9)
  895. }
  896. alias p_weight { return $gettok($read(txt/pokemon/weight.txt,w,$1- $+ *),2,9) }
  897. alias p_active {
  898.   if ($isid) { return $p_player($1,active) }
  899.   sqlite_exec %poke.db UPDATE p_players SET active=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  900. }
  901. alias p_status {
  902.   if ($isid) { return $p_player($1,status) }
  903.   sqlite_exec %poke.db UPDATE p_players SET status=' $+ $sql_esc($2) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  904. }
  905. alias p_mark {
  906.   if ($isid) { return $p_player($1,mark) }
  907.   sqlite_exec %poke.db UPDATE p_players SET mark=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  908. }
  909. alias p_ps {
  910.   if ($isid) { return $p_player($1,$2) }
  911.   sqlite_exec %poke.db UPDATE p_players SET $2 = $2 + 1 WHERE name=' $+ $sql_esc($1) $+ '
  912. }
  913. alias p_player {
  914.   set -l %sql SELECT $2 FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  915.   set -l %query $sqlite_query(%poke.db,%sql)
  916.   set -l %fetch $sqlite_fetch_row(%query,player,$SQLITE_ASSOC)
  917.   var %x = $iif($sql_re($hget(player,$2)),$v1,none)
  918.   sqlite_free %query
  919.   if ($hget(player)) { hfree player }
  920.   return %x
  921. }
  922. alias p_noncom { return $p_ini(cr,$1) }
  923. alias p_ini {
  924.   if ($isid) { return $readini(txt/pokemon/pokemon.ini,$1,$2) }
  925.   else { writeini txt/pokemon/pokemon.ini $1 $2 $3 }
  926. }
  927.  
  928. #pokemon end
  929. ;on 1500:text:!reset*:#:{ p_reset $2 }
  930. alias p_reset {
  931.   var %x = $iif($.nick($1).check,$.nick($1),$1)
  932.   sqlite_exec %poke.db DELETE FROM p_pokemon WHERE name=' $+ $sql_esc(%x) $+ '
  933.   sqlite_exec %poke.db DELETE FROM p_players WHERE name=' $+ $sql_esc(%x) $+ '
  934.   sqlite_exec %poke.db DELETE FROM p_inventory WHERE name=' $+ $sql_esc(%x) $+ '
  935.   sqlite_exec %poke.db DELETE FROM p_badges WHERE name=' $+ $sql_esc(%x) $+ '
  936.   sqlite_exec %poke.db DROP TABLE $sql_esc(%x)
  937.   msg $chan %x reset
  938. }
  939. alias db_additem {
  940.  
  941. }
  942. alias _pdb {
  943.   var %x = 1, %y = $lines(txt/pokemon/tms.txt), %a
  944.   sqlite_exec %poke.db CREATE TABLE p_tm (name varchar(20))
  945.   while (%x <= %y) {
  946.     %a = $gettok($read(txt/pokemon/tms.txt,%x),1,9)
  947.     sqlite_exec %poke.db ALTER TABLE p_tm ADD %a varchar(3)
  948.     inc %x
  949.   }
  950. }
  951. alias gendb {
  952.   var %sql.db = $sqlite_open(txt/pokemon/pokemon.db3)
  953.   sqlite_begin %sql.db
  954.   sqlite_exec %sql.db CREATE TABLE p_players (name varchar(20), id varcahr(6), sid varchar(6), loc varchar(5), active varchar(20), status varchar(10), attempts varchar(7), battles varchar(3), wins varchar(7), mark varchar(250))
  955.   sqlite_exec %sql.db CREATE TABLE p_badges (name varchar(20))
  956.   sqlite_exec %sql.db CREATE TABLE p_pokemon (name varchar(20))
  957.   var %x = 1, %y = $lines(txt/pokemon/pokemon.txt), %a
  958.   while (%x <= %y) {
  959.     %a = $gettok($read(txt/pokemon/pokemon.txt,%x),2,9)
  960.     sqlite_exec %sql.db ALTER TABLE p_pokemon ADD $sql_esc(%a) char(1)
  961.     inc %x
  962.   }
  963.   sqlite_exec %sql.db CREATE TABLE p_types (type varchar(8),Bug varchar(2),Fighting varchar(2),Flying varchar(2),Ghost varchar(2),Ground varchar(2),Normal varchar(2),Poison varchar(2),Rock varchar(2),Steel varchar(2),Dark varchar(2),Dragon varchar(2),Electric varchar(2),Fire varchar(2),Grass varchar(2),Ice varchar(2),Psychic varchar(2),Water varchar(2))
  964.   var %x = 2, %y = $lines(txt/pokemon/resource/chart.txt), %a
  965.   while (%x <= %y) {
  966.     %a = $replace($read(txt/pokemon/resource/chart.txt,%x),;,' $+ $chr(44) $+ ')
  967.     sqlite_exec %sql.db INSERT INTO p_types (type,Bug,Fighting,Flying,Ghost,Ground,Normal,Poison,Rock,Steel,Dark,Dragon,Electric,Fire,Grass,Ice,Psychic,Water) VALUES (' $+ %a $+ ')
  968.     inc %x
  969.   }
  970.   sqlite_exec %sql.db CREATE TABLE p_inventory (name varchar(20), Cash varchar(20))
  971.   sqlite_exec %sql.db CREATE TABLE p_items (name varchar(20), type varchar(20), cost varchar(10), mod varchar(10), effect varchar(15), desc varchar(200))
  972.   var %x = 1, %y = $lines(txt/pokemon/items.txt), %a
  973.   while (%x <= %y) {
  974.     %a = $read(txt/pokemon/items.txt,%x)
  975.     sqlite_exec %sql.db ALTER TABLE p_inventory ADD $sql_esc($gettok(%a,1,9)) varchar(3)
  976.     sqlite_exec %sql.db INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  977.     inc %x
  978.   }
  979.   sqlite_exec %sql.db CREATE TABLE p_learnset (name varchar(50))
  980.   %x = 1
  981.   while (%x <= 99) {
  982.     sqlite_exec %sql.db ALTER TABLE p_learnset ADD l $+ %x varchar(20)
  983.     inc %x
  984.   }
  985.   var %x = 1, %y = $lines(txt/pokemon/learnset.txt), %a, %n, %t
  986.   while (%x <= %y) {
  987.     %a = $read(txt/pokemon/learnset.txt,%x)
  988.     tokenize 9 %a
  989.     %n = 1
  990.     %t = $numtok($2,44)
  991.     sqlite_exec %sql.db INSERT INTO p_learnset (name) VALUES (' $+ $replace($sql_esc($1),_44,*) $+ ')
  992.     while (%n <= %t) {
  993.       sqlite_exec %sql.db UPDATE p_learnset SET l $+ $replace($gettok($2,%n,44),|,=') $+ ' WHERE name=' $+ $replace($sql_esc($1),_44,*) $+ '
  994.       inc %n
  995.     }
  996.     inc %x
  997.   }
  998.   sqlite_commit %sql.db
  999.   sqlite_close %sql.db
  1000. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement