Advertisement
Flip

pokemon irc

Mar 14th, 2011
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 61.95 KB | None | 0 0
  1.         ¤ pokemon ¤
  2.  
  3. #pokemon on
  4. on *:start:{ start_pdb }
  5. on *:exit:{ close_pdb }
  6. alias start_pdb {  
  7.   set %pdb $sqlite_open(txt/pokemon/pokemon.db3)
  8.   hmake pokemon
  9.   var %t = $tm(2) $tm(2) $tm(2) $tm(2) $tm(2) $tm(2)
  10.   while ($p_loc(%x,%y).name == 0) { var %x = $rand(1,5), %y = $rand(1,5) }
  11.   hadd pokemon p_attempt 1
  12.   hadd pokemon p_salesman %x %y
  13.   hadd pokemon p_mall $dupe(%t)
  14. }
  15. alias close_pdb {
  16.   sqlite_close %pdb
  17.   unset %pdb
  18.   hfree pokemon
  19. }
  20. 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) }
  21. alias sql_re { return $regsubex($1-,/(_(\d{2,3}))/g,$chr( \2 )) }
  22. on *:text:!catch:#:{
  23.   if (%pdb) {
  24.     var %a = $p_active($.nick), %status = $p_status($.nick)
  25.     if (%status == none) {
  26.       .notice $nick You don't have any pokemon yet, Please choose from the following by typing !choose <pokemon>
  27.       .notice $nick Bulbasaur, Charmander, Squirtle, Pidgey, Weedle, Pichu, Machop, Abra, Geodude, Staryu, Chikorita, Cyndaquil, Totodile
  28.       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. }
  29.     }
  30.     elseif ($hget(pokemon,$.nick)) { .notice $nick All the pokemon ran away, Try again later. ( $+ $v1 sec $+ ) }
  31.     elseif (%status == learn) { .notice $nick %a has too many moves! $+([,$sql_re($p_mark($.nick)),]) Type !forget <move> }
  32.     elseif (%status == replace) { .notice $nick You need to choose which pokemon to keep, but i havent wrote a message for this yet. }
  33.     elseif (%status == choiceadv) { choiceadv $gettok($p_mark($.nick),2,42) }
  34.     elseif (%status == ready) {
  35.       hadd -z pokemon $.nick $iif($istok(%punish,$.nick,44),150,$iif($p_item($.nick,Bicycle),45,60))
  36.       hinc pokemon p_attempt
  37.       if ($calc($hget(pokemon,p_attempt) % 10) == 0) && ($rand(1,100) < 80) { hadd pokemon p_salesman $p_loc($hget(pokemon,p_salesman)).rand }
  38.       if ($calc($hget(pokemon,p_attempt) % 100) == 0) {
  39.         var %t = $tm(2) $tm(2) $tm(2) $tm(2) $tm(2) $tm(2)
  40.         hadd pokemon p_mall $dupe(%t)
  41.       }
  42.       p_ps $.nick attempts
  43.       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
  44.       if ($calc($rand(0,100000) % 100) <= $p_noncom(%loc)) {
  45.         var %tf = txt/pokemon/ $+ $ticks , %cadv, %a
  46.         filter -ffg txt/pokemon/noncom.txt %tf /(\x09|\x2C)( %loc |\*)(\x09|\x2C)/x
  47.         while (!%cadv) {
  48.           var %a = $read(%tf)
  49.           if (!$gettok(%a,3,9)) || ($rand(1,100) > $gettok(%a,3,9)) {
  50.             %cadv = $gettok(%a,1,9)
  51.             if (%cadv == 38) && ($p_loc($.nick).num != $hget(pokemon,p_salesman)) { %cadv = $null }            
  52.           }
  53.         }
  54.         choiceadv %cadv
  55.         .remove %tf
  56.       }
  57.       else {
  58.         :redo
  59.         var %n = 1, %a, %c, %u, %r, %y = $rand(1,100), %catch, %npc, %npcvs, %vs, %cash
  60.         while (%n <= $numtok(%q,44)) {
  61.           %a = $regsubex($gettok(%q,%n,44),/(^\x20)/,)
  62.           if ($read(txt/pokemon/rare.txt,r,/\x09( $regescape(%a) )$/xi)) { %r = $addtok(%r,%a,44) }
  63.           if ($has_pokemon($.nick,%a) == has) { %c = $addtok(%c,%a,44) }
  64.           else { %u = $addtok(%u,%a,44) }
  65.           inc %n
  66.         }
  67.         %n = $calc(100 / ($numtok(%q,44) / $numtok(%u,44)))
  68.         if (%x == 0) {
  69.           %p = $p_rare
  70.           if (%r) && ($istok(%r,%p,44)) {
  71.             if ($istok(%u,%p,44)) { %catch = 1 }
  72.           }
  73.           else {
  74.             msg $chan $nick $+ : You see a rare %p in the distance, but it's gone before you can get to it.
  75.             see_pokemon $.nick %p
  76.             return
  77.           }
  78.         }
  79.         elseif (%n) && (%y <= %n) {
  80.           %p = $.rand(%u)
  81.           while ($istok(%r,%p,44)) {
  82.             %u = $remtok(%u,%p,1,44)
  83.             %p = $.rand(%u)
  84.           }
  85.           if (%p) { %catch = 1 }
  86.           else { var %p = $.rand(%c), %catch = 1 }
  87.         }
  88.         else { var %p = $.rand(%c), %catch = 1  }
  89.         if (!%p) {
  90.           msg $chan Error: no pokemon selected.
  91.           return
  92.         }
  93.         if ($p_uncom(%p)) {
  94.           if ($rand(1,10) < 7) {
  95.             %x = 1
  96.             %q = $dupe($p_get(20))
  97.             goto redo
  98.           }
  99.         }
  100.         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))
  101.         var %npc = $p_gen(%p,%lvl), %pv = $gettok(%npc,2,9)
  102.         %npcvs = $pokemon($gettok(%npc,1,9)).type $+ $chr(9) $+ $gettok(%npc,12-17,9)
  103.         %vs = $p_vs($p_stat($.nick,$p_active($.nick)).vs,%npcvs)
  104.         %cash = $ceil($calc(%lvl ^ 1.7 + (%lvl + $rand(1,%lvl) - $rand(1,%lvl)) * 1.5 + (%lvl * 2)))
  105.         if (%vs == 1) {
  106.           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)
  107.           echo -s $.nick %p Natural catch rate: %cr - After calc: %crp - Roll: %crr
  108.           if (%crr < %crp) { var %catch = 0 }
  109.           if (%catch) && ($p_item($.nick,Pokeball) > 0) {
  110.             p_item $.nick Pokeball -1
  111.             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) (+ $+ $bytes($p_mexp(%p,%lvl),b) Exp)
  112.             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. }
  113.             add_pokemon $.nick %npc
  114.             p_item $.nick Cash + $+ %cash
  115.           }
  116.           else {
  117.             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) (+ $+ $bytes($p_mexp(%p,%lvl),b) Exp)
  118.             p_item $.nick Cash + $+ %cash
  119.             if ($p_item($.nick,Pokeball) > 0) {
  120.               if (!$has_pokemon($.nick,%p)) || ($has_pokemon($.nick,%p) == seen) {
  121.                 if (%catch) { p_item $.nick Pokeball -1 }
  122.               }
  123.               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. }
  124.             }
  125.             noop $p_+exp(%p,%lvl)
  126.           }
  127.         }
  128.         else {
  129.           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.
  130.           see_pokemon $.nick %p
  131.         }
  132.       }
  133.     }
  134.   }
  135. }
  136. alias choiceadv {
  137.   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
  138.   if ($1 == 1) { msg $chan $nick $+ : You wander around, but don't really find anything of interest. }
  139.   elseif ($1 == 2) {
  140.     %x = $ceil($calc($rand(5,10) * $rand(10,50) * (%lvl ^ .4)))
  141.     msg $chan $nick $+ : You get sidetracked while looking for pokemon, but you find some buried treasure, score! (+$ $+ %x cash)
  142.     p_item $.nick cash + $+ %x
  143.   }
  144.   elseif ($1 == 3) {
  145.     %x = $rand(1,10) $iif($rand(1,10) > 8, * 2)
  146.     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!)
  147.     p_item $.nick pokeball + $+ %x
  148.   }
  149.   elseif ($1 == 4) {
  150.     %x = $rand(1,25)
  151.     if (%x == 25) {
  152.       msg $chan $nick $+ : You chase after %p but it gets away, but you spot some Rare candy, sweet! (+1 Rare candy)
  153.       p_item $.nick $sql_esc(Rare candy)
  154.       see_pokemon $.nick %p
  155.     }
  156.     elseif (%x == 1) {
  157.       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)
  158.       p_item $.nick $sql_esc(Gold nugget)
  159.       see_pokemon $.nick %p
  160.     }
  161.     else {
  162.       var %x = $rand(1,100), %t = $iif(%x <= 25,battle,hold), %x = $p_getitem(%t), %n = 1, %i = $p_item($.nick,%x)
  163.       if (%t == hold) {
  164.         while ($rand(1,100) < $calc(%i * 20)) && (%n <= 10) {
  165.           var %x = $p_getitem(%t)
  166.           var %i = $p_item($.nick,%x)
  167.           inc %n
  168.         }
  169.       }
  170.       if (*potion* iswm %x) { %x = $p_cug($.nick).potion }
  171.       msg $chan $nick $+ : You start battling with %p $+ . It gets away, but it drops a %x $+ . (+1 %x $+ )
  172.       p_item $.nick $sql_esc(%x)
  173.       see_pokemon $.nick %p
  174.     }
  175.   }
  176.   elseif ($1 == 5) {
  177.     var %i1 = $p_getitem(hold), %i2 = $p_getitem(hold), %i3 = $p_getitem(hold)
  178.     msg $chan $nick $+ : You find a stash of sweet loot! (+1 %i1 $+ , %i2 $+ , %i3 $+ )
  179.     p_item $.nick $sql_esc(%i1)
  180.     p_item $.nick $sql_esc(%i2)
  181.     p_item $.nick $sql_esc(%i3)
  182.   }
  183.   elseif ($1 == 6) {
  184.     msg $chan $nick $+ : %p spots you and attacks! You just got ownd, you need some time to rest before you can go out again.
  185.     hadd -z pokemon $.nick 180
  186.     see_pokemon $.nick %p
  187.   }
  188.   elseif ($1 isnum 7-10) {
  189.     var %i = $gettok($read(txt/pokemon/noncom.txt,$1),4,9)
  190.     msg $chan $nick $+ : You find a mysterious %i lying on the ground. (+1 %i $+ )
  191.     p_item $.nick $sql_esc(%i) +1
  192.   }
  193.   elseif ($1 isnum 11-30) || ($1 isnum 36-37) {
  194.     var %x = $read(txt/pokemon/noncom.txt,r,/^ $1 \x09/ix), %i = $gettok(%x,4,9), %c = $gettok(%x,5,9)
  195.     msg $chan $nick $+ : You are exploring $p_loc($iif($gettok(%x,2,9) == *,$.nick,$v1)).name when you meet a guy selling a %i $+ . ($ $+ $bytes(%c,b) $+ ) - [Buy] [Leave]
  196.     p_status $.nick choiceadv
  197.     p_mark $.nick $+(buy|leave*,$1,*,%i,*,%c)
  198.   }
  199.   elseif ($1 isnum 31-35) {
  200.     var %x = $read(txt/pokemon/noncom.txt,r,/^ $1 \x09/ix), %i = $gettok(%x,4,9)
  201.     msg $chan $nick $+ : You meet an old man, after a short talk he gives you a %i ( $+ $tm(%i) $+ ).
  202.     p_item $.nick %i +1
  203.   }
  204.   elseif ($1 == 38) {
  205.     var %1 = $tm(3), %2 = $tm(3), %3 = $tm(3)
  206.     msg $chan $nick $+ : You meet a traveling salesman, he has a few TM's for sale. ($50,000) - $+([,%1,] [,%2,] [,%3,]) [Leave]
  207.     p_status $.nick choiceadv
  208.     p_mark $.nick $+(%1,|,%2,|,%3,*,$1,*,50000)
  209.   }
  210. }
  211. on *:text:!visit*:#:{
  212.   if ($p_status($.nick) == ready) {
  213.     if (*pokemart* iswm $2-) {
  214.       if (!$istok($p_loc($.nick).npc,Pokemart,44)) { notice $nick There isn't a Pokemart close by! }
  215.       else {
  216.         var %b = $p_cug($.nick).ball, %p = $p_cug($.nick).potion
  217.         .notice $nick Welcome to Pokemart! Commands: !buy, !upgrade and !sell
  218.         .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 $+ ) )
  219.         .notice $nick Antidote: $!100 - Paralyze heal: $!200 -  Awakening: $!200 -  Burn heal: $!500 -  Ice heal: $!500 -  Full heal: $!1,000 -  Full restore: $!5,000
  220.         if (!$p_item($.nick,Bicycle)) { .notice $nick Bicycle: $!100,000 }
  221.       }
  222.     }
  223.     elseif (*pokecenter* iswm $2-) {
  224.       if (!$istok($p_loc($.nick).npc,Pokecenter,44)) { notice $nick There isn't a Pokecenter close by! }
  225.       else {
  226.         .notice $nick Welcome to the Pokecenter! Commands: !take and !leave to change pokemon in your team.
  227.         .notice $nick $p_team($.nick) Current team: $replace($p_team($.nick),|,$chr(32) - $chr(32))
  228.       }
  229.     }
  230.     elseif (*mall* iswm $2-) {
  231.       if (!$istok($p_loc($.nick).npc,The mall,44)) { notice $nick You aren't near The Mall! }
  232.       else {
  233.         .notice $nick Welcome to The Mall! You can buy TMs with he !buy command.
  234.         var %f = txt/pokemon/ $+ $ticks, %a
  235.         filter -ffg txt/pokemon/tms.txt %f /\x09(1)$/x
  236.         .fopen tm %f
  237.         while ($fread(tm)) {
  238.           %a = $addtok(%a,$+([,$gettok($v1,1,9),]),32)
  239.           if ($numtok(%a,32) > 14) {
  240.             .notice $nick TM's currently in stock ($20,000): %a
  241.             %a = $null
  242.           }
  243.         }
  244.         fclose tm
  245.         remove %f
  246.         .notice $nick Limited time only ($30,000): $+([,$replace($hget(pokemon,p_mall),$chr(32),] [),])
  247.       }
  248.     }
  249.     elseif (*day*care* iswm $2-) { }
  250.     elseif (*move tutor* iswm $2-) { }
  251.     elseif (*treasure hunter* iswm $2-) { }
  252.     elseif (*trick master* iswm $2-) { }
  253.     elseif (*safari hunt* iswm $2-) { }
  254.     elseif (*bug c* iswm $2-) { }
  255.     elseif (*dojo* iswm $2-) { }
  256.     elseif (*gym* iswm $2-) { }
  257.   }
  258. }
  259. on *:text:!choose*:#:{
  260.   var %a = $p_active($.nick), %p = $pokemon($2-).name, %status = $p_status($.nick)
  261.   if (!%p) { .notice $nick Unrecognized pokemon }
  262.   elseif ($2) {
  263.     if (%status == none) {
  264.       if ($istok(Bulbasaur Charmander Squirtle Pidgey Weedle Pichu Machop Abra Geodude Staryu Chikorita Cyndaquil Totodile Absol,%p,32)) {
  265.         sqlite_begin %pdb
  266.         sqlite_exec %pdb INSERT INTO p_inventory (name, cash, pokeball) VALUES (' $+ $sql_esc($.nick) $+ ', 500, 20)
  267.         sqlite_exec %pdb INSERT INTO p_badges (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  268.         sqlite_exec %pdb INSERT INTO p_pokemon (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  269.         sqlite_exec %pdb INSERT INTO p_tm (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  270.         sqlite_exec %pdb INSERT INTO p_players VALUES (' $+ $sql_esc($.nick) $+ ', $rand(1,65535) , $rand(1,65535) , ' $+ 3 3 $+ ', ' $+ %p $+ ', ' $+ %p $+ ', ' $+ ready $+ ', 0, 0, 0, '')
  271.         sqlite_exec %pdb 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))
  272.         sqlite_commit %pdb
  273.         add_pokemon $.nick $p_gen(%p,1)
  274.         hadd -z pokemon $+($.nick,.travel) 900
  275.         .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
  276.       }
  277.       else { .notice $nick That isn't a valid option. }
  278.     }
  279.     elseif (%status == ready) {
  280.       if (%a == %p) { .notice $nick %p is already your active pokemon! }
  281.       elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p }
  282.       elseif ($p_stat($.nick,%p).lvl < $p_loc($.nick).lvl) { .notice $nick %p is too weak to be out here. }
  283.       elseif (!$istok($p_team($.nick),%p,124)) { .notice $nick %p isn't in your team! You can change your team with !take and !leave when you are near a Pokecenter. }
  284.       else {
  285.         .notice $nick %p is now your active pokemon.
  286.         p_active $.nick %p
  287.       }
  288.     }
  289.   }
  290. }
  291. on *:text:!take*:#:{
  292.   if ($p_status($.nick) == ready) {
  293.     var %p = $pokemon($2).name, %t = $p_team($.nick)
  294.     if (!%p) { notice $nick Unrecognized pokemon! }
  295.     elseif (!$istok($p_loc($.nick).npc,Pokecenter,44)) { notice $nick There isnt a Pokecenter close by! }
  296.     elseif ($numtok(%t,124) >= 6) { notice $nick Your team is full! You need to !leave one first. }
  297.     elseif ($has_pokemon($.nick,%p) != has) { notice $nick You don't have a %p $+ ! }
  298.     elseif ($istok(%t,%p,124)) { notice $nick %p is already in your team! }
  299.     else {
  300.       %t = $addtok(%t,%p,124)
  301.       notice $nick You take %p with you. [Team: $replace(%t,|,$chr(32) - $chr(32)) $+ ]
  302.       p_team $.nick %t
  303.     }
  304.   }
  305. }
  306. on *:text:!leave*:#:{
  307.   if ($p_status($.nick) == ready) {
  308.     var %p = $pokemon($2).name, %t = $p_team($.nick)
  309.     if (!%p) { notice $nick Unrecognized pokemon! }
  310.     elseif (!$istok($p_loc($.nick).npc,Pokecenter,44)) { notice $nick There isn't a Pokecenter close by! }
  311.     elseif (!$istok(%t,%p,124)) { notice $nick %p isn't in your team! }
  312.     elseif (%p == $p_active($.nick)) { notice $nick You can't leave your active pokemon! }
  313.     else {
  314.       %t = $remtok(%t,%p,1,124)
  315.       notice $nick You leave %p [Team: $replace(%t,|,$chr(32) - $chr(32)) $+ ]
  316.       p_team $.nick %t
  317.     }
  318.   }
  319. }
  320. on *:text:!team:#:{
  321.   if ($p_status($.nick)) {
  322.     notice $nick $replace($p_team($.nick),|,$chr(32) - $chr(32))
  323.   }
  324. }
  325. on *:text:!give *:#:{
  326.   if ($p_status($.nick) == ready) {
  327.     var %p = $pokemon($iif($5,$2 $3,$2)).name, %i = $p_item($iif($5,$4-,$iif($p_item($3-).name,$3-,$4-))).name
  328.     if (!%i) { .notice $nick That isn't an item! }
  329.     elseif ($p_item(%i).type != hold) { .notice $nick You can't give that to him! }
  330.     elseif (!%p) { .notice $nick I think you misspelled the pokemon name, or have the name and item in the wrong order. }
  331.     elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p }
  332.     elseif (!$p_item($.nick,%i)) { .notice $nick You don't have a %i }
  333.     else {
  334.       set -l %sql SELECT item FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  335.       set -l %query $sqlite_query(%pdb,%sql)
  336.       set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  337.       sqlite_exec %pdb UPDATE $sql_esc($.nick) SET item=' $+ $sql_esc(%i) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  338.       p_item $.nick $sql_esc(%i) -1
  339.       if ($hget(pitem,item)) {
  340.         var %new = $v1
  341.         .notice $nick You exchange %p $+ 's $sql_re(%new) for your %i
  342.         p_item $.nick $sql_esc(%new)
  343.       }
  344.       else { .notice $nick You give the %i to %p }
  345.     }
  346.   }
  347.   sqlite_free %query
  348. }
  349. on $*:text:/^!travel\s(north|south|east|west)/i:#:{
  350.   if ($p_status($.nick) == ready) {
  351.     tokenize 32 $($+($!p_loc($.nick),.,$2),2)
  352.     if ($hget(pokemon,$+($.nick,.travel))) { .notice $nick You cant travel yet, You need to wait $duration($v1) }
  353.     elseif ($p_stat($.nick,$p_active($.nick)).lvl < $p_loc($1,$2).lvl) { .notice $nick You should wait until you are stronger before going to $p_loc($1,$2).name ( $+ $p_loc($1,$2).lvl $+ ) }
  354.     else {
  355.       if ($p_loc($1,$2)) && ($p_loc($.nick) != $1 $2) {
  356.         hadd -z pokemon $+($.nick,.,travel) $iif($p_item($.nick,bicycle),600,900)
  357.         p_loc $.nick $1 $2
  358.         .notice $nick You travel to $p_loc($.nick).name $+ . Points of interest: [ $+ $replace($p_loc($.nick).npc,$chr(44),] - [) $+ ]
  359.       }
  360.       else { .notice $nick You cant travel there! }
  361.     }
  362.   }
  363. }
  364. on $*:text:/^!(location|map)/:#:{
  365.   if ($p_status($.nick) == ready) {
  366.     .notice $nick $p_loc($.nick).map
  367.     .notice $nick Points of interest: [ $+ $replace($p_loc($.nick).npc,$chr(44),] - [) $+ ]
  368.   }
  369. }
  370. alias p_loc {
  371.   if ($isid) {
  372.     if (!$2) { tokenize 32 $1 }
  373.     if ($1 !isnum) {
  374.       set -l %sql SELECT loc FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  375.       set -l %query $sqlite_query(%pdb,%sql)
  376.       set -l %fetch $sqlite_fetch_row(%query,loc,$SQLITE_ASSOC)
  377.       sqlite_free %query
  378.       tokenize 32 $hget(loc,loc)
  379.       if ($hget(loc)) { hfree loc }
  380.     }
  381.     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)
  382.     if (!%x) { return 0 }
  383.     if ($prop == npc) {
  384.       var %tf = txt/pokemon/ $+ $ticks, %a
  385.       filter -ffg txt/pokemon/npc.txt %tf /(\x09|\x2C)( %x |\*)(\x09|\x2C)/x
  386.       .fopen locnpc %tf
  387.       while ($fread(locnpc)) { %a = $addtok(%a,$gettok($v1,3,9),44) }
  388.       .fclose locnpc
  389.       .remove %tf
  390.       return %a
  391.     }
  392.     if ($prop == name) { return $p_ini(area,%x) }
  393.     if ($prop == num) { return %x }
  394.     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) $+ ])  }
  395.     if ($prop == lvl) { return $p_ini(level,%x) }
  396.     if ($prop == north) && (%n) { return $calc($1 - 1) $2 }
  397.     if ($prop == east) && (%e) { return $1 $calc($2 + 1) }
  398.     if ($prop == south) && (%s) { return $calc($1 + 1) $2 }
  399.     if ($prop == west) && (%w) { return $1 $calc($2 - 1) }
  400.     if ($prop == rand) {
  401.       var %r = $1 $2 $iif(%n,$chr(44) $calc($1 - 1) $2) $iif(%e,$chr(44) $1 $calc($2 + 1)) $iif(%s,$chr(44) $calc($1 + 1) $2) $iif(%w,$chr(44) $1 $calc($2 - 1))
  402.       return $.rand(%r)
  403.     }
  404.     return $1-
  405.   }
  406.   sqlite_exec %pdb UPDATE p_players SET loc=' $+ $2- $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  407. }
  408. alias pokemon {
  409.   if (!$1) {
  410.     if ($prop) { return }
  411.     return $gettok($read(txt/pokemon/pokemon.txt),2,9)
  412.   }
  413.   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)
  414.   if ($prop == num) { return $gettok(%x,1,9) }
  415.   if ($prop == name) { return $gettok(%x,2,9) }
  416.   if ($prop == type) { return $gettok(%x,3,9) }
  417.   if ($prop == hp) { return $gettok(%x,4,9) }
  418.   if ($prop == atk) { return $gettok(%x,5,9) }
  419.   if ($prop == def) { return $gettok(%x,6,9) }
  420.   if ($prop == satk) { return $gettok(%x,7,9) }
  421.   if ($prop == sdef) { return $gettok(%x,8,9) }
  422.   if ($prop == spd) { return $gettok(%x,9,9) }
  423.   if ($prop == total) { return $gettok(%x,10,9) }
  424.   if ($prop == fmt) { return ( $+ $gettok(%x,1,9) $+ ) $gettok(%x,2,9) [Type: $gettok(%x,3,9) $+ ] }
  425.   if (stat* iswm $prop) { return $gettok(%x,3-9,9) }
  426.   else { return %x }
  427. }
  428. alias p_get {
  429.   var %f = txt/pokemon/ $+ $ticks, %a = $p_loc($.nick).num, %m
  430.   filter -ffg txt/pokemon/area.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  431.   %m = $($str( $+ $!gettok( $+ $!read( $+ %f $+ ),2,9) $!+ $!chr(44) $chr(32) ,$iif($1,$1,1)),2)
  432.   .remove %f
  433.   return %m
  434. }
  435. alias p_rare {
  436.   if ($1) {
  437.     var %x = $pokemon($1-).name
  438.     return $iif($read(txt/pokemon/rare.txt,r,/(\x09 $regescape(%x) )$/ix),$true,$false)
  439.   }
  440.   var %f = txt/pokemon/ $+ $ticks, %a = $p_loc($.nick).num
  441.   filter -ffg txt/pokemon/rare.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  442.   .timerrare 1 1 .remove %f
  443.   return $gettok($read(%f),2,9)
  444. }
  445. alias p_uncom {
  446.   if ($1) {
  447.     var %x = $pokemon($1-).name
  448.     return $iif($read(txt/pokemon/uncommon.txt,w,%x $+ *),$true,$false)
  449.   }
  450. }
  451. alias p_traded {
  452.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $2 $+ '
  453.   set -l %query $sqlite_query(%pdb,%sql)
  454.   set -l %fetch $sqlite_fetch_row(%query,traded,$SQLITE_ASSOC)
  455.   var %x = $iif($hget(traded,traded) == 1,$true,$false)
  456.   sqlite_free %query
  457.   if ($hget(traded)) { hfree traded }
  458.   return %x
  459. }
  460. alias p_exp { return $ceil($calc((7 * $1 ^ 3) / 5)) }
  461. alias p_mexp { return $ceil($calc($iif($p_traded($.nick,%p),1.5,1) * $p_bexp($1).exp * $2 / 7)) }
  462. alias p_+exp {
  463.   sqlite_begin %pdb
  464.   if ($1 == rare candy) {
  465.     var %p = $2, %exp = $calc($p_exp($calc($p_stat($.nick,%p).lvl + 1)) - $p_stat($.nick,%p).exp)
  466.     sqlite_exec %pdb UPDATE $sql_esc($.nick) SET exp=exp+ %exp WHERE pokemon=' $+ $sql_esc(%p) $+ '
  467.   }
  468.   else {
  469.     var %p = $p_active($.nick), %exp = $ceil($calc($iif($p_traded($.nick,%p),1.5,1) * $p_bexp($1).exp * $2 / 7))
  470.     sqlite_exec %pdb 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) $+ '
  471.   }
  472.   set -l %sql SELECT * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  473.   set -l %query $sqlite_query(%pdb,%sql)
  474.   set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  475.   if ($p_exp($calc($hget(pkexp,lvl) + 1)) <= $hget(pkexp,exp)) && ($hget(pkexp,lvl) < 99) {
  476.     var %lvl = $hget(pkexp,lvl) + 1, %e = $p_path(%p), %n = $gettok(%e,$calc($findtok(%e,%p,1,9) + 1),9)
  477.     if (%lvl >= $p_el(%p)) && (%lvl != 99) && ($has_pokemon($.nick,%n) != has) {
  478.       if (| isin %n) {
  479.         if (%p == Wurmple) { %n = $iif($calc($hget(pkexp,pv) % 10) < 5,Silcoon,Cascoon) }
  480.         elseif ($regex(%p,/^(Silcoon|Cascoon)$/i)) { %n = $iif(%p == Silcoon,Beautifly,Dustox) }
  481.         else {
  482.           var %x = 1, %y = $numtok(%n,124), %a, %s
  483.           while (%x <= %y) {
  484.             var %a = $gettok(%n,%x,124)
  485.             if ($sql_re($hget(pkexp,item)) == $p_ei(%a)) { %s = %a }
  486.             inc %x
  487.           }
  488.           if (!%s) { goto level }
  489.           else { %n = %s }
  490.         }
  491.       }
  492.       elseif ($p_ei(%n)) {
  493.         if ($sql_re($hget(pkexp,item)) != $p_ei(%n)) { goto level }
  494.         else { sqlite_exec %pdb UPDATE $sql_esc($.nick) SET item=' $+ $null $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ ' }
  495.       }
  496.       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))
  497.       msg $chan %p is Evolving! %p evolved in to %n
  498.       p_team $.nick $reptok($p_team($.nick),%p,%n,1,124)
  499.       sqlite_exec %pdb UPDATE $sql_esc($.nick) SET pokemon=' $+ $sql_esc(%n) $+ ', ability=' $+ $sql_esc(%ability) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  500.       sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc(%n) $+ ='1' WHERE name=' $+ $sql_esc($.nick) $+ '
  501.       sqlite_exec %pdb DELETE * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  502.       lock_pokemon $.nick %p
  503.       hadd pkexp pokemon %n
  504.       if ($p_active($.nick) == %p) { p_active $.nick %n }
  505.     }
  506.     :level
  507.     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)
  508.     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))
  509.     if ($gettok(%n,2,32)) {
  510.       inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  511.       dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  512.     }
  513.     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))),])
  514.     sqlite_exec %pdb 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) $+ '
  515.     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)
  516.     if ($p_move(%p,%lvl)) {
  517.       var %nm = $v1
  518.       if ($numtok(%mlist,44) < 4) {
  519.         msg $chan $sql_re(%p) learned %nm $+ !
  520.         sqlite_exec %pdb UPDATE $sql_esc($.nick) SET $+(m,$calc($numtok(%mlist,44) + 1)) =' $+ $sql_esc(%nm) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  521.       }
  522.       else {
  523.         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.)
  524.         p_mark $.nick $+(%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4,$chr(44),%nm)
  525.         p_status $.nick learn
  526.       }
  527.     }
  528.   }
  529.   sqlite_commit %pdb
  530.   sqlite_free %query
  531.   if ($hget(pkexp)) { hfree pkexp }
  532.   return %exp
  533. }
  534. on *:text:!forget*:#:{
  535.   if ($p_status($.nick) == learn) || ($p_status($.nick) == tm) {
  536.     var %m = $p_mark($.nick), %x = $iif($p_status($.nick) == tm,$gettok(%m,2,124),$p_mark($.nick)), %p = $iif($p_status($.nick) == tm,$gettok(%m,1,124),$p_active($.nick))
  537.     if ($istok(%x,$pokemove($2-).name,44)) { %x = $remtok(%x,$pokemove($2-).name,1,44)
  538.       .notice $nick %p 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),])
  539.       sqlite_exec %pdb 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 $+ '
  540.       p_status $.nick ready
  541.     }
  542.     else { .notice $nick That isn't a valid option. }
  543.   }
  544. }
  545. alias p_bexp {
  546.   tokenize 9 $read(txt/pokemon/ev.txt,r,/\x09 $replace($pokemon($1-).name,$chr(32),\s,$chr(40),.,$chr(41),.) \s\x09/xi)
  547.   if ($prop == exp) { return $3 }
  548.   if ($prop == hp) { return $4 }
  549.   if ($prop == atk) { return $5 }
  550.   if ($prop == def) { return $6 }
  551.   if ($prop == spatk) { return $7 }
  552.   if ($prop == spdef) { return $8 }
  553.   if ($prop == spd) { return $9 }
  554. }
  555. alias p_cr {
  556.   var %x = $read(txt/pokemon/cr.txt,w,$pokemon($1).name $+ *)
  557.   return $gettok(%x,2,9)
  558. }
  559. alias p_el {
  560.   if ($1) {
  561.     var %x = $read(txt/pokemon/level.txt,w,$pokemon($1).name $+ *)
  562.     return $iif(%x,$calc($gettok(%x,2,9) + 1),$null)
  563.   }
  564. }
  565. alias p_path {
  566.   var %p = $pokemon($1).name, %x = $read(txt/pokemon/path.txt,w,* $+ %p $+ *), %t = $calc($findtok(%x,%p,1,9) $prop 1)
  567.   if ($prop) { return $gettok(%x,%t,9) }
  568.   return %x
  569. }
  570. alias p_ml {
  571.   if ($1) {
  572.     var %x = $pokemon($1).name, %p = $p_path(%x), %t = $findtok(%p,%x,1,9) - 1
  573.     return $iif(%t,$p_el($gettok(%p,%t,9)),1)
  574.   }
  575. }
  576. alias p_ei {
  577.   if ($1) {
  578.     var %x = $pokemon($1).name
  579.     if %x { %x = $read(txt/pokemon/evolve.item.txt,w,%x $+ *) }
  580.     return $iif(%x,$gettok(%x,2,9),$null)
  581.   }
  582. }
  583. alias p_ep {
  584.   var %p = $read(txt/pokemon/path.txt,w,* $+ $pokemon($1).name $+ * )
  585.   return $($regsubex(%p,/([^\|]+?)(\x09)/g,\1->( $!+ $!p_el( $+ \1 $+ ) $!+ $!iif( $!+ $!read(txt/pokemon/evolve.item.txt,w,* $!+ $!p_path( $+ \1 $+ ).+ $!+ *) $!+ ,*) $!+ )->),3)
  586. }
  587. alias p_vs {
  588.   var %x = 1, %a1, %d1, %dam1, %a2, %d2, %dam2, %h, %m, %hp1, %hp2
  589.   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))
  590.   while (%x <= %apm1) {
  591.     var %h = $rand(1,20), %m = $rand(1,20)
  592.     if (%m > %h) || (%h < 3) { dec %apm1 }
  593.     elseif (%h == 20) { inc %apm1 }
  594.     inc %x
  595.   }
  596.   %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)
  597.   %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)
  598.   %x = 1
  599.   while (%x <= %apm2) {
  600.     var %h = $rand(1,20), %m = $rand(1,20)
  601.     if (%m > %h) || (%h < 3) { dec %apm2 }
  602.     elseif (%h == 20) { inc %apm2 }
  603.     inc %x
  604.   }
  605.   %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)
  606.   %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)
  607.   %dam1 = $bottom($calc(%a1 - %d1),1)
  608.   %dam2 = $bottom($calc(%a2 - %d2),1)
  609.   %hp1 = $calc($gettok($1,2,9) - %dam2)
  610.   %hp2 = $calc($gettok($2,2,9) - %dam1)
  611.   return $iif(%hp1 > %hp2,1,2)
  612. }
  613. alias p_battle {
  614.  
  615. }
  616. alias p_gen {
  617.   var %x, %y = $lines(txt/pokemon/ev.txt), %p = $pokemon($1).stat, %l = 1, %exp = 1, %pv = $rand(0,4294967295)
  618.   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
  619.   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 $+ *)
  620.   .fopen npc txt/pokemon/ev.txt
  621.   while (%l < $2) {
  622.     .fseek -l npc $rand(1,%y)
  623.     %x = $fread(npc)
  624.     inc %exp $floor($calc($gettok(%x,3,9) * %l / 7))
  625.     inc %evhp $gettok(%x,4,9)
  626.     inc %evatk $gettok(%x,5,9)
  627.     inc %evdef $gettok(%x,6,9)
  628.     inc %evspatk $gettok(%x,7,9)
  629.     inc %evspdef $gettok(%x,8,9)
  630.     inc %evspd $gettok(%x,9,9)
  631.     while (%exp > $p_exp($calc(%l + 1))) { inc %l }
  632.   }
  633.   set -l %sql SELECT * FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  634.   set -l %query $sqlite_query(%pdb,%sql)
  635.   set -l %fetch $sqlite_fetch_row(%query,npcmove,$SQLITE_ASSOC)
  636.   var %n = 1, %m, %physical, %status, %special, %all
  637.   while (%n <= $2) {
  638.     if ($hget(npcmove,$+(l,%n))) {
  639.       %m = $hget(npcmove,$+(l,%n))
  640.       %all = $addtok(%all,%m,9)
  641.       var % $+ $pokemove(%m).cat $addtok($($+(%,$pokemove(%m).cat),2),%m,9)
  642.     }
  643.     inc %n
  644.   }
  645.   var %m
  646.   if ($numtok(%all,9) <= 4) { var %c = $numtok(%all,9), %m = %all $+ $str($chr(9),$calc(4 - %c)) }
  647.   else {
  648.     while ($numtok(%m,9) < 4) { %m = $addtok(%m,$p_movesel($1,%all),9) }
  649.   }
  650.   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))
  651.   if ($gettok(%n,2,32)) {
  652.     inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  653.     dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  654.   }
  655.   .fclose npc
  656.   sqlite_free %query
  657.   if ($hget(npcmove)) { hfree npcmove }
  658.   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)
  659. }
  660. alias p_move {
  661.   set -l %sql SELECT l $+ $2 FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  662.   set -l %query $sqlite_query(%pdb,%sql)
  663.   set -l %fetch $sqlite_fetch_row(%query,pkmove,$SQLITE_ASSOC)
  664.   var %x = $hget(pkmove,l $+ $2)
  665.   sqlite_free %query
  666.   if ($hget(pkmove)) { hfree pkmove }
  667.   return $iif(%x,$v1,$null)
  668. }
  669. alias add_pokemon {
  670.   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
  671.   sqlite_begin %pdb
  672.   if ($has_pokemon($1,$gettok($2-,1,9)) == has) {
  673.     .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?
  674.     .notice $nick Old: $p_statfmt($1,$p_stat($1,$gettok($2-,1,9)))
  675.     .notice $nick New: $p_statfmt($1,$2-)
  676.     p_mark $1 $replace($2-,$chr(9),*)
  677.     p_status $1 replace
  678.     return
  679.   }
  680.   var %t = $p_team($1)
  681.   if ($numtok(%t,124) < 6) {
  682.     p_team $1 $addtok(%t,$gettok($2,1,9),124)
  683.   }
  684.   noop $p_+exp($gettok($2-,1,9),$gettok($filltok($2-,-,9),11,9))
  685.   sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($gettok($2,1,9)) $+ ='1' WHERE name=' $+ $sql_esc($1) $+ '
  686.   sqlite_exec %pdb INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  687.   sqlite_commit %pdb
  688. }
  689. on *:text:!keep:#:{
  690.   if ($p_status($.nick) == replace) {
  691.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  692.     .notice $nick You keep the new %p and set your old one free.
  693.     p_status $.nick ready
  694.     replace_pokemon $.nick %x
  695.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  696.   }
  697. }
  698. on *:text:!release:#:{
  699.   if ($p_status($.nick) == replace) {
  700.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  701.     .notice $nick You keep your %p and let the new one go.
  702.     p_status $.nick ready
  703.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  704.   }
  705. }
  706. alias replace_pokemon {
  707.   var %p = $gettok($2-,1,42), %x = $replace($sql_esc($2-),$chr(42),' $+ $chr(44) $+ ')
  708.   sqlite_exec %pdb DELETE FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  709.   sqlite_exec %pdb INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  710. }
  711. alias see_pokemon {
  712.   if (!$has_pokemon($1,$2)) {
  713.     sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='s' WHERE name=' $+ $sql_esc($1) $+ '
  714.   }
  715. }
  716. alias lock_pokemon {
  717.   sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='x' WHERE name=' $+ $sql_esc($1) $+ '
  718. }
  719. alias has_pokemon {
  720.   set -l %sql SELECT $sql_esc($2) FROM p_pokemon WHERE name=' $+ $sql_esc($1) $+ '
  721.   set -l %query $sqlite_query(%pdb,%sql)
  722.   set -l %fetch $sqlite_fetch_row(%query,haspkm,$SQLITE_ASSOC)
  723.   sqlite_free %query
  724.   var %x = $replacex($hget(haspkm,$sql_esc($2)),1,has,x,had,s,seen)
  725.   if ($hget(haspkm)) { hfree haspkm }
  726.   return %x
  727. }
  728. alias trade_pokemon { }
  729.  
  730. on *:text:!buy*:#:{
  731.   if ($p_status($.nick) == ready) {
  732.     var %t = $iif($2 isnum,$3-,$2-), %c
  733.     if (TM* iswm %t) {
  734.       if (!$istok($p_loc($.nick).npc,The Mall,44)) { notice $nick You aren't near The Mall! }
  735.       else {
  736.         if ($tm(%t).r == 1) {
  737.           %c = $iif($2 isnum,$2,1)
  738.           if ($p_item($.nick,cash) >= $calc(%c * 20000)) {
  739.             .notice $nick You buy $iif($2 isnum,$2 $upper(%t) $+ s,a $upper(%t))
  740.             p_item $.nick %t + $+ %c
  741.             p_item $.nick cash - $+ $calc(20000 * %c)
  742.           }
  743.           else { .notice $nick You don't have enough cash! }
  744.         }
  745.         elseif ($tm(%t).r == 2) {
  746.           var %m = $hget(pokemon,p_mall)
  747.           if (!$istok(%m,$2,32)) { .notice $nick That isn't for sale! }
  748.           elseif ($2 isnum) { .notice $nick We only have 1 $upper($3) in stock. }
  749.           else {
  750.             if ($p_item($.nick,cash) >=30000) {
  751.               .notice $nick You buy a $upper(%t)
  752.               p_item $.nick %t +1
  753.               p_item $.nick cash -30000
  754.               %m = $replace(%m,$2,$tm(2))
  755.               hadd pokemon p_mall $dupe(%m)
  756.             }
  757.           }
  758.         }
  759.         else { .notice $nick That isn't for sale! }
  760.       }
  761.     }
  762.     else {
  763.       if (!$istok($p_loc($.nick).npc,Pokemart,44)) { notice $nick There isn't a Pokemart close by! }
  764.       else {
  765.         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)) {
  766.           if (*ball* iswm %t) { %t = $p_cug($.nick).ball }
  767.           if (*potion* iswm %t) { %t = $p_cug($.nick).potion }
  768.           %c = $iif($2 isnum,$calc($p_item(%t).cost * $2),$p_item(%t).cost)
  769.           if ($p_item($.nick,cash) >= %c) {
  770.             if (%t == bicycle) && ($p_item($.nick,bicycle)) { .notice $nick You already have a Bicycle! }
  771.             else {
  772.               .notice $nick You buy $iif($2 isnum,$2 %t $+ s,a %t)
  773.               if (*ball* iswm %t) { p_item $.nick Pokeball $iif($2 isnum,+ $+ $2) }
  774.               elseif (*potion* iswm %t) { p_item $.nick Potion $iif($2 isnum,+ $+ $2) }
  775.               else { p_item $.nick $sql_esc($p_item(%t).name) $iif($2 isnum,+ $+ $2) }
  776.               p_item $.nick cash - $+ %c
  777.             }
  778.           }
  779.           else { .notice $nick You don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  780.         }
  781.         else { .notice $nick You can't buy that! }
  782.       }
  783.     }
  784.   }
  785. }
  786. on $*:text:/^!upgrade\s(.*)(ball|potion)(.*)/:#:{
  787.   if ($p_status($.nick) == ready) {
  788.     if (!$istok($p_loc($.nick).npc,Pokemart,44)) { notice $nick There isn't a Pokemart close by! }
  789.     else {
  790.       var %x, %c
  791.       if (*ball* iswm $2) { %x = $p_cug($.nick).ball }
  792.       elseif (*potion* iswm $2) { %x = $p_cug($.nick).potion }
  793.       %c = $calc($p_iug(%x).cost + $p_item($.nick,$iif(*ball* iswm $2,pokeball,potion)) * $p_item($iif(*ball* iswm $2,pokeball,potion)).cost)
  794.       if ($p_iug(%x)) {
  795.         if ($p_item($.nick,cash) >= %c) {
  796.           p_item $.nick $sql_esc($p_iug(%x))
  797.           p_item $.nick cash - $+ %c
  798.           .notice $nick You upgrade your %x to $p_iug(%x)
  799.         }
  800.         else { .notice $nick you don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  801.       }
  802.       else { .notice $nick You can't upgrade that! }
  803.     }
  804.   }
  805. }
  806. on *:text:!sell*:#:{
  807.   if ($p_status($.nick) == ready) {
  808.     if (!$istok($p_loc($.nick).npc,Pokemart,44)) { notice $nick There isn't a Pokemart close by! }
  809.     var %i = $p_item($iif($2 isnum,$3-,$2-)).name, %n = $iif($2 isnum,$2,1), %c = $calc(($p_item(%i).cost * .1) * %n)
  810.     if ($p_item($.nick,%i) >= %n) {
  811.       .notice $nick You sell %n %i $+ $iif(%n > 1,$+ 's) for $ $+ %c $+ .
  812.       p_item $.nick $sql_esc(%i) - $+ %n
  813.       p_item $.nick cash + $+ %c
  814.     }
  815.     else { .notice $nick You don't have that many! }
  816.   }
  817. }
  818.  
  819. on *:text:!inventory*:#:{
  820.   if ($p_status($.nick) == ready) {
  821.     if ($regex($2,/(T|H)Ms?/i)) {
  822.       set -l %sql SELECT * FROM p_tm WHERE name=' $+ $sql_esc($.nick) $+ '
  823.       set -l %query $sqlite_query(%pdb,%sql)
  824.       set -l %fetch $sqlite_fetch_row(%query,pinv,$SQLITE_ASSOC)
  825.       sqlite_free %query
  826.       var %x = 1, %y = $hget(pinv,0).item, %m, %t
  827.       while (%x <= %y) {
  828.         if ($hget(pinv,%x).item != name) && ($hget(pinv,$hget(pinv,%x).item)) { %m = $addtok(%m,$chr(32) $hget(pinv,%x).item ( $+ $v1 $+ ) $chr(32),45) }
  829.         if ($numtok(%m,45) > 9) {
  830.           .notice $nick $sql_re(%m)
  831.           %m = $null
  832.           inc %t
  833.         }
  834.         inc %x
  835.       }
  836.       if (%m) { .notice $nick $sql_re(%m) }
  837.       elseif (!%t) { .notice $nick You don't have any TM's. }
  838.     }
  839.     else {
  840.       set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($.nick) $+ '
  841.       set -l %query $sqlite_query(%pdb,%sql)
  842.       set -l %fetch $sqlite_fetch_row(%query,pinv,$SQLITE_ASSOC)
  843.       sqlite_free %query
  844.       if (!$2) {
  845.         .notice $nick Cash $ $+ $bytes($hget(pinv,cash),b) - $p_cug($.nick).ball ( $+ $hget(pinv,pokeball) $+ ) - $p_cug($.nick).potion ( $+ $hget(pinv,potion) $+ )
  846.         .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) $+ )
  847.         var %m = $iif($hget(pinv,bicycle),Bicycle ( $+ $v1 $+ ) ) $iif($hget(pinv,Masterball),Masterball ( $+ $v1 $+ ) ) $iif($hget(pinv,Rare_32candy),Rare Candy ( $+ $v1 $+ ) ) $iif($hget(pinv,Gold_32Nugget),Gold Nugget ( $+ $v1 $+ ) )
  848.         if (%m) { .notice $nick $regsubex(%m,/(\x29)\s(.)/,\1 - \2) }
  849.       }
  850.       else {
  851.         var %x = 1, %n, %m, %i
  852.         if (*ball* iswm $2) { %i = Pokeball,Masterball }
  853.         if (* $+ $2 $+ * iswm *equipment*hold*) { %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 }
  854.         elseif (spec* iswm $2) { %i = Bicycle,Rare_32candy,Gold_32nugget,Blue_32shard,Red_32shard,Yellow_32shard,Green_32shard }
  855.         while (%x <= $numtok(%i,44)) {
  856.           %n = $gettok(%i,%x,44)
  857.           if ($hget(pinv,%n)) { %m = $addtok(%m,$chr(32) $iif(%n == Pokeball,$p_cug($.nick).ball,%n) ( $+ $hget(pinv,%n) $+ ) $chr(32),45) }
  858.           if ($numtok(%m,45) > 7) {
  859.             .notice $nick $sql_re(%m)
  860.             %m = $null
  861.           }
  862.           inc %x
  863.         }
  864.         if (%m) { .notice $nick $sql_re(%m) }
  865.       }
  866.     }
  867.   }
  868. }
  869. on *:text:!use*:#:{
  870.   if ($p_status($.nick) == ready) {
  871.     var %p = $pokemon($iif($4,$4-,$3-)).name, %i = $p_item($iif($4,$iif($p_item($2 $3).name,$2 $3,$2),$2)).name
  872.     if (!%p) { .notice $nick That isn't a pokemon! }
  873.     elseif (!%i) { .notice $nick That isn't an item! }
  874.     elseif ($p_item($.nick,%i) < 1) { .notice $nick You don't have a %i $+ ! }
  875.     elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p $+ ! }
  876.     else {
  877.       if (%i == rare candy) {
  878.         noop $p_+exp(rare candy,%p)
  879.         p_item $.nick Rare_32candy -1          
  880.       }
  881.       elseif ($regex($2,/(T|H)M\d\d/i)) {
  882.         if (%i !isin $read(txt/pokemon/tmcom.txt,w,%p $+ *)) { .notice $nick %p can't learn that! }
  883.         else {
  884.           set -l %sql SELECT * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  885.           set -l %query $sqlite_query(%pdb,%sql)
  886.           set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  887.           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)
  888.           var %nm = $tm(%i)
  889.           if ($istok($sql_re(%mlist),%nm,44)) { .notice $nick %p already knows that move! }
  890.           else {
  891.             p_item $.nick %i -1
  892.             if ($numtok(%mlist,44) < 4) {
  893.               msg $chan $sql_re(%p) learned %nm $+ !
  894.               sqlite_exec %pdb UPDATE $sql_esc($.nick) SET $+(m,$calc($numtok(%mlist,44) + 1)) =' $+ $sql_esc(%nm) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  895.             }
  896.             else {
  897.               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.)
  898.               p_mark $.nick $+(%p,|,%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4,$chr(44),%nm)
  899.               p_status $.nick tm
  900.             }
  901.           }
  902.         }
  903.       }
  904.       else { .notice $nick That doesn't do anything }
  905.     }
  906.   }
  907. }
  908. on *:text:!pokeitem*:#:{
  909.   if ($p_status($.nick) == ready) {
  910.     if ($p_item($2-).name) {
  911.       tokenize 9 $p_item($2-).desc
  912.       msg $chan $1 [Type: $2 $+ ] $6
  913.     }
  914.   }
  915. }
  916. alias p_getitem {
  917.   set -l %sql SELECT name FROM p_items WHERE type LIKE $+('%,$1,$(%',0)) ORDER BY RANDOM() LIMIT 1
  918.   set -l %query $sqlite_query(%pdb,%sql)
  919.   set -l %fetch $sqlite_fetch_row(%query,pgitem,$SQLITE_ASSOC)
  920.   sqlite_free %query
  921.   var %x = $sql_re($hget(pgitem,name))
  922.   if ($hget(pgitem)) { hfree pgitem }
  923.   return %x
  924. }
  925. alias p_item {
  926.   var %t = $iif($regex($2,/^(T|H)M/i),p_tm,p_inventory), %f = $iif($regex($1,/^(T|H)M/i),txt/pokemon/tms.txt,txt/pokemon/items.txt)
  927.   if ($isid) {
  928.     if ($prop == name) { return $gettok($read(%f,w,* $+ $1 $+ *),1,9) }
  929.     if ($prop == type) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),2,9) }
  930.     if ($prop == cost) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),3,9) }
  931.     if ($prop == desc) { return $read(txt/pokemon/items.txt,w,* $+ $1 $+ *) }
  932.     set -l %sql SELECT $sql_esc($2) FROM %t WHERE name=' $+ $sql_esc($1) $+ '
  933.     set -l %query $sqlite_query(%pdb,%sql)
  934.     set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  935.     sqlite_free %query
  936.     var %x = $hget(pitem,$sql_esc($2))
  937.     if ($hget(pitem)) { hfree pitem }
  938.     return %x
  939.   }
  940.   sqlite_exec %pdb UPDATE %t SET $sql_esc($2) $+ = $sql_esc($2) $iif($3,$3,+1) WHERE name=' $+ $sql_esc($1) $+ '
  941. }
  942. alias p_iug {
  943.   if ($prop == cost) { var %x = $replacex($1,Pokeball,10000,Greatball,20000,Potion,5000,Super Potion,25000,Hyper Potion,50000) }
  944.   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) }
  945.   return %x
  946. }
  947. alias p_cug {
  948.   set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($1) $+ '
  949.   set -l %query $sqlite_query(%pdb,%sql)
  950.   set -l %fetch $sqlite_fetch_row(%query,pcug,$SQLITE_ASSOC)
  951.   var %x = $iif($prop == ball,Pokeball,Potion)
  952.   while ($hget(pcug,$sql_esc($p_iug(%x)))) { %x = $p_iug(%x) }
  953.   if ($hget(pcug)) { hfree pcug }
  954.   sqlite_free %query
  955.   return %x
  956. }
  957. alias p_bmod {
  958.   set -l %sql SELECT mod FROM p_items WHERE name=" $+ $sql_esc($1) $+ "
  959.   set -l %query $sqlite_query(%pdb,%sql)
  960.   set -l %fetch $sqlite_fetch_row(%query,pbmod,$SQLITE_ASSOC)
  961.   var %x = $hget(pbmod,mod)
  962.   if ($hget(pcug)) { hfree pcug }
  963.   sqlite_free %quest
  964.   return %x
  965. }
  966. alias p_type {
  967.   if (/ isin $1) { return $max($p_typex($gettok($1,1,47),$2),$p_typex($gettok($1,2,47),$2)) }
  968.   else { return $p_typex($1,$2) }
  969. }
  970. alias p_typex {
  971.   set -l %sql SELECT * FROM p_types WHERE type=' $+ $1 $+ '
  972.   set -l %query $sqlite_query(%pdb,%sql)
  973.   set -l %fetch $sqlite_fetch_row(%query,ptype,$SQLITE_ASSOC)
  974.   sqlite_free %query
  975.   tokenize 47 $2
  976.   if ($2) {
  977.     var %x = $calc($hget(ptype,$1) + $hget(ptype,$2))
  978.     return $p_typec(%x).dual
  979.   }
  980.   else { return $p_typec($hget(ptype,$1)) }
  981. }
  982. alias p_typec {
  983.   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) }
  984.   return $replacex($1,1,0,2,.5,4,1,8,2)
  985. }
  986. on *:text:!pokemon:#:{
  987.   var %a
  988.   set -l %sql SELECT pokemon, lvl, pv FROM $sql_esc($.nick) ORDER BY lvl
  989.   set -l %query $sqlite_query(%pdb,%sql)
  990.   while ($sqlite_fetch_row(%query,listp,$SQLITE_ASSOC)) {
  991.     whilefix
  992.     %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)
  993.     if ($numtok(%a,44) > 24) {
  994.       .notice $nick %a
  995.       %a = $null
  996.     }
  997.   }
  998.   if (%a) { .notice $nick %a }
  999.   sqlite_free %query
  1000. }
  1001. on $*:text:/^!(poke)?dex(stat)?\s/:#:{
  1002.   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$)/,)
  1003.   if (%x) {
  1004.     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) $+ ]  }
  1005.     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 $+ ]) }
  1006.   }
  1007. }
  1008. on *:text:!pokestat*:#:{
  1009.   if ($p_status($.nick)) {
  1010.     if ($2) && ($has_pokemon($.nick,$2) != has) { .notice $nick You don't have a $2 $+ , $.nick $+ . }
  1011.     else { msg $chan $p_statfmt($.nick,$p_stat($.nick,$iif($2,$pokemon($2).name,$p_active($.nick)))) }
  1012.   }
  1013. }
  1014. alias p_statfmt {
  1015.   tokenize 9 $1 $chr(9) $sql_re($filltok($replace($2,*,$chr(9)),-,9))
  1016.   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) $+ ])
  1017. }
  1018. alias p_stat {
  1019.   var %x = $pokemon($2).name, %t = txt/pokemon/ $+ $ticks
  1020.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%x) $+ '
  1021.   set -l %query $sqlite_query(%pdb,%sql)
  1022.   set -l %fetch $sqlite_fetch_all(%query,%t)
  1023.   if (!%fetch) { return error %sqlite_errstr }
  1024.   sqlite_free %query
  1025.   .timer 1 1 .remove %t
  1026.   %x = $filltok($read(%t,1),-,9)
  1027.   if ($prop == lvl) { return $gettok(%x,11,9) }
  1028.   if ($prop == exp) { return $gettok(%x,12,9) }
  1029.   if ($prop == vs) { return $pokemon($gettok(%x,1,9)).type $+ $chr(9) $+ $gettok(%x,13-18,9) }
  1030.   return %x
  1031. }
  1032. on *:text:!pokemove*:#:{
  1033.   tokenize 44 $replace($2-,*,.+?)
  1034.   if ($len($1) >= 3) {
  1035.     filter -cffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($1,/(\s)/g,.*) )(.+?)/ix
  1036.     if ($len($2) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($2,/(\s)/g,.*) )(.+?)/ix }
  1037.     if ($len($3) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($3,/(\s)/g,.*) )(.+?)/ix }
  1038.     if ($len($4) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($4,/(\s)/g,.*) )(.+?)/ix }
  1039.     .fopen pmove txt/pokemon/temp.txt
  1040.     while ($fread(pmove)) { msg $chan $pokemove($v1) }
  1041.     .fclose pmove
  1042.   }
  1043. }
  1044. alias pokemove {
  1045.   if ($2) { var %t = $2 }
  1046.   tokenize 9 $read(txt/pokemon/attacks.txt,w,$1 $+ *)
  1047.   if ($prop == name) { return $1 }
  1048.   if ($prop == type) { return $2 }
  1049.   if (cat* iswm $prop) { return $3 }
  1050.   if ($prop == power) { return $4 }
  1051.   if (acc* iswm $prop) { return $5 }
  1052.   if ($prop == pp) { return $6 }
  1053.   if ($prop == effect) { return $7 }
  1054.   if (prob* iswm $prop) { return $8 }
  1055.   if ($prop == rating) {
  1056.     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))
  1057.   }
  1058.   if ($1) {
  1059.     return $1 [Type: $2 $+ ] [Catagory: $3 $+ ] $iif($4 != -,[Power: $4 $+ ]) $iif($5 != -,[Accuracy: $5 $+ ]) [PP: $6 $+ ] $iif($7 != -,[Effect: $iif($8 != -,$8 $+ % chance -) $7 $+ ])
  1060.   }
  1061. }
  1062. on $*:text:/^!((T|H)M\d\d)$/i:#:{
  1063.   msg $chan ( $+ $upper($regml(1)) $+ ) $pokemove($tm($regml(1)))
  1064. }
  1065. alias tm {
  1066.   if ($1 isnum 1-3) {
  1067.     var %f = txt/pokemon/ $+ $ticks, %a
  1068.     filter -ffg txt/pokemon/tms.txt %f /\x09( $1 )$/x
  1069.     %a = $read(%f)
  1070.     .remove %f
  1071.     return $gettok(%a,1,9)
  1072.   }
  1073.   tokenize 9 $read(txt/pokemon/tms.txt,w,$1 $+ *)
  1074.   if ($prop == r) { return $3 }
  1075.   if ($1) { return $2 }
  1076. }
  1077. on *:text:!ability*:#:{
  1078.   tokenize 9 $read(txt/pokemon/ability.txt,w,$2- $+ *)
  1079.   if ($1) { msg $chan $1 $+ : $2 }
  1080. }
  1081. on *:text:!nature*:#:{
  1082.   tokenize 32 $replace($read(txt/pokemon/nature.txt,wn,$2- $+ *),%,$null)
  1083.   if ($1) { msg $chan $1 $+ : $iif($2,+ $+ $2 - $+ $3,No effect) }
  1084. }
  1085. alias p_movesel {
  1086.   var %x = 1, %y = $numtok($2-,9), %t = $pokemon($1).type, %a, %cr, %m, %r = 0
  1087.   while (%x <= %y) {
  1088.     %a = $gettok($2-,%x,9)
  1089.     %cr = $pokemove(%a,%t).rating
  1090.     if (%cr > %r) { var %m = %a, %r = %cr }
  1091.     inc %x
  1092.   }
  1093.   return %m
  1094. }
  1095. alias p_shiny {
  1096.   if (!$3) {
  1097.     set -l %sql SELECT id, sid FROM p_players WHERE name=" $+ $sql_esc($1) $+ "
  1098.     set -l %query $sqlite_query(%pdb,%sql)
  1099.     set -l %fetch $sqlite_fetch_row(%query,pshiny,$SQLITE_ASSOC)
  1100.     tokenize 32 $hget(pshiny,id) $hget(pshiny,sid) $2
  1101.   }
  1102.   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)))
  1103.   if (%x < 8) { msg #Flip shiny! }
  1104.   return $iif(%x < 8,Shiny)
  1105. }
  1106. alias p_height {
  1107.   noop $read(txt/pokemon/height.txt,w,* $+ $1- $+ *)
  1108.   return $gettok($read(txt/pokemon/height.txt,$readn),1,9)
  1109. }
  1110. alias p_weight { return $gettok($read(txt/pokemon/weight.txt,w,$1- $+ *),2,9) }
  1111. alias p_active {
  1112.   if ($isid) { return $p_player($1,active) }
  1113.   sqlite_exec %pdb UPDATE p_players SET active=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1114. }
  1115. alias p_team {
  1116.   if ($isid) { return $p_player($1,team) }
  1117.   sqlite_exec %pdb UPDATE p_players SET team=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1118. }
  1119. alias p_status {
  1120.   if ($isid) { return $p_player($1,status) }
  1121.   sqlite_exec %pdb UPDATE p_players SET status=' $+ $sql_esc($2) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1122. }
  1123. alias p_mark {
  1124.   if ($isid) { return $p_player($1,mark) }
  1125.   sqlite_exec %pdb UPDATE p_players SET mark=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1126. }
  1127. alias p_ps {
  1128.   if ($isid) { return $p_player($1,$2) }
  1129.   sqlite_exec %pdb UPDATE p_players SET $2 = $2 + 1 WHERE name=' $+ $sql_esc($1) $+ '
  1130. }
  1131. alias p_player {
  1132.   set -l %sql SELECT $2 FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  1133.   set -l %query $sqlite_query(%pdb,%sql)
  1134.   set -l %fetch $sqlite_fetch_row(%query,player,$SQLITE_ASSOC)
  1135.   var %x = $iif($sql_re($hget(player,$2)),$v1,none)
  1136.   sqlite_free %query
  1137.   if ($hget(player)) { hfree player }
  1138.   return %x
  1139. }
  1140. alias p_noncom { return $p_ini(cr,$1) }
  1141. alias p_ini {
  1142.   if ($isid) { return $readini(txt/pokemon/pokemon.ini,$1,$2) }
  1143.   else { writeini txt/pokemon/pokemon.ini $1 $2 $3 }
  1144. }
  1145. on *:text:*:#:{  
  1146.   if ($p_status($.nick) == choiceadv) && ($regex($1-,/^( $gettok($p_mark($.nick),1,42) )$/ix)) {
  1147.     var %m = $p_mark($.nick), %adv = $gettok(%m,2,42)
  1148.     if ($1 == leave) {
  1149.       msg $chan $nick $+ : You decide to leave and continue exploring.
  1150.       p_status $.nick ready
  1151.     }
  1152.     elseif (%adv isnum 11-30) || (%adv isnum 36-37) {
  1153.       var %i = $gettok(%m,3,42), %c = $gettok(%m,4,42)
  1154.       if ($1 == buy) {
  1155.         if ($p_item($.nick,cash) >= %c) {
  1156.           msg $chan $nick $+ : You buy the %i and continue on your journey.
  1157.           p_item $.nick $sql_esc(%i) +1
  1158.           p_item $.nick cash - $+ %c
  1159.           p_status $.nick ready
  1160.         }
  1161.         else { msg $chan $nick $+ : You don't have enough cash, so you continue on your journey. }
  1162.       }
  1163.     }
  1164.     elseif (%adv == 38) {
  1165.       var %c = $gettok(%m,3,42)
  1166.       if ($p_item($.nick,cash) > %c) {
  1167.         msg $chan $nick $+ : You buy the $upper($1) and continue on your journey.
  1168.         p_item $.nick $upper($1) +1
  1169.         p_item $.nick cash - $+ %c
  1170.         p_status $.nick ready
  1171.       }
  1172.       else { msg $chan $nick $+ : You don't have enough cash, so you continue on your journey. }
  1173.     }
  1174.   }
  1175. }
  1176. #pokemon end
  1177. alias p_reset {
  1178.   var %x = $iif($.nick($1).check,$.nick($1),$1)
  1179.   sqlite_exec %pdb DELETE FROM p_pokemon WHERE name=' $+ $sql_esc(%x) $+ '
  1180.   sqlite_exec %pdb DELETE FROM p_players WHERE name=' $+ $sql_esc(%x) $+ '
  1181.   sqlite_exec %pdb DELETE FROM p_inventory WHERE name=' $+ $sql_esc(%x) $+ '
  1182.   sqlite_exec %pdb DELETE FROM p_badges WHERE name=' $+ $sql_esc(%x) $+ '
  1183.   sqlite_exec %pdb DROP TABLE $sql_esc(%x)
  1184.   msg $chan %x reset
  1185. }
  1186. alias db_additem {
  1187.   var %a = $read(txt/pokemon/items.txt,w,$1- $+ *)
  1188.   sqlite_exec %pdb ALTER TABLE p_inventory ADD $sql_esc($1-) varchar(3) default 0
  1189.   sqlite_exec %pdb INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1190. }
  1191. alias db_flushitems {
  1192.   sqlite_exec %pdb DROP TABLE p_items
  1193.   sqlite_exec %pdb CREATE TABLE p_items (name varchar(20), type varchar(20), cost varchar(10), mod varchar(10), effect varchar(15), desc varchar(200))
  1194.   var %x = 1, %y = $lines(txt/pokemon/items.txt), %a
  1195.   while (%x <= %y) {
  1196.     %a = $read(txt/pokemon/items.txt,%x)
  1197.     sqlite_exec %pdb INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1198.     inc %x
  1199.   }
  1200. }
  1201. alias _pdb {
  1202.  
  1203. }
  1204. alias gendb {
  1205.   var %sql.db = $sqlite_open(txt/pokemon/pokemon.new.db3)
  1206.   sqlite_begin %sql.db
  1207.   sqlite_exec %sql.db CREATE TABLE p_players (name varchar(20), id varcahr(6), sid varchar(6), loc varchar(5), active varchar(20), team varchar(150), status varchar(10), attempts varchar(7), battles varchar(3), wins varchar(7), mark varchar(250))
  1208.   sqlite_exec %sql.db CREATE TABLE p_badges (name varchar(20))
  1209.   sqlite_exec %sql.db CREATE TABLE p_pokemon (name varchar(20))
  1210.   var %x = 1, %y = $lines(txt/pokemon/pokemon.txt), %a
  1211.   while (%x <= %y) {
  1212.     %a = $gettok($read(txt/pokemon/pokemon.txt,%x),2,9)
  1213.     sqlite_exec %sql.db ALTER TABLE p_pokemon ADD $sql_esc(%a) char(1)
  1214.     inc %x
  1215.   }
  1216.   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))
  1217.   var %x = 2, %y = $lines(txt/pokemon/resource/chart.txt), %a
  1218.   while (%x <= %y) {
  1219.     %a = $replace($read(txt/pokemon/resource/chart.txt,%x),;,' $+ $chr(44) $+ ')
  1220.     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 $+ ')
  1221.     inc %x
  1222.   }
  1223.   sqlite_exec %sql.db CREATE TABLE p_inventory (name varchar(20), Cash varchar(20))
  1224.   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))
  1225.   var %x = 1, %y = $lines(txt/pokemon/items.txt), %a
  1226.   while (%x <= %y) {
  1227.     %a = $read(txt/pokemon/items.txt,%x)
  1228.     sqlite_exec %sql.db ALTER TABLE p_inventory ADD $sql_esc($gettok(%a,1,9)) varchar(3) default 0
  1229.     sqlite_exec %sql.db INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1230.     inc %x
  1231.   }
  1232.   var %x = 1, %y = $lines(txt/pokemon/tms.txt), %a
  1233.   sqlite_exec %sql.db CREATE TABLE p_tm (name varchar(20))
  1234.   while (%x <= %y) {
  1235.     %a = $gettok($read(txt/pokemon/tms.txt,%x),1,9)
  1236.     sqlite_exec %sql.db ALTER TABLE p_tm ADD %a varchar(3) default 0
  1237.     inc %x
  1238.   }
  1239.   sqlite_exec %sql.db CREATE TABLE p_learnset (name varchar(50))
  1240.   %x = 1
  1241.   while (%x <= 99) {
  1242.     sqlite_exec %sql.db ALTER TABLE p_learnset ADD l $+ %x varchar(20)
  1243.     inc %x
  1244.   }
  1245.   var %x = 1, %y = $lines(txt/pokemon/learnset.txt), %a, %n, %t
  1246.   while (%x <= %y) {
  1247.     %a = $read(txt/pokemon/learnset.txt,%x)
  1248.     tokenize 9 %a
  1249.     %n = 1
  1250.     %t = $numtok($2,44)
  1251.     sqlite_exec %sql.db INSERT INTO p_learnset (name) VALUES (' $+ $replace($sql_esc($1),_44,*) $+ ')
  1252.     while (%n <= %t) {
  1253.       sqlite_exec %sql.db UPDATE p_learnset SET l $+ $replace($gettok($2,%n,44),|,=') $+ ' WHERE name=' $+ $replace($sql_esc($1),_44,*) $+ '
  1254.       inc %n
  1255.     }
  1256.     inc %x
  1257.   }
  1258.   sqlite_commit %sql.db
  1259.   sqlite_close %sql.db
  1260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement