Advertisement
Flip

Pokemon irc

Jul 2nd, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 83.86 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:%chans:{
  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 (%status == learn) { .notice $nick %a has too many moves! $+([,$sql_re($p_mark($.nick)),]) Type !forget <move> }
  31.     elseif (%status == replace) {
  32.       tokenize 9 $.nick $+ $chr(9) $+ $p_mark($.nick)
  33.       .notice $nick You caught $gettok($2-,1,42) but you already have a $gettok($2-,1,42) $+ ! Do you want to !keep or !release the new one?
  34.       .notice $nick Old: $p_statfmt($1,$p_stat($1,$gettok($2-,1,42)))
  35.       .notice $nick New: $p_statfmt($1,$2-)
  36.     }
  37.     elseif (%status == choiceadv) { choiceadv $gettok($p_mark($.nick),2,42) }
  38.     elseif ($hget(pokemon,$.nick)) { .notice $nick All the pokemon ran away, Try again later. ( $+ $v1 sec $+ ) }
  39.     elseif (%status == ready) {
  40.       if ($p_daycare($.nick) != none) { p_+daycare $.nick }
  41.       hadd -z pokemon $.nick $iif($istok(%punish,$.nick,44),150,$iif($p_item($.nick,Bicycle),45,60))
  42.       hinc pokemon p_attempt
  43.       if ($calc($hget(pokemon,p_attempt) % 10) == 0) && ($rand(1,100) < 80) { hadd pokemon p_salesman $p_loc($hget(pokemon,p_salesman)).rand }
  44.       if ($calc($hget(pokemon,p_attempt) % 100) == 0) {
  45.         var %t = $tm(2) $tm(2) $tm(2) $tm(2) $tm(2) $tm(2)
  46.         hadd pokemon p_mall $dupe(%t)
  47.       }
  48.       p_ps $.nick attempts
  49.       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
  50.       if (%x != 0) && ($calc($rand(0,100000) % 100) <= $p_noncom(%loc)) {
  51.         var %tf = txt/pokemon/nc $+ $ticks , %cadv, %a
  52.         filter -ffg txt/pokemon/noncom.txt %tf /(\x09|\x2C)( %loc |\*)(\x09|\x2C)/x
  53.         while (!%cadv) {
  54.           var %a = $read(%tf)
  55.           if (!$gettok(%a,3,9)) || ($rand(1,100) > $gettok(%a,3,9)) {
  56.             %cadv = $gettok(%a,1,9)
  57.             if (%cadv == 38) && ($p_loc($.nick).num != $hget(pokemon,p_salesman)) { %cadv = $null }            
  58.           }
  59.         }
  60.         choiceadv %cadv
  61.         .remove %tf
  62.       }
  63.       else {
  64.         :redo
  65.         var %n = 1, %a, %c, %u, %r, %y = $rand(1,100), %catch, %npc, %npcvs, %vs, %cash
  66.         while (%n <= $numtok(%q,44)) {
  67.           %a = $regsubex($gettok(%q,%n,44),/(^\x20)/,)
  68.           if ($read(txt/pokemon/rare.txt,r,/\x09( $regescape(%a) )$/xi)) { %r = $addtok(%r,%a,44) }
  69.           elseif ($has_pokemon($.nick,%a) == has) { %c = $addtok(%c,%a,44) }
  70.           else { %u = $addtok(%u,%a,44) }
  71.           inc %n
  72.         }
  73.         var %n = $calc(100 / (($numtok(%u,44) + $numtok(%c,44)) / $numtok(%u,44)))
  74.         if (%x == 0) {
  75.           %p = $p_rare
  76.           if (!%r) || (!$istok(%r,%p,44)) {
  77.             msg $chan $nick $+ : You see a rare %p in the distance, but it's gone before you can get to it.
  78.             see_pokemon $.nick %p
  79.             return
  80.           }
  81.         }
  82.         elseif (%n) && (%y <= %n) || (!%c) { var %p = $.rand(%u) }
  83.         else { var %p = $.rand(%c) }
  84.         if (!%p) {
  85.           msg $chan Error: no pokemon selected.
  86.           msg #flip n %n - y %y - c %c - u %u - r %r
  87.           return
  88.         }
  89.         if ($p_uncom(%p)) {
  90.           if ($rand(1,100) < 85) {
  91.             %x = 1
  92.             %q = $dupe($p_get(20))
  93.             goto redo
  94.           }
  95.         }
  96.         var %min = $floor($bottom($cap($calc(%lvl * .85 - 1),$calc($p_el(%p) * .85)),$p_ml(%p))), %max = $ceil($bottom($cap($cap($calc(%lvl * 1.20 + 1),$calc(($p_el(%p) - 1) * $+(.,$rand(85,100)))),99),$calc($p_ml(%p) + 1))), %lvl = $rand(%min,%max)
  97.         var %npc = $p_gen(%p,%lvl), %pv = $gettok(%npc,2,9)
  98.         %npcvs = $pokemon($gettok(%npc,1,9)).type $+ $chr(9) $+ $gettok(%npc,12-17,9)
  99.         %vs = $p_vs($p_stat($.nick,$p_active($.nick)).vs,%npcvs)
  100.         %cash = $ceil($calc(%lvl ^ 1.7 + (%lvl + $rand(1,%lvl) - $rand(1,%lvl)) * 1.5 + (%lvl * 2)))
  101.         if (%vs == 1) {
  102.           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)
  103.           if (%crr > %crp) { %catch = 1 }
  104.           if (%catch) && ($p_item($.nick,Pokeball) > 0) {
  105.             p_item $.nick Pokeball -1
  106.             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)
  107.             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. }
  108.             add_pokemon $.nick %npc
  109.             p_item $.nick Cash + $+ %cash
  110.           }
  111.           else {
  112.             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)
  113.             p_item $.nick Cash + $+ %cash
  114.             if ($p_item($.nick,Pokeball) > 0) {
  115.               if (!$has_pokemon($.nick,%p)) || ($has_pokemon($.nick,%p) == seen) {
  116.                 if (%catch) { p_item $.nick Pokeball -1 }
  117.               }
  118.               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. }
  119.             }
  120.             noop $p_+exp(%p,%lvl)
  121.           }
  122.         }
  123.         else {
  124.           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.
  125.           see_pokemon $.nick %p
  126.         }
  127.       }
  128.     }
  129.   }
  130. }
  131. alias choiceadv {
  132.   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
  133.   if ($1 == 1) { msg $chan $nick $+ : You wander around, but don't really find anything of interest. }
  134.   elseif ($1 == 2) {
  135.     %x = $ceil($calc($rand(5,10) * $rand(10,50) * (%lvl ^ .4)))
  136.     msg $chan $nick $+ : You get sidetracked while looking for pokemon, but you find some buried treasure, score! (+$ $+ %x cash)
  137.     p_item $.nick cash + $+ %x
  138.   }
  139.   elseif ($1 == 3) {
  140.     %x = $rand(1,10) $iif($rand(1,10) > 8, * 2)
  141.     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!)
  142.     p_item $.nick pokeball + $+ %x
  143.   }
  144.   elseif ($1 == 4) {
  145.     %x = $rand(1,25)
  146.     if (%x == 25) {
  147.       msg $chan $nick $+ : You chase after %p but it gets away, but you spot some Rare candy, sweet! (+1 Rare candy)
  148.       p_item $.nick $sql_esc(Rare candy)
  149.       see_pokemon $.nick %p
  150.     }
  151.     elseif (%x == 1) {
  152.       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)
  153.       p_item $.nick $sql_esc(Gold nugget)
  154.       see_pokemon $.nick %p
  155.     }
  156.     else {
  157.       var %x = $rand(1,100), %t = $iif(%x <= 25,battle,hold), %x = $p_getitem(%t), %n = 1, %i = $p_item($.nick,%x)
  158.       if (%t == hold) {
  159.         while ($rand(1,100) < $calc(%i * 20)) && (%n <= 10) {
  160.           var %x = $p_getitem(%t)
  161.           var %i = $p_item($.nick,%x)
  162.           inc %n
  163.         }
  164.       }
  165.       if (*potion* iswm %x) { %x = $p_cug($.nick).potion }
  166.       msg $chan $nick $+ : You start battling with %p $+ . It gets away, but it drops a %x $+ . (+1 %x $+ )
  167.       p_item $.nick $sql_esc(%x)
  168.       see_pokemon $.nick %p
  169.     }
  170.   }
  171.   elseif ($1 == 5) {
  172.     var %i1 = $p_getitem(hold), %i2 = $p_getitem(hold), %i3 = $p_getitem(hold)
  173.     msg $chan $nick $+ : You find a stash of sweet loot! (+1 %i1 $+ , %i2 $+ , %i3 $+ )
  174.     p_item $.nick $sql_esc(%i1)
  175.     p_item $.nick $sql_esc(%i2)
  176.     p_item $.nick $sql_esc(%i3)
  177.   }
  178.   elseif ($1 == 6) {
  179.     msg $chan $nick $+ : %p spots you and attacks! You just got ownd, you need some time to rest before you can go out again.
  180.     hadd -z pokemon $.nick 180
  181.     see_pokemon $.nick %p
  182.   }
  183.   elseif ($1 isnum 7-10) {
  184.     var %i = $gettok($read(txt/pokemon/noncom.txt,$1),4,9)
  185.     msg $chan $nick $+ : You find a mysterious %i lying on the ground. (+1 %i $+ )
  186.     p_item $.nick $sql_esc(%i) +1
  187.   }
  188.   elseif ($1 isnum 11-30) || ($1 isnum 36-37) {
  189.     var %x = $read(txt/pokemon/noncom.txt,r,/^ $1 \x09/ix), %i = $gettok(%x,4,9), %c = $gettok(%x,5,9)
  190.     msg $chan $nick $+ : You are exploring $p_loc($.nick).name when you meet a guy selling a %i $+ . ($ $+ $bytes(%c,b) $+ ) ( $+ You have $p_item($.nick,%i) $+ ) - [Buy] [Leave]
  191.     p_status $.nick choiceadv
  192.     p_mark $.nick $+(buy|leave*,$1,*,%i,*,%c)
  193.   }
  194.   elseif ($1 isnum 31-35) {
  195.     var %x = $read(txt/pokemon/noncom.txt,r,/^ $1 \x09/ix), %i = $gettok(%x,4,9)
  196.     msg $chan $nick $+ : You meet an old man, after a short talk he gives you a %i ( $+ $tm(%i) $+ ).
  197.     p_item $.nick %i +1
  198.   }
  199.   elseif ($1 == 38) {
  200.     var %1 = $tm(3), %2 = $tm(3), %3 = $tm(3)
  201.     msg $chan $nick $+ : You meet a traveling salesman, he has a few TM's for sale. ($50,000) - $+([,%1,] [,%2,] [,%3,]) [Leave]
  202.     p_status $.nick choiceadv
  203.     p_mark $.nick $+(%1,|,%2,|,%3,*,$1,*,50000)
  204.   }
  205.   elseif ($1 isnum 39-44) {
  206.     var %i = $gettok($read(txt/pokemon/noncom.txt,$1),4,9)
  207.     msg $chan $nick $+ : You come across a tree with a %i $+ . (+1 %i $+ )
  208.     p_item $.nick $sql_esc(%i) +1
  209.   }
  210.   elseif ($1 == daycare) {
  211.     var %x = $addtok($p_team($.nick),leave,124)
  212.     if ($p_daycare($.nick) == none) {
  213.       .notice $nick Welcome to Pokemon daycare! Would you like to leave a pokemon with us? $+([,$replace(%x,|,] [),])
  214.       p_status $.nick choiceadv
  215.       p_mark $.nick $+(%x,*daycare)
  216.     }
  217.     else {
  218.       var %dcl = $replace($p_player($.nick,dcl),none,0)
  219.       .notice $nick Welcome to Pokemon daycare! $p_daycare($.nick) is currently staying with us $+ $iif(%dcl,$chr(44) and has gained $v1 levels) $+ . Would you like to take him with you? $ $+ $bytes($calc((%dcl + 1) * 1000),b) [Yes] [No]
  220.       p_status $.nick choiceadv
  221.       p_mark $.nick yes|no*daycare
  222.     }
  223.   }
  224. }
  225. on *:text:!visit*:#:{
  226.   if ($p_status($.nick) == ready) {
  227.     if (*pokemart* iswm $2-) {
  228.       if (!$istok($p_loc($.nick).npc,Pokemart,44)) { .notice $nick There isn't a Pokemart close by! }
  229.       else {
  230.         var %b = $p_cug($.nick).ball, %p = $p_cug($.nick).potion
  231.         .notice $nick Welcome to Pokemart! You currently have $ $+ $p_item($.nick,cash) $+ . Commands: !buy, !upgrade and !sell
  232.         .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 $+ ) )
  233.         .notice $nick Revive: $!2,000 - Antidote: $!100 - Paralyze heal: $!200 -  Awakening: $!200 -  Burn heal: $!500 -  Ice heal: $!500 -  Full heal: $!1,000 -  Full restore: $!5,000
  234.         if (!$p_item($.nick,Bicycle)) { .notice $nick Bicycle: $!100,000 }
  235.       }
  236.     }
  237.     elseif (*pokecenter* iswm $2-) {
  238.       if (!$istok($p_loc($.nick).npc,Pokecenter,44)) { .notice $nick There isn't a Pokecenter close by! }
  239.       else {
  240.         .notice $nick Welcome to the Pokecenter! Commands: !take and !leave to change pokemon in your team.
  241.         .notice $nick $p_team($.nick) Current team: $replace($p_team($.nick),|,$chr(32) - $chr(32))
  242.       }
  243.     }
  244.     elseif (*mall* iswm $2-) {
  245.       if (!$istok($p_loc($.nick).npc,The mall,44)) { .notice $nick You aren't near The Mall! }
  246.       else {
  247.         .notice $nick Welcome to The Mall! You can buy TMs with he !buy command.
  248.         var %f = txt/pokemon/mall $+ $ticks, %a
  249.         filter -ffg txt/pokemon/tms.txt %f /\x09(1)$/x
  250.         .fopen tm %f
  251.         while ($fread(tm)) {
  252.           %a = $addtok(%a,$+([,$gettok($v1,1,9),]),32)
  253.           if ($numtok(%a,32) > 14) {
  254.             .notice $nick TM's currently in stock ($20,000): %a
  255.             %a = $null
  256.           }
  257.         }
  258.         .fclose tm
  259.         .remove %f
  260.         .notice $nick Limited time only ($30,000): $+([,$replace($hget(pokemon,p_mall),$chr(32),] [),])
  261.       }
  262.     }
  263.     elseif (*day*care* iswm $2-) { choiceadv daycare }
  264.     else { .notice $nick That either isnt a place, or its not done yet, still working on this part }
  265.   }
  266. }
  267. elseif (*move tutor* iswm $2-) { }
  268. elseif (*treasure hunter* iswm $2-) { }
  269. elseif (*trick master* iswm $2-) { }
  270. elseif (*safari hunt* iswm $2-) { }
  271. elseif (*bug c* iswm $2-) { }
  272. elseif (*dojo* iswm $2-) { }
  273. elseif (*gym* iswm $2-) { }
  274.  
  275. on *:text:!choose*:#:{
  276.   var %a = $p_active($.nick), %p = $pokemon($2-).name, %status = $p_status($.nick)
  277.   if (!%p) { .notice $nick Unrecognized pokemon }
  278.   elseif ($2) {
  279.     if (%status == none) {
  280.       if ($istok(Bulbasaur Charmander Squirtle Pidgey Weedle Pichu Machop Abra Geodude Staryu Chikorita Cyndaquil Totodile Absol,%p,32)) {
  281.         sqlite_begin %pdb
  282.         sqlite_exec %pdb INSERT INTO p_inventory (name, cash, pokeball) VALUES (' $+ $sql_esc($.nick) $+ ', 500, 20)
  283.         sqlite_exec %pdb INSERT INTO p_badges (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  284.         sqlite_exec %pdb INSERT INTO p_pokemon (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  285.         sqlite_exec %pdb INSERT INTO p_tm (name) VALUES (' $+ $sql_esc($.nick) $+ ')
  286.         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, '', '', 0)
  287.         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))
  288.         sqlite_commit %pdb
  289.         add_pokemon $.nick $p_gen(%p,1)
  290.         hadd -z pokemon $+($.nick,.travel) 900
  291.         .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
  292.       }
  293.       else { .notice $nick That isn't a valid option. }
  294.     }
  295.     elseif (%status == ready) {
  296.       if (%a == %p) { .notice $nick %p is already your active pokemon! }
  297.       elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p }
  298.       elseif ($p_stat($.nick,%p).lvl < $p_loc($.nick).lvl) { .notice $nick %p is too weak to be out here. }
  299.       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. }
  300.       else {
  301.         .notice $nick %p is now your active pokemon.
  302.         p_active $.nick %p
  303.       }
  304.     }
  305.   }
  306. }
  307. on *:text:!take*:#:{
  308.   if ($p_status($.nick) == ready) {
  309.     var %p = $pokemon($2).name, %t = $p_team($.nick)
  310.     if (!%p) { .notice $nick Unrecognized pokemon! }
  311.     elseif (!$istok($p_loc($.nick).npc,Pokecenter,44)) { .notice $nick There isnt a Pokecenter close by! }
  312.     elseif ($numtok(%t,124) >= 6) { .notice $nick Your team is full! You need to !leave one first. }
  313.     elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p $+ ! }
  314.     elseif ($istok(%t,%p,124)) { .notice $nick %p is already in your team! }
  315.     elseif (%p == $p_daycare($.nick)) { .notice $nick %p is in Daycare! }
  316.     else {
  317.       %t = $addtok(%t,%p,124)
  318.       .notice $nick You take %p with you. [Team: $replace(%t,|,$chr(32) - $chr(32)) $+ ]
  319.       p_team $.nick %t
  320.     }
  321.   }
  322. }
  323. on *:text:!leave*:#:{
  324.   if ($p_status($.nick) == ready) {
  325.     var %p = $pokemon($2).name, %t = $p_team($.nick)
  326.     if (!%p) { .notice $nick Unrecognized pokemon! }
  327.     elseif (!$istok($p_loc($.nick).npc,Pokecenter,44)) { .notice $nick There isn't a Pokecenter close by! }
  328.     elseif (!$istok(%t,%p,124)) { .notice $nick %p isn't in your team! }
  329.     elseif (%p == $p_active($.nick)) { .notice $nick You can't leave your active pokemon! }
  330.     else {
  331.       %t = $remtok(%t,%p,1,124)
  332.       .notice $nick You leave %p [Team: $replace(%t,|,$chr(32) - $chr(32)) $+ ]
  333.       p_team $.nick %t
  334.     }
  335.   }
  336. }
  337. on *:text:!team:#:{
  338.   if ($p_status($.nick)) {
  339.     .notice $nick $replace($p_team($.nick),|,$chr(32) - $chr(32))
  340.   }
  341. }
  342. on *:text:!give *:#:{
  343.   if ($p_status($.nick) == ready) {
  344.     var %p = $pokemon($iif($5,$2 $3,$2)).name, %i = $p_item($iif($5,$4-,$iif($p_item($3-).name,$3-,$4-))).name
  345.     if (!%i) { .notice $nick That isn't an item! }
  346.     elseif ($p_item(%i).type != hold) { .notice $nick You can't give that to him! }
  347.     elseif (!%p) { .notice $nick I think you misspelled the pokemon name, or have the name and item in the wrong order. }
  348.     elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p }
  349.     elseif (!$p_item($.nick,%i)) { .notice $nick You don't have a %i }
  350.     else {
  351.       set -l %sql SELECT item FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  352.       set -l %query $sqlite_query(%pdb,%sql)
  353.       set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  354.       sqlite_exec %pdb UPDATE $sql_esc($.nick) SET item=' $+ $sql_esc(%i) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  355.       p_item $.nick $sql_esc(%i) -1
  356.       if ($hget(pitem,item)) {
  357.         var %new = $v1
  358.         .notice $nick You exchange %p $+ 's $sql_re(%new) for your %i
  359.         p_item $.nick $sql_esc(%new)
  360.       }
  361.       else { .notice $nick You give the %i to %p }
  362.     }
  363.   }
  364.   sqlite_free %query
  365. }
  366. on $*:text:/^!travel\s(north|south|east|west)/i:#:{
  367.   if ($p_status($.nick) == ready) {
  368.     tokenize 32 $($+($!p_loc($.nick),.,$2),2)
  369.     if ($hget(pokemon,$+($.nick,.travel))) { .notice $nick You cant travel yet, You need to wait $duration($v1) }
  370.     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 $+ ) }
  371.     else {
  372.       if ($p_loc($1,$2)) && ($p_loc($.nick) != $1 $2) {
  373.         hadd -z pokemon $+($.nick,.,travel) $iif($p_item($.nick,bicycle),600,900)
  374.         p_loc $.nick $1 $2
  375.         .notice $nick You travel to $p_loc($.nick).name $+ . $iif($p_loc($.nick).npc,Points of interest: [ $+ $replace($v1,$chr(44),] - [) $+ ])
  376.       }
  377.       else { .notice $nick You cant travel there! }
  378.     }
  379.   }
  380. }
  381. on $*:text:/^!(location|map)/i:#:{
  382.   if ($p_status($.nick) == ready) {
  383.     .notice $nick $p_loc($.nick).map
  384.     if ($p_loc($.nick).npc) { .notice $nick Points of interest: [ $+ $replace($p_loc($.nick).npc,$chr(44),] - [) $+ ] }
  385.   }
  386. }
  387. alias p_loc {
  388.   if ($isid) {
  389.     if (!$2) { tokenize 32 $1 }
  390.     if ($1 !isnum) {
  391.       set -l %sql SELECT loc FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  392.       set -l %query $sqlite_query(%pdb,%sql)
  393.       set -l %fetch $sqlite_fetch_row(%query,loc,$SQLITE_ASSOC)
  394.       sqlite_free %query
  395.       tokenize 32 $hget(loc,loc)
  396.       if ($hget(loc)) { hfree loc }
  397.     }
  398.     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)
  399.     if (!%x) { return 0 }
  400.     if ($prop == npc) {
  401.       var %tf = txt/pokemon/loc $+ $ticks, %a
  402.       filter -ffg txt/pokemon/npc.txt %tf /(\x09|\x2C)( %x |\*)(\x09|\x2C)/x
  403.       .fopen locnpc %tf
  404.       while ($fread(locnpc)) { %a = $addtok(%a,$gettok($v1,3,9),44) }
  405.       .fclose locnpc
  406.       .remove %tf
  407.       return %a
  408.     }
  409.     if ($prop == name) { return $p_ini(area,%x) }
  410.     if ($prop == num) { return %x }
  411.     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) $+ ])  }
  412.     if ($prop == lvl) { return $p_ini(level,%x) }
  413.     if ($prop == north) && (%n) { return $calc($1 - 1) $2 }
  414.     if ($prop == east) && (%e) { return $1 $calc($2 + 1) }
  415.     if ($prop == south) && (%s) { return $calc($1 + 1) $2 }
  416.     if ($prop == west) && (%w) { return $1 $calc($2 - 1) }
  417.     if ($prop == rand) {
  418.       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))
  419.       return $.rand(%r)
  420.     }
  421.     return $1-
  422.   }
  423.   sqlite_exec %pdb UPDATE p_players SET loc=' $+ $2- $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  424. }
  425. alias pokemon {
  426.   if (!$1) {
  427.     if ($prop) { return }
  428.     return $gettok($read(txt/pokemon/pokemon.txt),2,9)
  429.   }
  430.   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)
  431.   if ($prop == num) { return $gettok(%x,1,9) }
  432.   if ($prop == name) { return $gettok(%x,2,9) }
  433.   if ($prop == type) { return $gettok(%x,3,9) }
  434.   if ($prop == hp) { return $gettok(%x,4,9) }
  435.   if ($prop == atk) { return $gettok(%x,5,9) }
  436.   if ($prop == def) { return $gettok(%x,6,9) }
  437.   if ($prop == satk) { return $gettok(%x,7,9) }
  438.   if ($prop == sdef) { return $gettok(%x,8,9) }
  439.   if ($prop == spd) { return $gettok(%x,9,9) }
  440.   if ($prop == total) { return $gettok(%x,10,9) }
  441.   if ($prop == fmt) { return ( $+ $gettok(%x,1,9) $+ ) $gettok(%x,2,9) [Type: $gettok(%x,3,9) $+ ] }
  442.   if (stat* iswm $prop) { return $gettok(%x,3-9,9) }
  443.   else { return %x }
  444. }
  445. alias p_get {
  446.   var %f = txt/pokemon/pget $+ $ticks, %a = $iif($2,$2,$p_loc($.nick).num), %m
  447.   filter -ffg txt/pokemon/area.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  448.   var %m = $($str( $+ $!gettok( $+ $!read( $+ %f $+ ),2,9) $!+ $!chr(44) $chr(32) ,$iif($1,$1,1)),2)
  449.   .remove %f
  450.   return %m
  451. }
  452. alias p_rare {
  453.   if ($1) {
  454.     var %x = $pokemon($1-).name
  455.     return $iif($read(txt/pokemon/rare.txt,r,/(\x09 $regescape(%x) )$/ix),$true,$false)
  456.   }
  457.   var %f = txt/pokemon/prare $+ $ticks, %a = $p_loc($.nick).num
  458.   filter -ffg txt/pokemon/rare.txt %f /(?<=^|\x2C)( %a )(?=\x2C|\x09)/ix
  459.   .timerrare 1 1 .remove %f
  460.   return $gettok($read(%f),2,9)
  461. }
  462. alias p_uncom {
  463.   if ($1) {
  464.     var %x = $pokemon($1-).name
  465.     return $iif($read(txt/pokemon/uncommon.txt,w,%x $+ *),$true,$false)
  466.   }
  467. }
  468. alias p_traded {
  469.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $2 $+ '
  470.   set -l %query $sqlite_query(%pdb,%sql)
  471.   set -l %fetch $sqlite_fetch_row(%query,traded,$SQLITE_ASSOC)
  472.   var %x = $iif($hget(traded,traded) == 1,$true,$false)
  473.   sqlite_free %query
  474.   if ($hget(traded)) { hfree traded }
  475.   return %x
  476. }
  477. alias p_exp { return $ceil($calc((7 * $1 ^ 3) / 5)) }
  478. alias p_mexp { return $ceil($calc($iif($p_traded($.nick,%p),1.5,1) * $p_bexp($1).exp * $2 / 7)) }
  479. alias p_+exp {
  480.   sqlite_begin %pdb
  481.   if ($1 == rare candy) {
  482.     var %p = $2, %exp = $calc($p_exp($calc($p_stat($.nick,%p).lvl + 1)) - $p_stat($.nick,%p).exp)
  483.     sqlite_exec %pdb UPDATE $sql_esc($.nick) SET exp=exp+ %exp WHERE pokemon=' $+ $sql_esc(%p) $+ '
  484.   }
  485.   else {
  486.     var %p = $p_active($.nick), %exp = $ceil($calc($iif($p_traded($.nick,%p),1.5,1) * $p_bexp($1).exp * $2 / 7))
  487.     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) $+ '
  488.   }
  489.   set -l %sql SELECT * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  490.   set -l %query $sqlite_query(%pdb,%sql)
  491.   set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  492.   if ($p_exp($calc($hget(pkexp,lvl) + 1)) <= $hget(pkexp,exp)) && ($hget(pkexp,lvl) < 99) {
  493.     var %lvl = $hget(pkexp,lvl) + 1, %e = $p_path(%p), %n = $gettok(%e,$calc($findtok(%e,%p,1,9) + 1),9)
  494.     if (%lvl >= $p_el(%p)) && (%lvl != 99) && ($has_pokemon($.nick,%n) != has) {
  495.       if (| isin %n) {
  496.         if (%p == Wurmple) { %n = $iif($calc($hget(pkexp,pv) % 10) < 5,Silcoon,Cascoon) }
  497.         elseif ($regex(%p,/^(Silcoon|Cascoon)$/i)) { %n = $iif(%p == Silcoon,Beautifly,Dustox) }
  498.         else {
  499.           var %x = 1, %y = $numtok(%n,124), %a, %s
  500.           while (%x <= %y) {
  501.             var %a = $gettok(%n,%x,124)
  502.             if ($sql_re($hget(pkexp,item)) == $p_ei(%a)) { %s = %a }
  503.             inc %x
  504.           }
  505.           if (!%s) { goto level }
  506.           else { %n = %s }
  507.         }
  508.       }
  509.       elseif ($p_ei(%n)) {
  510.         if ($sql_re($hget(pkexp,item)) != $p_ei(%n)) { goto level }
  511.         else { sqlite_exec %pdb UPDATE $sql_esc($.nick) SET item=' $+ $null $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ ' }
  512.       }
  513.       var %pstat = $p_stat($.nick,%p), %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))
  514.       %pstat = $puttok(%pstat,%ability,3,9)
  515.       msg $chan %p is Evolving! %p evolved in to %n
  516.       p_team $.nick $reptok($p_team($.nick),%p,%n,1,124)
  517.       sqlite_exec %pdb UPDATE $sql_esc($.nick) SET pokemon=' $+ $sql_esc(%n) $+ ', ability=' $+ $sql_esc(%ability) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  518.       sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc(%n) $+ ='1' WHERE name=' $+ $sql_esc($.nick) $+ '
  519.       sqlite_exec %pdb DELETE * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  520.       lock_pokemon $.nick %p
  521.       hadd pkexp pokemon %n
  522.       if ($p_active($.nick) == %p) { p_active $.nick %n }
  523.     }
  524.     :level
  525.     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)
  526.     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))
  527.     if ($gettok(%n,2,32)) {
  528.       inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  529.       dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  530.     }
  531.     msg $chan $sql_re(%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))),])
  532.     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) $+ '
  533.     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)
  534.     if ($p_move(%p,%lvl)) {
  535.       var %nm = $v1
  536.       if ($numtok(%mlist,44) < 4) {
  537.         msg $chan $sql_re(%p) learned %nm $+ !
  538.         sqlite_exec %pdb UPDATE $sql_esc($.nick) SET $+(m,$calc($numtok(%mlist,44) + 1)) =' $+ $sql_esc(%nm) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  539.       }
  540.       else {
  541.         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.)
  542.         p_mark $.nick $+(%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4,$chr(44),%nm)
  543.         p_status $.nick learn
  544.       }
  545.     }
  546.   }
  547.   sqlite_commit %pdb
  548.   sqlite_free %query
  549.   if ($hget(pkexp)) { hfree pkexp }
  550.   return %exp
  551. }
  552. alias p_+daycare {
  553.   var %p = $p_daycare($1), %cl = $p_stat($1,%p).lvl
  554.   sqlite_exec %pdb UPDATE $sql_esc($1) SET exp=exp+ $cap($calc(%cl * 2),100) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  555.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  556.   set -l %query $sqlite_query(%pdb,%sql)
  557.   set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  558.   if ($p_exp($calc($hget(pkexp,lvl) + 1)) <= $hget(pkexp,exp)) && ($hget(pkexp,lvl) < 99) {
  559.     var %lvl = $hget(pkexp,lvl) + 1, %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)
  560.     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))
  561.     if ($gettok(%n,2,32)) {
  562.       inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  563.       dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  564.     }
  565.     sqlite_exec %pdb UPDATE $sql_esc($1) 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) $+ '
  566.     p_ps $1 dcl
  567.     if ($p_move(%p,%lvl)) {
  568.       var %m1 = $hget(pkexp,m1), %m2 = $hget(pkexp,m2), %m3 = $hget(pkexp,m3), %m4 = $hget(pkexp,m4), %all = $+(%m1,$chr(9),%m2,$chr(9),%m3,$chr(9),%m4,$chr(9),$p_move(%p,%lvl))
  569.       if ($numtok(%all,9) <= 4) { var %c = $numtok(%all,9), %m = %all $+ $str($chr(9),$calc(4 - %c)) }
  570.       else {
  571.         while ($numtok(%m,9) < 4) { %m = $addtok(%m,$p_movesel($1,%all),9) }
  572.       }
  573.       sqlite_exec %pdb UPDATE $sql_esc($1) SET m1=' $+ $gettok(%m,1,9) $+ ' m2=' $+ $gettok(%m,2,9) $+ ' m3=' $+ $gettok(%m,3,9) $+ ' m4=' $+ $gettok(%m,4,9) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  574.     }
  575.   }
  576.   sqlite_commit %pdb
  577.   sqlite_free %query
  578.   if ($hget(pkexp)) { hfree pkexp }
  579. }
  580. on *:text:!forget*:#:{
  581.   if ($p_status($.nick) == learn) || ($p_status($.nick) == tm) {
  582.     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))
  583.     if ($istok(%x,$pokemove($2-).name,44)) { %x = $remtok(%x,$pokemove($2-).name,1,44)
  584.       .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),])
  585.       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 $+ '
  586.       p_status $.nick ready
  587.     }
  588.     else { .notice $nick That isn't a valid option. }
  589.   }
  590. }
  591. alias p_bexp {
  592.   tokenize 9 $read(txt/pokemon/ev.txt,r,/\x09 $replace($pokemon($1-).name,$chr(32),\s,$chr(40),.,$chr(41),.) \s\x09/xi)
  593.   if ($prop == exp) { return $3 }
  594.   if ($prop == hp) { return $4 }
  595.   if ($prop == atk) { return $5 }
  596.   if ($prop == def) { return $6 }
  597.   if ($prop == spatk) { return $7 }
  598.   if ($prop == spdef) { return $8 }
  599.   if ($prop == spd) { return $9 }
  600. }
  601. alias p_cr {
  602.   var %x = $read(txt/pokemon/cr.txt,w,$pokemon($1).name $+ *)
  603.   return $gettok(%x,2,9)
  604. }
  605. alias p_el {
  606.   if ($1) {
  607.     var %x = $read(txt/pokemon/level.txt,w,$pokemon($1).name $+ *)
  608.     return $iif(%x,$calc($gettok(%x,2,9) + 1),$null)
  609.   }
  610. }
  611. alias p_path {
  612.   var %p = $pokemon($1).name, %x = $read(txt/pokemon/path.txt,w,* $+ %p $+ *), %t = $calc($findtok(%x,%p,1,9) $prop 1)
  613.   if ($prop) { return $gettok(%x,%t,9) }
  614.   return %x
  615. }
  616. alias p_ml {
  617.   if ($1) {
  618.     var %x = $pokemon($1).name, %p = $p_path(%x), %t = $findtok(%p,%x,1,9) - 1
  619.     if (!%p) { return 1 }
  620.     return $iif(%t,$p_el($gettok(%p,%t,9)),1)
  621.   }
  622. }
  623. alias p_ei {
  624.   if ($1) {
  625.     var %x = $pokemon($1).name
  626.     if %x { %x = $read(txt/pokemon/evolve.item.txt,w,%x $+ *) }
  627.     return $iif(%x,$gettok(%x,2,9),$null)
  628.   }
  629. }
  630. alias p_ep {
  631.   var %p = $read(txt/pokemon/path.txt,w,* $+ $pokemon($1).name $+ * )
  632.   return $($regsubex(%p,/([^\|]+?)(\x09)/g,\1->( $!+ $!p_el( $+ \1 $+ ) $!+ $!iif( $!+ $!read(txt/pokemon/evolve.item.txt,w,* $!+ $!p_path( $+ \1 $+ ).+ $!+ *) $!+ ,*) $!+ )->),3)
  633. }
  634. alias p_vs {
  635.   var %x = 1, %a1, %d1, %dam1, %a2, %d2, %dam2, %h, %m, %hp1, %hp2
  636.   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))
  637.   while (%x <= %apm1) {
  638.     var %h = $rand(1,20), %m = $rand(1,20)
  639.     if (%m > %h) || (%h < 3) { dec %apm1 }
  640.     elseif (%h == 20) { inc %apm1 }
  641.     inc %x
  642.   }
  643.   %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)
  644.   %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)
  645.   %x = 1
  646.   while (%x <= %apm2) {
  647.     var %h = $rand(1,20), %m = $rand(1,20)
  648.     if (%m > %h) || (%h < 3) { dec %apm2 }
  649.     elseif (%h == 20) { inc %apm2 }
  650.     inc %x
  651.   }
  652.   var %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)
  653.   var %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)
  654.   var %dam1 = $bottom($calc(%a1 - %d1),1), %dam2 = $bottom($calc(%a2 - %d2),1), %hp1 = $calc($gettok($1,2,9) - %dam2), %hp2 = $calc($gettok($2,2,9) - %dam1)
  655.   return $iif(%hp1 > %hp2,1,2)
  656. }
  657. alias p_gen {
  658.   var %x, %y = $lines(txt/pokemon/ev.txt), %p = $pokemon($1).stat, %l = 1, %exp = 1, %pv = $rand(0,4294967295)
  659.   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
  660.   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 $+ *)
  661.   .fopen npc txt/pokemon/ev.txt
  662.   while (%l < $2) {
  663.     .fseek -l npc $rand(1,%y)
  664.     %x = $fread(npc)
  665.     inc %exp $floor($calc($gettok(%x,3,9) * %l / 7))
  666.     inc %evhp $gettok(%x,4,9)
  667.     inc %evatk $gettok(%x,5,9)
  668.     inc %evdef $gettok(%x,6,9)
  669.     inc %evspatk $gettok(%x,7,9)
  670.     inc %evspdef $gettok(%x,8,9)
  671.     inc %evspd $gettok(%x,9,9)
  672.     while (%exp > $p_exp($calc(%l + 1))) { inc %l }
  673.   }
  674.   set -l %sql SELECT * FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  675.   set -l %query $sqlite_query(%pdb,%sql)
  676.   set -l %fetch $sqlite_fetch_row(%query,npcmove,$SQLITE_ASSOC)
  677.   var %n = 1, %m, %physical, %status, %special, %all
  678.   while (%n <= $2) {
  679.     if ($hget(npcmove,$+(l,%n))) {
  680.       %m = $hget(npcmove,$+(l,%n))
  681.       %all = $addtok(%all,%m,9)
  682.       var % $+ $pokemove(%m).cat $addtok($($+(%,$pokemove(%m).cat),2),%m,9)
  683.     }
  684.     inc %n
  685.   }
  686.   var %m
  687.   if ($numtok(%all,9) <= 4) { var %c = $numtok(%all,9), %m = %all $+ $str($chr(9),$calc(4 - %c)) }
  688.   else {
  689.     while ($numtok(%m,9) < 4) { %m = $addtok(%m,$p_movesel($1,%all),9) }
  690.   }
  691.   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))
  692.   if ($gettok(%n,2,32)) {
  693.     inc $gettok(%n,2,32) $calc($gettok(%n,2,32) * .1)
  694.     dec $gettok(%n,3,32) $calc($gettok(%n,3,32) * .1)
  695.   }
  696.   .fclose npc
  697.   sqlite_free %query
  698.   if ($hget(npcmove)) { hfree npcmove }
  699.   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)
  700. }
  701. alias p_move {
  702.   set -l %sql SELECT l $+ $2 FROM p_learnset WHERE name LIKE $+('%,$sql_esc($1),$(%',0))
  703.   set -l %query $sqlite_query(%pdb,%sql)
  704.   set -l %fetch $sqlite_fetch_row(%query,pkmove,$SQLITE_ASSOC)
  705.   var %x = $hget(pkmove,l $+ $2)
  706.   sqlite_free %query
  707.   if ($hget(pkmove)) { hfree pkmove }
  708.   return $iif(%x,$v1,$null)
  709. }
  710. alias add_pokemon {
  711.   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
  712.   sqlite_begin %pdb
  713.   if ($has_pokemon($1,$gettok($2-,1,9)) == has) {
  714.     .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?
  715.     .notice $nick Old: $p_statfmt($1,$p_stat($1,$gettok($2-,1,9)))
  716.     .notice $nick New: $p_statfmt($1,$2-)
  717.     p_mark $1 $replace($2-,$chr(9),*)
  718.     p_status $1 replace
  719.     return
  720.   }
  721.   var %t = $p_team($1)
  722.   if ($numtok(%t,124) < 6) {
  723.     p_team $1 $addtok(%t,$gettok($2,1,9),124)
  724.   }
  725.   noop $p_+exp($gettok($2-,1,9),$gettok($filltok($2-,-,9),11,9))
  726.   sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($gettok($2-,1,9)) $+ ='1' WHERE name=' $+ $sql_esc($1) $+ '
  727.   sqlite_exec %pdb INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  728.   sqlite_commit %pdb
  729. }
  730. on *:text:!keep:#:{
  731.   if ($p_status($.nick) == replace) {
  732.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  733.     .notice $nick You keep the new %p and set your old one free.
  734.     p_status $.nick ready
  735.     replace_pokemon $.nick %x
  736.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  737.   }
  738. }
  739. on *:text:!release:#:{
  740.   if ($p_status($.nick) == replace) {
  741.     var %x = $p_mark($.nick), %p = $gettok(%x,1,42)
  742.     .notice $nick You keep your %p and let the new one go.
  743.     p_status $.nick ready
  744.     noop $p_+exp(%p,$gettok($filltok(%x,-,42),11,42))
  745.   }
  746. }
  747. alias replace_pokemon {
  748.   var %p = $gettok($2-,1,42), %x = $replace($sql_esc($2-),$chr(42),' $+ $chr(44) $+ ')
  749.   sqlite_exec %pdb DELETE FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  750.   sqlite_exec %pdb INSERT INTO $sql_esc($1) VALUES (' $+ %x $+ ')
  751. }
  752. alias see_pokemon {
  753.   if (!$has_pokemon($1,$2)) {
  754.     sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='s' WHERE name=' $+ $sql_esc($1) $+ '
  755.   }
  756. }
  757. alias lock_pokemon {
  758.   sqlite_exec %pdb UPDATE p_pokemon SET $sql_esc($pokemon($2).name) $+ ='x' WHERE name=' $+ $sql_esc($1) $+ '
  759. }
  760. alias has_pokemon {
  761.   set -l %sql SELECT $sql_esc($2-) FROM p_pokemon WHERE name=' $+ $sql_esc($1) $+ '
  762.   set -l %query $sqlite_query(%pdb,%sql)
  763.   set -l %fetch $sqlite_fetch_row(%query,haspkm,$SQLITE_ASSOC)
  764.   sqlite_free %query
  765.   var %x = $replacex($hget(haspkm,$sql_esc($2-)),1,has,x,had,s,seen)
  766.   if ($hget(haspkm)) { hfree haspkm }
  767.   return %x
  768. }
  769. alias trade_pokemon { }
  770.  
  771. on *:text:!buy*:#:{
  772.   if ($p_status($.nick) == ready) {
  773.     var %t = $iif($2 isnum,$3-,$2-), %c
  774.     if (TM* iswm %t) {
  775.       if (!$istok($p_loc($.nick).npc,The Mall,44)) { .notice $nick You aren't near The Mall! }
  776.       else {
  777.         if ($tm(%t).r == 1) {
  778.           %c = $iif($2 isnum,$2,1)
  779.           if ($p_item($.nick,cash) >= $calc(%c * 20000)) {
  780.             .notice $nick You buy $iif($2 isnum,$2 $upper(%t) $+ s,a $upper(%t))
  781.             p_item $.nick %t + $+ %c
  782.             p_item $.nick cash - $+ $calc(20000 * %c)
  783.           }
  784.           else { .notice $nick You don't have enough cash! }
  785.         }
  786.         elseif ($tm(%t).r == 2) {
  787.           var %m = $hget(pokemon,p_mall)
  788.           if (!$istok(%m,$2,32)) { .notice $nick That isn't for sale! }
  789.           elseif ($2 isnum) { .notice $nick We only have 1 $upper($3) in stock. }
  790.           else {
  791.             if ($p_item($.nick,cash) >= 30000) {
  792.               .notice $nick You buy a $upper(%t) $+ .
  793.               p_item $.nick %t +1
  794.               p_item $.nick cash -30000
  795.               %m = $replace(%m,$2,$tm(2))
  796.               hadd pokemon p_mall $dupe(%m)
  797.             }
  798.           }
  799.         }
  800.         else { .notice $nick That isn't for sale! }
  801.       }
  802.     }
  803.     else {
  804.       if (!$istok($p_loc($.nick).npc,Pokemart,44)) { .notice $nick There isn't a Pokemart close by! }
  805.       else {
  806.         if ($regex($2-,/((poke|great|ultra)?\s?ball|revive|(super|hyper|max)?\s?potion|full\srestore|antidote|paralyze\sheal|awakening|burn\sheal|ice\sheal|full\sheal|bicycle)\s?/i)) {
  807.           if (*ball* iswm %t) { %t = $p_cug($.nick).ball }
  808.           if (*potion* iswm %t) { %t = $p_cug($.nick).potion }
  809.           %c = $iif($2 isnum,$calc($p_item(%t).cost * $2),$p_item(%t).cost)
  810.           if ($p_item($.nick,cash) >= %c) {
  811.             if (%t == bicycle) && ($p_item($.nick,bicycle)) { .notice $nick You already have a Bicycle! }
  812.             else {
  813.               .notice $nick You buy $iif($2 isnum,$2 %t $+ s,a %t)
  814.               if (*ball* iswm %t) { p_item $.nick Pokeball $iif($2 isnum,+ $+ $2) }
  815.               elseif (*potion* iswm %t) { p_item $.nick Potion $iif($2 isnum,+ $+ $2) }
  816.               else { p_item $.nick $sql_esc($p_item(%t).name) $iif($2 isnum,+ $+ $2) }
  817.               p_item $.nick cash - $+ %c
  818.             }
  819.           }
  820.           else { .notice $nick You don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  821.         }
  822.         else { .notice $nick You can't buy that! }
  823.       }
  824.     }
  825.   }
  826. }
  827. on $*:text:/^!upgrade\s(.*)(ball|potion)(.*)/:#:{
  828.   if ($p_status($.nick) == ready) {
  829.     if (!$istok($p_loc($.nick).npc,Pokemart,44)) { .notice $nick There isn't a Pokemart close by! }
  830.     else {
  831.       var %x, %c
  832.       if (*ball* iswm $2) { %x = $p_cug($.nick).ball }
  833.       elseif (*potion* iswm $2) { %x = $p_cug($.nick).potion }
  834.       %c = $calc($p_iug(%x).cost + $p_item($.nick,$iif(*ball* iswm $2,pokeball,potion)) * $p_item($iif(*ball* iswm $2,pokeball,potion)).cost)
  835.       if ($p_iug(%x)) {
  836.         if ($p_item($.nick,cash) >= %c) {
  837.           p_item $.nick $sql_esc($p_iug(%x))
  838.           p_item $.nick cash - $+ %c
  839.           .notice $nick You upgrade your %x to $p_iug(%x)
  840.         }
  841.         else { .notice $nick you don't have enough cash! ($ $+ $bytes(%c,b) - You have $ $+ $bytes($p_item($.nick,cash),b) $+ ) }
  842.       }
  843.       else { .notice $nick You can't upgrade that! }
  844.     }
  845.   }
  846. }
  847. on *:text:!sell*:#:{
  848.   if ($p_status($.nick) == ready) {
  849.     if (!$istok($p_loc($.nick).npc,Pokemart,44)) { .notice $nick There isn't a Pokemart close by! }
  850.     else {
  851.       var %i = $p_item($iif($2 isnum,$3-,$2-)).name, %n = $iif($2 isnum,$2,1), %c = $calc(($p_item(%i).cost * $iif(TM* iswm %i,5000,.1)) * %n)
  852.       if (!%i) || (!%c) { notice $nick You can't sell that! }
  853.       elseif ($p_item($.nick,%i) >= %n) {
  854.         .notice $nick You sell %n %i $+ $iif(%n > 1,$+ 's) for $ $+ %c $+ .
  855.         p_item $.nick $sql_esc(%i) - $+ %n
  856.         p_item $.nick cash + $+ %c
  857.       }
  858.       else { .notice $nick You don't have that many! }
  859.     }
  860.   }
  861. }
  862. on *:text:!inventory*:#:{
  863.   if ($p_status($.nick) == ready) {
  864.     if ($regex($2,/(T|H)Ms?/i)) {
  865.       set -l %sql SELECT * FROM p_tm WHERE name=' $+ $sql_esc($.nick) $+ '
  866.       set -l %query $sqlite_query(%pdb,%sql)
  867.       set -l %fetch $sqlite_fetch_row(%query,pinv,$SQLITE_ASSOC)
  868.       var %x = 1, %y = $hget(pinv,0).item, %m, %t
  869.       while (%x <= %y) {
  870.         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) }
  871.         if ($numtok(%m,45) > 9) {
  872.           .notice $nick $sql_re(%m)
  873.           %m = $null
  874.           inc %t
  875.         }
  876.         inc %x
  877.       }
  878.       if (%m) { .notice $nick $sql_re(%m) }
  879.       elseif (!%t) { .notice $nick You don't have any TM's. }
  880.     }
  881.     else {
  882.       set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($.nick) $+ '
  883.       set -l %query $sqlite_query(%pdb,%sql)
  884.       set -l %fetch $sqlite_fetch_row(%query,pinv,$SQLITE_ASSOC)
  885.       if (!$2) {
  886.         .notice $nick Cash $ $+ $bytes($hget(pinv,cash),b) - $p_cug($.nick).ball ( $+ $hget(pinv,pokeball) $+ ) - $p_cug($.nick).potion ( $+ $hget(pinv,potion) $+ )
  887.         .notice $nick Revive ( $+ $hget(pinv,Revive) $+ ) - 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) $+ )
  888.         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 $+ ) )
  889.         if (%m) { .notice $nick $regsubex(%m,/(\x29)\s(.)/g,\1 - \2) }
  890.       }
  891.       else {
  892.         var %x = 1, %n, %m, %i
  893.         if (*ball* iswm $2) { %i = Pokeball,Masterball }
  894.         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 }
  895.         elseif (spec* iswm $2) { %i = Bicycle,Rare_32candy,Gold_32nugget,Blue_32shard,Red_32shard,Yellow_32shard,Green_32shard,Black_32Apricorn,White_32Apricorn,Blue_32Apricorn,Green_32Apricorn,Yellow_32Apricorn,Red_32Apricorn }
  896.         while (%x <= $numtok(%i,44)) {
  897.           %n = $gettok(%i,%x,44)
  898.           if ($hget(pinv,%n)) { %m = $addtok(%m,$chr(32) $iif(%n == Pokeball,$p_cug($.nick).ball,%n) ( $+ $hget(pinv,%n) $+ ) $chr(32),45) }
  899.           if ($numtok(%m,45) > 7) {
  900.             .notice $nick $sql_re(%m)
  901.             %m = $null
  902.           }
  903.           inc %x
  904.         }
  905.         if (%m) { .notice $nick $sql_re(%m) }
  906.       }
  907.       if ($hget(pinv)) { hfree pinv }
  908.       sqlite_free %query
  909.     }
  910.   }
  911. }
  912. on *:text:!use*:#:{
  913.   if ($p_status($.nick) == ready) {
  914.     var %p = $pokemon($iif($4,$4-,$3-)).name, %i = $p_item($iif($4,$iif($p_item($2 $3).name,$2 $3,$2),$2)).name
  915.     if (!%p) { .notice $nick That isn't a pokemon! }
  916.     elseif (!%i) { .notice $nick That isn't an item! }
  917.     elseif ($p_item($.nick,%i) < 1) { .notice $nick You don't have a %i $+ ! }
  918.     elseif ($has_pokemon($.nick,%p) != has) { .notice $nick You don't have a %p $+ ! }
  919.     else {
  920.       if (%i == rare candy) {
  921.         noop $p_+exp(rare candy,%p)
  922.         p_item $.nick Rare_32candy -1          
  923.       }
  924.       elseif ($regex($2,/(T|H)M\d\d/i)) {
  925.         if (%i !isin $read(txt/pokemon/tmcom.txt,w,%p $+ *)) { .notice $nick %p can't learn that! }
  926.         else {
  927.           set -l %sql SELECT * FROM $sql_esc($.nick) WHERE pokemon=' $+ $sql_esc(%p) $+ '
  928.           set -l %query $sqlite_query(%pdb,%sql)
  929.           set -l %fetch $sqlite_fetch_row(%query,pkexp,$SQLITE_ASSOC)
  930.           sqlite_free %query
  931.           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)
  932.           var %nm = $tm(%i)
  933.           if ($istok($sql_re(%mlist),%nm,44)) { .notice $nick %p already knows that move! }
  934.           else {
  935.             p_item $.nick %i -1
  936.             if ($numtok(%mlist,44) < 4) {
  937.               msg $chan $sql_re(%p) learned %nm $+ !
  938.               sqlite_exec %pdb UPDATE $sql_esc($.nick) SET $+(m,$calc($numtok(%mlist,44) + 1)) =' $+ $sql_esc(%nm) $+ ' WHERE pokemon=' $+ $sql_esc(%p) $+ '
  939.             }
  940.             else {
  941.               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.)
  942.               p_mark $.nick $+(%p,|,%m1,$chr(44),%m2,$chr(44),%m3,$chr(44),%m4,$chr(44),%nm)
  943.               p_status $.nick tm
  944.             }
  945.           }
  946.         }
  947.       }
  948.       else { .notice $nick That doesn't do anything }
  949.     }
  950.   }
  951. }
  952. on *:text:!pokeitem*:#:{
  953.   if ($p_item($2-).name) {
  954.     tokenize 9 $p_item($2-).desc
  955.     msg $chan $1 [Type: $2 $+ ] $6
  956.   }
  957. }
  958. alias p_getitem {
  959.   set -l %sql SELECT name FROM p_items WHERE type LIKE $+('%,$1,$(%',0)) ORDER BY RANDOM() LIMIT 1
  960.   set -l %query $sqlite_query(%pdb,%sql)
  961.   set -l %fetch $sqlite_fetch_row(%query,pgitem,$SQLITE_ASSOC)
  962.   sqlite_free %query
  963.   var %x = $sql_re($hget(pgitem,name))
  964.   if ($hget(pgitem)) { hfree pgitem }
  965.   return %x
  966. }
  967. alias p_item {
  968.   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)
  969.   if ($isid) {
  970.     if ($prop == name) { return $gettok($read(%f,w,* $+ $1 $+ *),1,9) }
  971.     if ($prop == type) { return $gettok($read(txt/pokemon/items.txt,w,* $+ $1 $+ *),2,9) }
  972.     if ($prop == cost) { return $gettok($read(%f,w,* $+ $1 $+ *),3,9) }
  973.     if ($prop == desc) { return $read(txt/pokemon/items.txt,w,* $+ $1 $+ *) }
  974.     set -l %sql SELECT $sql_esc($2) FROM %t WHERE name=' $+ $sql_esc($1) $+ '
  975.     set -l %query $sqlite_query(%pdb,%sql)
  976.     set -l %fetch $sqlite_fetch_row(%query,pitem,$SQLITE_ASSOC)
  977.     sqlite_free %query
  978.     var %x = $hget(pitem,$sql_esc($2))
  979.     if ($hget(pitem)) { hfree pitem }
  980.     return %x
  981.   }
  982.   sqlite_exec %pdb UPDATE %t SET $sql_esc($2) $+ = $sql_esc($2) $iif($3,$3,+1) WHERE name=' $+ $sql_esc($1) $+ '
  983. }
  984. alias p_iug {
  985.   if ($prop == cost) { var %x = $replacex($1,Pokeball,10000,Greatball,20000,Potion,5000,Super Potion,25000,Hyper Potion,50000) }
  986.   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) }
  987.   return %x
  988. }
  989. alias p_cug {
  990.   set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($1) $+ '
  991.   set -l %query $sqlite_query(%pdb,%sql)
  992.   set -l %fetch $sqlite_fetch_row(%query,pcug,$SQLITE_ASSOC)
  993.   var %x = $iif($prop == ball,Pokeball,Potion)
  994.   while ($hget(pcug,$sql_esc($p_iug(%x)))) { %x = $p_iug(%x) }
  995.   if ($hget(pcug)) { hfree pcug }
  996.   sqlite_free %query
  997.   return %x
  998. }
  999. alias p_bmod {
  1000.   set -l %sql SELECT mod FROM p_items WHERE name=" $+ $sql_esc($1) $+ "
  1001.   set -l %query $sqlite_query(%pdb,%sql)
  1002.   set -l %fetch $sqlite_fetch_row(%query,pbmod,$SQLITE_ASSOC)
  1003.   var %x = $hget(pbmod,mod)
  1004.   if ($hget(pbmod)) { hfree pbmod }
  1005.   sqlite_free %query
  1006.   return %x
  1007. }
  1008. alias p_type {
  1009.   if (/ isin $1) { return $max($p_typex($gettok($1,1,47),$2),$p_typex($gettok($1,2,47),$2)) }
  1010.   else { return $p_typex($1,$2) }
  1011. }
  1012. alias p_typex {
  1013.   set -l %sql SELECT * FROM p_types WHERE type=' $+ $1 $+ ' COLLATE NOCASE
  1014.   set -l %query $sqlite_query(%pdb,%sql)
  1015.   set -l %fetch $sqlite_fetch_row(%query,ptype,$SQLITE_ASSOC)
  1016.   sqlite_free %query
  1017.   tokenize 47 $2
  1018.   if ($2) {
  1019.     var %x = $calc($hget(ptype,$1) + $hget(ptype,$2))
  1020.     if ($hget(ptype)) { hfree ptype }
  1021.     return $replacex(%x,2,0,3,0,5,0,9,0,4,.25,6,.5,10,1,8,1,12,2,16,4)
  1022.   }
  1023.   else {
  1024.     var %x = $hget(ptype,$1)
  1025.     if ($hget(ptype)) { hfree ptype }
  1026.     return $replacex(%x,1,0,2,.5,4,1,8,2)
  1027.   }
  1028. }
  1029. on *:text:!pokemon*:#:{
  1030.   var %a
  1031.   if ($2 isnum) { set -l %sql SELECT pokemon, lvl, pv FROM $sql_esc($.nick) WHERE lvl BETWEEN $2 AND 99 ORDER BY lvl ASC }
  1032.   else { set -l %sql SELECT pokemon, lvl, pv FROM $sql_esc($.nick) ORDER BY lvl ASC }
  1033.   set -l %query $sqlite_query(%pdb,%sql)
  1034.   while ($sqlite_fetch_row(%query,listp,$SQLITE_ASSOC)) {
  1035.     whilefix
  1036.     if ($2 isnum) {
  1037.       if ($hget(listp,lvl) > 9) {  %a = $addtok(%a,$p_shiny($.nick,$hget(listp,pv)) $sql_re($hget(listp,pokemon) $iif($p_rare($hget(listp,pokemon)),[Rare]) $+ $iif($p_uncom($hget(listp,pokemon)),[Uncommon]) ( $+ $hget(listp,lvl) $+ )),44) }
  1038.     }
  1039.     else { %a = $addtok(%a,$p_shiny($.nick,$hget(listp,pv)) $sql_re($hget(listp,pokemon) $iif($p_rare($hget(listp,pokemon)),[Rare]) $+ $iif($p_uncom($hget(listp,pokemon)),[Uncommon]) ( $+ $hget(listp,lvl) $+ )),44) }
  1040.     if ($numtok(%a,44) > 24) {
  1041.       .notice $nick %a
  1042.       %a = $null
  1043.     }
  1044.   }
  1045.   if (%a) { .notice $nick %a }
  1046.   if ($hget(listp)) { hfree listp }
  1047.   sqlite_free %query
  1048. }
  1049. on $*:text:/^!(poke)?dex(stat)?\s/i:#:{
  1050.   var %x = $pokemon($2-), %a = $replace($gettok($read(txt/pokemon/abilitylist.txt,w,$pokemon($2-).name $+ *),2,9),$chr(44),/), %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$)/,)
  1051.   if (%x) {
  1052.     msg $chan $iif($p_rare($2-),[Rare]) $iif($p_uncom($2-),[Uncommon]) $pokemon($2-).fmt [Height: $p_height($2-) $+ ] [Weight: $p_weight($2-) $+ ] [Ability: %a $+ ] [Evolution: $iif(%e,%e,Does not evolve) $+ ] $iif($has_pokemon($.nick,$2-),[Locations: %l $+ ])
  1053.     if (*stat* iswm $1) { msg $chan $pokemon($2-).name 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) $+ ]  }
  1054.   }
  1055. }
  1056. on *:text:!pokestat*:#:{
  1057.   if ($p_status($.nick)) {
  1058.     if ($2) && ($has_pokemon($.nick,$2-) != has) { .notice $nick You don't have a $2- $+ , $.nick $+ . }
  1059.     else { msg $chan $p_statfmt($.nick,$p_stat($.nick,$iif($2-,$pokemon($2-).name,$p_active($.nick)))) }
  1060.   }
  1061. }
  1062. alias p_statfmt {
  1063.   tokenize 9 $1 $+ $chr(9) $+ $sql_re($filltok($replace($2,*,$chr(9)),-,9))
  1064.   return $p_shiny($1,$3) $2 ( $+ $12 $+ ) $iif($p_gender($2,$3),$+([,$v1,])) [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) $+ ])
  1065. }
  1066. alias p_stat {
  1067.   var %x = $pokemon($2).name, %t = txt/pokemon/pstat $+ $ticks
  1068.   set -l %sql SELECT * FROM $sql_esc($1) WHERE pokemon=' $+ $sql_esc(%x) $+ '
  1069.   set -l %query $sqlite_query(%pdb,%sql)
  1070.   set -l %fetch $sqlite_fetch_all(%query,%t)
  1071.   if (!%fetch) { return error %sqlite_errstr }
  1072.   sqlite_free %query
  1073.   .timer 1 1 .remove %t
  1074.   %x = $filltok($read(%t,1),-,9)
  1075.   if ($prop == lvl) { return $gettok(%x,11,9) }
  1076.   if ($prop == exp) { return $gettok(%x,12,9) }
  1077.   if ($prop == vs) { return $pokemon($gettok(%x,1,9)).type $+ $chr(9) $+ $gettok(%x,13-18,9) }
  1078.   return %x
  1079. }
  1080. on *:text:!pokemove*:#:{
  1081.   tokenize 44 $replace($regsubex($2-,/\x2C(\s)/x,$chr(44)),*,.+?)
  1082.   if ($len($1) >= 3) {
  1083.     filter -cffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($1,/(\s)/g,.*) )(.+?)/ix
  1084.     if ($len($2) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($2,/(\s)/g,.*) )(.+?)/ix }
  1085.     if ($len($3) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($3,/(\s)/g,.*) )(.+?)/ix }
  1086.     if ($len($4) >= 3) { filter -ffg txt/pokemon/attacks.txt txt/pokemon/temp.txt /^[^\x09]*( $regsubex($4,/(\s)/g,.*) )(.+?)/ix }
  1087.     .fopen pmove txt/pokemon/temp.txt
  1088.     while ($fread(pmove)) {
  1089.       var %x = $v1
  1090.       msg $chan $iif($read(txt/pokemon/tms.txt,w,* $+ $gettok(%x,1,9) $+ *),( $+ $gettok($v1,1,9) $+ ) ) $pokemove(%x)
  1091.     }
  1092.     .fclose pmove
  1093.   }
  1094. }
  1095. alias pokemove {
  1096.   if ($2) { var %t = $2 }
  1097.   if ($prop == priority) { return $iif($read(txt/pokemon/priority.txt,r,/(^ $replace($1,$chr(32),\s) \x09)/ix),$gettok($v1,2,9),0) }
  1098.   if ($prop == stats) { return $read(txt/pokemon/attacks.txt,w,$sql_re($1) $+ *) }
  1099.   tokenize 9 $read(txt/pokemon/attacks.txt,w,$sql_re($1) $+ *)
  1100.   if ($prop == name) { return $1 }
  1101.   if ($prop == type) { return $2 }
  1102.   if (cat* iswm $prop) { return $3 }
  1103.   if ($prop == power) { return $4 }
  1104.   if (acc* iswm $prop) { return $5 }
  1105.   if ($prop == pp) { return $6 }
  1106.   if ($prop == effect) { return $7 }
  1107.   if (prob* iswm $prop) { return $8 }
  1108.   if ($prop == rating) {
  1109.     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))
  1110.   }
  1111.   if ($1) {
  1112.     return $1 [Type: $2 $+ ] [Category: $3 $+ ] $iif($4 != -,[Power: $4 $+ ]) $iif($5 != -,[Accuracy: $5 $+ ]) [PP: $6 $+ ] $iif($7 != -,[Effect: $iif($8 != -,$8 $+ % chance -) $7 $+ ])
  1113.   }
  1114. }
  1115. alias p_movesel {
  1116.   var %x = 1, %y = $numtok($2-,9), %t = $pokemon($1).type, %a, %cr, %m, %r = 0
  1117.   while (%x <= %y) {
  1118.     %a = $gettok($2-,%x,9)
  1119.     %cr = $pokemove(%a,%t).rating
  1120.     if (%cr > %r) { var %m = %a, %r = %cr }
  1121.     inc %x
  1122.   }
  1123.   return %m
  1124. }
  1125. on $*:text:/^!((T|H)M\d\d)(\slist)?$/i:#:{
  1126.   if ($2 == list) {
  1127.     var %a
  1128.     filter -cff txt/pokemon/tmcom.txt txt/pokemon/temp.txt * $+ $regml(1) $+ *  
  1129.     .fopen tmcom txt/pokemon/temp.txt
  1130.     while ($fread(tmcom)) {
  1131.       %a = $addtok(%a,$gettok($v1,1,9),44)
  1132.       if ($numtok(%a,44) > 14) {
  1133.         msg $chan %a
  1134.         %a = $null
  1135.       }
  1136.     }
  1137.     .fclose tmcom
  1138.     if (%a) { msg $chan %a }
  1139.   }
  1140.   else { msg $chan ( $+ $upper($regml(1)) $+ ) $pokemove($tm($regml(1))) }
  1141. }
  1142. alias tm {
  1143.   if ($1 isnum 1-3) {
  1144.     var %f = txt/pokemon/tm $+ $ticks, %a
  1145.     filter -ffg txt/pokemon/tms.txt %f /\x09( $1 )$/x
  1146.     %a = $read(%f)
  1147.     .remove %f
  1148.     return $gettok(%a,1,9)
  1149.   }
  1150.   tokenize 9 $read(txt/pokemon/tms.txt,w,$1 $+ *)
  1151.   if ($prop == r) { return $3 }
  1152.   if ($1) { return $2 }
  1153. }
  1154. on *:text:!ability*:#:{
  1155.   tokenize 9 $read(txt/pokemon/ability.txt,w,$2- $+ *)
  1156.   if ($1) { msg $chan $1 $+ : $2 }
  1157. }
  1158. on *:text:!nature*:#:{
  1159.   var %x = $replace($read(txt/pokemon/nature.txt,wn,$2- $+ *),%,$null)
  1160.   if (%x) {
  1161.     tokenize 32 %x
  1162.     msg $chan $1 $+ : $iif($2,+ $+ $2 - $+ $3,No effect)
  1163.   }
  1164.   else {
  1165.     var %a, %n = $2
  1166.     filter -cffg txt/pokemon/nature.txt txt/pokemon/temp.txt /\s% $2 \s/ix
  1167.     .fopen nature txt/pokemon/temp.txt
  1168.     while ($fread(nature)) {
  1169.       tokenize 32 $remove($v1,%)
  1170.       %a = $addtok(%a,$chr(32) $1 $+ : - $+ $3,44)
  1171.     }
  1172.     .fclose nature
  1173.     msg $chan + $+ $upper($2) natures: %a
  1174.   }
  1175. }
  1176. alias p_shiny {
  1177.   if (!$3) {
  1178.     set -l %sql SELECT id, sid FROM p_players WHERE name=" $+ $sql_esc($1) $+ "
  1179.     set -l %query $sqlite_query(%pdb,%sql)
  1180.     set -l %fetch $sqlite_fetch_row(%query,pshiny,$SQLITE_ASSOC)
  1181.     tokenize 32 $hget(pshiny,id) $hget(pshiny,sid) $2
  1182.     sqlite_free %query
  1183.   }
  1184.   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)))
  1185.   if (%x < 8) { msg #Flip shiny! }
  1186.   if ($hget(pshiny)) { hfree pshiny }
  1187.   return $iif(%x < 8,Shiny)
  1188. }
  1189. alias p_gender {
  1190.   var %x = $right($base($2,10,2),8), %t = $gettok($read(txt/pokemon/gender.txt,w,$1 $+ *),2,9)
  1191.   if (%t != 11111111) { return $iif(%x >= %t,Male,Female) }
  1192. }
  1193. alias p_height {
  1194.   noop $read(txt/pokemon/height.txt,w,* $+ $1- $+ *)
  1195.   return $gettok($read(txt/pokemon/height.txt,$readn),1,9)
  1196. }
  1197. alias p_weight { return $gettok($read(txt/pokemon/weight.txt,w,$1- $+ *),2,9) }
  1198. alias p_active {
  1199.   if ($isid) { return $p_player($1,active) }
  1200.   sqlite_exec %pdb UPDATE p_players SET active=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1201. }
  1202. alias p_team {
  1203.   if ($isid) { return $p_player($1,team) }
  1204.   sqlite_exec %pdb UPDATE p_players SET team=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1205. }
  1206. alias p_status {
  1207.   if ($isid) { return $p_player($1,status) }
  1208.   sqlite_exec %pdb UPDATE p_players SET status=' $+ $sql_esc($2) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1209. }
  1210. alias p_mark {
  1211.   if ($isid) { return $p_player($1,mark) }
  1212.   sqlite_exec %pdb UPDATE p_players SET mark=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1213. }
  1214. alias p_daycare {
  1215.   if ($isid) { return $p_player($1,daycare) }
  1216.   sqlite_exec %pdb UPDATE p_players SET daycare=' $+ $sql_esc($2-) $+ ' WHERE name=' $+ $sql_esc($1) $+ '
  1217. }
  1218. alias p_ps {
  1219.   if ($isid) { return $p_player($1,$2) }
  1220.   sqlite_exec %pdb UPDATE p_players SET $2 = $2 + 1 WHERE name=' $+ $sql_esc($1) $+ '
  1221. }
  1222. alias p_player {
  1223.   if ($isid) {
  1224.     set -l %sql SELECT $2 FROM p_players WHERE name=' $+ $sql_esc($1) $+ '
  1225.     set -l %query $sqlite_query(%pdb,%sql)
  1226.     set -l %fetch $sqlite_fetch_row(%query,player,$SQLITE_ASSOC)
  1227.     var %x = $iif($sql_re($hget(player,$2)),$v1,none)
  1228.     sqlite_free %query
  1229.     if ($hget(player)) { hfree player }
  1230.     return %x
  1231.   }
  1232.   else { sqlite_exec %pdb UPDATE p_players SET $2 =' $+ $sql_esc($3) $+ ' WHERE name=' $+ $sql_esc($1) $+ ' }
  1233. }
  1234. alias p_noncom { return $p_ini(cr,$1) }
  1235. alias p_ini {
  1236.   if ($isid) { return $readini(txt/pokemon/pokemon.ini,$1,$2) }
  1237.   else { writeini txt/pokemon/pokemon.ini $1 $2 $3 }
  1238. }
  1239. on *:text:*:#:{  
  1240.   if ($p_status($.nick) == choiceadv) && ($regex($1-,/^( $gettok($p_mark($.nick),1,42) )$/ix)) {
  1241.     var %m = $p_mark($.nick), %adv = $gettok(%m,2,42)
  1242.     if ($1 == leave) {
  1243.       msg $chan $nick $+ : You decide to leave and continue exploring.
  1244.       p_status $.nick ready
  1245.     }
  1246.     elseif (%adv isnum 11-30) || (%adv isnum 36-37) {
  1247.       var %i = $gettok(%m,3,42), %c = $gettok(%m,4,42)
  1248.       if ($1 == buy) {
  1249.         if ($p_item($.nick,cash) >= %c) {
  1250.           msg $chan $nick $+ : You buy the %i and continue on your journey.
  1251.           p_item $.nick $sql_esc(%i) +1
  1252.           p_item $.nick cash - $+ %c
  1253.           p_status $.nick ready
  1254.         }
  1255.         else { msg $chan $nick $+ : You don't have enough cash, so you continue on your journey. }
  1256.         p_status $.nick ready
  1257.       }
  1258.     }
  1259.     elseif (%adv == 38) {
  1260.       var %c = $gettok(%m,3,42)
  1261.       if ($p_item($.nick,cash) > %c) {
  1262.         msg $chan $nick $+ : You buy the $upper($1) and continue on your journey.
  1263.         p_item $.nick $upper($1) +1
  1264.         p_item $.nick cash - $+ %c
  1265.       }
  1266.       else { msg $chan $nick $+ : You don't have enough cash, so you continue on your journey. }
  1267.       p_status $.nick ready
  1268.     }
  1269.     elseif (%adv == daycare) {
  1270.       var %t = $p_team($.nick)
  1271.       if ($1 == yes) {
  1272.         if ($numtok(%t,124) < 6) {
  1273.           var %dcl = $calc($p_player($.nick,dcl) * 1000)
  1274.           if ($p_item($.nick,cash) < %dcl) { .notice $nick You don't have enough to pay The Daycare lady! }
  1275.           else {
  1276.             .notice $nick You take $p_daycare($.nick) with you.
  1277.             p_team $.nick $addtok(%t,$p_daycare($.nick),124)
  1278.             p_player $.nick dcl 0
  1279.             p_item $.nick cash - $+ %dcl
  1280.             p_daycare $.nick
  1281.           }
  1282.         }
  1283.         else { .notice $nick You don't have room in your team! }
  1284.       }
  1285.       elseif ($1 == no) { .notice $nick You leave The Daycare lady's house. }
  1286.       else {
  1287.         .notice $nick You let $1 stay with The daycare lady.
  1288.         p_team $.nick $remtok(%t,$1,1,124)
  1289.         p_daycare $.nick $pokemon($1).name
  1290.         if ($1 == $p_active($.nick)) { p_active $.nick $gettok($p_team($.nick),1,124) }
  1291.       }
  1292.       p_status $.nick ready
  1293.     }
  1294.   }
  1295. }
  1296. #pokemon end
  1297. alias p_reset {
  1298.   var %x = $iif($.nick($1).check,$.nick($1),$1)
  1299.   sqlite_exec %pdb DELETE * FROM p_pokemon WHERE name=' $+ $sql_esc(%x) $+ '
  1300.   sqlite_exec %pdb DELETE * FROM p_players WHERE name=' $+ $sql_esc(%x) $+ '
  1301.   sqlite_exec %pdb DELETE * FROM p_inventory WHERE name=' $+ $sql_esc(%x) $+ '
  1302.   sqlite_exec %pdb DELETE * FROM p_badges WHERE name=' $+ $sql_esc(%x) $+ '
  1303.   sqlite_exec %pdb DROP TABLE $sql_esc(%x)
  1304.   msg $chan %x reset
  1305. }
  1306. alias db_additem {
  1307.   var %a = $read(txt/pokemon/items.txt,w,$1- $+ *)
  1308.   sqlite_exec %pdb ALTER TABLE p_inventory ADD $sql_esc($1-) varchar(3) default 0
  1309.   sqlite_exec %pdb INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1310. }
  1311. alias db_flushitems {
  1312.   sqlite_exec %pdb DROP TABLE p_items
  1313.   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))
  1314.   var %x = 1, %y = $lines(txt/pokemon/items.txt), %a
  1315.   while (%x <= %y) {
  1316.     %a = $read(txt/pokemon/items.txt,%x)
  1317.     sqlite_exec %pdb INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1318.     inc %x
  1319.   }
  1320. }
  1321. alias _pdb {
  1322.   sqlite_exec %pdb CREATE TABLE p_types (type varchar(8),Normal varchar(2),Fighting varchar(2),Flying varchar(2),Poison varchar(2),Ground varchar(2),Rock varchar(2),Bug varchar(2),Ghost varchar(2),Steel varchar(2),Fire varchar(2),Water varchar(2),Grass varchar(2),Electric varchar(2),Psychic varchar(2),Ice varchar(2),Dragon varchar(2),Dark varchar(2))
  1323.   var %x = 2, %y = $lines(txt/pokemon/resource/chart.txt), %a
  1324.   while (%x <= %y) {
  1325.     var -s %a = $replace($read(txt/pokemon/resource/chart.txt,%x),;,' $+ $chr(44) $+ ')
  1326.     sqlite_exec %pdb INSERT INTO p_types VALUES (' $+ %a $+ ')
  1327.     inc %x
  1328.   }
  1329.  
  1330. }
  1331. alias gendb {
  1332.   var %sql.db = $sqlite_open(txt/pokemon/pokemon.new.db3)
  1333.   sqlite_begin %sql.db
  1334.   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), daycare varchar(20))
  1335.   sqlite_exec %sql.db CREATE TABLE p_badges (name varchar(20))
  1336.   sqlite_exec %sql.db CREATE TABLE p_pokemon (name varchar(20))
  1337.   var %x = 1, %y = $lines(txt/pokemon/pokemon.txt), %a
  1338.   while (%x <= %y) {
  1339.     %a = $gettok($read(txt/pokemon/pokemon.txt,%x),2,9)
  1340.     sqlite_exec %sql.db ALTER TABLE p_pokemon ADD $sql_esc(%a) char(1)
  1341.     inc %x
  1342.   }
  1343.   sqlite_exec %sql.db CREATE TABLE p_types (type varchar(8),Normal varchar(2),Fighting varchar(2),Flying varchar(2),Poison varchar(2),Ground varchar(2),Rock varchar(2),Bug varchar(2),Ghost varchar(2),Steel varchar(2),Fire varchar(2),Water varchar(2),Grass varchar(2),Electric varchar(2),Psychic varchar(2),Ice varchar(2),Dragon varchar(2),Dark varchar(2))
  1344.   var %x = 2, %y = $lines(txt/pokemon/resource/chart.txt), %a
  1345.   while (%x <= %y) {
  1346.     %a = $replace($read(txt/pokemon/resource/chart.txt,%x),;,' $+ $chr(44) $+ ')
  1347.     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 $+ ')
  1348.     inc %x
  1349.   }
  1350.   sqlite_exec %sql.db CREATE TABLE p_inventory (name varchar(20), Cash varchar(20))
  1351.   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))
  1352.   var %x = 1, %y = $lines(txt/pokemon/items.txt), %a
  1353.   while (%x <= %y) {
  1354.     %a = $read(txt/pokemon/items.txt,%x)
  1355.     sqlite_exec %sql.db ALTER TABLE p_inventory ADD $sql_esc($gettok(%a,1,9)) varchar(3) default 0
  1356.     sqlite_exec %sql.db INSERT INTO p_items VALUES (' $+ $replace($filltok($sql_esc(%a),-,9),$chr(9),' $+ $chr(44) $+ ') $+ ')
  1357.     inc %x
  1358.   }
  1359.   var %x = 1, %y = $lines(txt/pokemon/tms.txt), %a
  1360.   sqlite_exec %sql.db CREATE TABLE p_tm (name varchar(20))
  1361.   while (%x <= %y) {
  1362.     %a = $gettok($read(txt/pokemon/tms.txt,%x),1,9)
  1363.     sqlite_exec %sql.db ALTER TABLE p_tm ADD %a varchar(3) default 0
  1364.     inc %x
  1365.   }
  1366.   sqlite_exec %sql.db CREATE TABLE p_learnset (name varchar(50))
  1367.   %x = 1
  1368.   while (%x <= 99) {
  1369.     sqlite_exec %sql.db ALTER TABLE p_learnset ADD l $+ %x varchar(20)
  1370.     inc %x
  1371.   }
  1372.   var %x = 1, %y = $lines(txt/pokemon/learnset.txt), %a, %n, %t
  1373.   while (%x <= %y) {
  1374.     %a = $read(txt/pokemon/learnset.txt,%x)
  1375.     tokenize 9 %a
  1376.     %n = 1
  1377.     %t = $numtok($2,44)
  1378.     sqlite_exec %sql.db INSERT INTO p_learnset (name) VALUES (' $+ $replace($sql_esc($1),_44,*) $+ ')
  1379.     while (%n <= %t) {
  1380.       sqlite_exec %sql.db UPDATE p_learnset SET l $+ $replace($gettok($2,%n,44),|,=') $+ ' WHERE name=' $+ $replace($sql_esc($1),_44,*) $+ '
  1381.       inc %n
  1382.     }
  1383.     inc %x
  1384.   }
  1385.   sqlite_commit %sql.db
  1386.   sqlite_close %sql.db
  1387. }
  1388.  
  1389. on *:start:{ hmake pbattle 10 }
  1390. on 1000:text:!battle*:#:{
  1391.   if ($nick($chan,$2)) {
  1392.     var %p2 = $nick($chan,$v1)
  1393.     if (!$hget(pbattle,$nick)) && (!$hget(pbattle,%p2)) {
  1394.       msg $chan %p2 $+ , $nick has challenged you to a battle! You have 45 seconds to accept. [Accept] [Decline]
  1395.       hadd pbattle $nick %p2
  1396.       hadd pbattle %p2 $nick
  1397.       hadd pbattle $+(%p2,.accept) 1
  1398.       .timerpbattle 1 45 battle_end %p2 $chan
  1399.     }
  1400.   }
  1401. }
  1402. on $*:text:/^(accept|decline)$/i:#:{
  1403.   if ($hget(pbattle,$+($nick,.accept))) {
  1404.     if ($1 == decline) { battle_end $nick $chan }
  1405.     elseif ($1 == accept) {
  1406.       battle_init $hget(pbattle,$nick) $nick
  1407.       hdel pbattle $+($nick,.accept)
  1408.       .timerpbattle off
  1409.     }
  1410.   }
  1411. }
  1412. on *:text:*:#:{
  1413.   var %id = $hget(pbattle,$nick)
  1414.   if (%id) && ($pb_status(%id,$nick) == waiting) && $regex($1-,/^(item|switch| $pb_active(%id,$nick) ).+?/ix) {
  1415.     if ($1 == item) {
  1416.       var %p = $pokemon($iif($4,$4-,$3-)).name, %i = $p_item($iif($4,$iif($p_item($2 $3).name,$2 $3,$2),$2)).name
  1417.       if ($p_item(%i).type != battle) { .notice $nick You can't use that in battle! }
  1418.       elseif (!%p) { .notice $nick Unrecognized pokemon! }
  1419.       elseif (!$istok($p_team($.nick),%p,124) { .notice $nick %p isn't here! }
  1420.       elseif ($p_item($.nick,%i) < 1) { .notice $nick You Don't have a %i $+ ! }
  1421.       else {
  1422.         var %s = $pb_pkstatus(%id,$nick,%p), %hp = $pb_pkstat(%id,$nick,%p), %chp = $gettok(%hp,1,124), %mhp = $gettok(%hp,2,124)
  1423.         if (%i == revive) && (%s != fainted) { .notice $nick That will have no effect! }
  1424.         elseif (*potion* iswm %i) && (%chp == %mhp) { .notice $nick That will have no effect! }
  1425.         elseif (%i == antidote) && (!$istok(%s,poisoned,124)) { .notice $nick That will have no effect! }
  1426.         elseif (%i == paralyze heal) && (!$istok(%s,paralyzed,124)) { .notice $nick That will have no effect! }
  1427.         elseif (%i == awakening) && (!$istok(%s,asleep,124)) { .notice $nick That will have no effect! }
  1428.         elseif (%i == burn heal) && (!$istok(%s,burned,124)) { .notice $nick That will have no effect! }
  1429.         elseif (%i == ice heal) && (!$istok(%s,frozen,124)) { .notice $nick That will have no effect! }
  1430.         elseif (%i == full heal) && (%s != fainted) && (%s != ready) { .notice $nick That will have no effect! }
  1431.         elseif (%i == full restore) && (%s != fainted) && (%s != ready) && (%chp == %mhp) { .notice $nick That will have no effect! }
  1432.         else {
  1433.           pb_status %id $nick $+(item|,%i,|,%p)
  1434.           if ($pb_status(%id,$pb_op(%id,$nick)) != waiting) { battle_nextround %id }
  1435.           else { .notice $nick accepted, waiting on opponent }
  1436.         }
  1437.       }
  1438.     }
  1439.     elseif ($1 == switch) {
  1440.       var %p = $pokemon($2-).name
  1441.       if (!%p) { .notice $nick Unrecognized pokemon! }
  1442.       elseif (!$istok($p_team($.nick),%p,124)) { .notice $nick %p isn't here! }
  1443.       elseif (%p == $pb_active(%id,$nick)) { .notice $nick %p is already out! }
  1444.       elseif ($istok($pb_pkstatus(%id,$nick,%p),fainted,124)) { .notice $nick %p has already fainted! }
  1445.       else {
  1446.         pb_status %id $nick $+(switch|,%p)
  1447.         if ($pb_status(%id,$pb_op(%id,$nick)) != waiting) { battle_nextround %id }
  1448.         else { .notice $nick accepted, waiting on opponent }
  1449.       }
  1450.     }
  1451.     elseif ($1 == $pb_active(%id,$nick)) {
  1452.       var %p = $iif($pokemon($1 $2).name,$pokemon($1 $2).name,$pokemon($1).name), %m = $iif($pokemove($2-).name,$pokemove($2-).name,$pokemove($3-).name), %ml = $pb_ml(%id,$nick), %pp = $gettok(%ml,5-,124), %ml = $gettok(%ml,1-4,124), %pp = $gettok(%pp,$findtok(%ml,%m,1,124),124)
  1453.       if (!%m) { .notice $nick That isn't a move! }
  1454.       elseif (!$istok($sql_re(%ml),%m,124)) { .notice $nick $pokemon($1).name doesn't know %m $+ ! }
  1455.       elseif (%pp < 1) { .notice $nick %m is out of PP! }
  1456.       else {
  1457.         pb_status %id $nick $+(%m,|,%p)
  1458.         if ($pb_status(%id,$pb_op(%id,$nick)) != waiting) { battle_nextround %id }
  1459.         else { .notice $nick accepted, waiting on opponent }
  1460.       }
  1461.     }
  1462.   }
  1463. }
  1464. alias battle_init {
  1465.   var %t = $ticks, %id = p_ $+ $md5($+($1 $2 %t))
  1466.   hadd pbattle $1 %id
  1467.   hadd pbattle $2 %id
  1468.   sqlite_exec %pdb INSERT INTO p_battle VALUES (' $+ %id $+ ',' $+ $sql_esc($1) $+ ',' $+ $sql_esc($2) $+ ')
  1469.   sqlite_exec %pdb CREATE TABLE %id (id varchar(34), trainer varchar(20), status varchar(100), pokemon varchar(20), item varchar(20), lvl varchar(2), chp varchar(3), mhp varchar(3), catk varchar(3), atk varchar(3), cdef varchar(3), def varchar(3), cspatk varchar(3), spatk varchar(3), cspdef varchar(3), spdef varchar(3), cspd varchar(3), spd varchar(3), m1 varchar(20), pp1 varchar(2), m2 varchar(20), pp2 varchar(2), m3 varchar(20), pp3 varchar(2), m4 varchar(20), pp4 varchar(2))
  1470.   battle_insertinfo $1
  1471.   battle_insertinfo $2
  1472.   var %a1 = $p_active($.nick($1)), %a2 = $p_active($.nick($2))
  1473.   msg $chan $1 VS $2 $+ ! $1 sends out %a1 $+ , $2 sends out %a2 $+ !
  1474.   battle_nextround %id
  1475. }
  1476. alias battle_nextround {
  1477.   set -l %sql SELECT * FROM p_battle WHERE id=' $+ $1 $+ '
  1478.   set -l %query $sqlite_query(%pdb,%sql)
  1479.   set -l %fetch $sqlite_fetch_row(%query,$1,$SQLITE_ASSOC)
  1480.   sqlite_free %query
  1481.   var %p1 = $hget($1,p1), %p2 = $hget($1,p2), %a1 = $pb_active($1,$.nick(%p1)), %a2 = $pb_active($1,$.nick(%p2)), %stat1 = $pb_pkstat($1,%p1,%a1), %stat2 = $pb_pkstat($1,%p2,%a2), %s1 = $pb_status($1,%p1), %s2 = $pb_status($1,%p2), %spd1 = $+($pokemove($gettok(%s1,1,124)).priority,.,$gettok(%stat1,9,124)), %spd2 = $+($pokemove($gettok(%s2,1,124)).priority,.,$gettok(%stat2,9,124)), %bs1 = $+($1,|,%p1,|,%s1,|,%stat1), %bs2 = $+($1,|,%p2,|,%s2,|,%stat2)
  1482.   if (%s1 != ready) {
  1483.     if (%spd1 == %spd2) {
  1484.       battle_melee $iif($even($rand(1,10)),%bs1,%bs2)
  1485.       battle_melee $iif($odd($rand(1,10)),%bs2,%bs1)
  1486.     }
  1487.     else {
  1488.       battle_melee $iif(%spd1 > %spd2,%bs1,%bs2)
  1489.       battle_melee $iif(%spd1 > %spd2,%bs2,%bs1)
  1490.     }
  1491.   }
  1492.   pb_al $1 %p1
  1493.   pb_al $1 %p2
  1494. }
  1495. alias battle_melee {
  1496.   ;id player action info level chp mhp catk cdef cspatk cspdef cspd atk def spatk spdef cspd
  1497.   tokenize 124 $1-
  1498.   if ($3 == switch) {
  1499.     pb_active $1 $2 $4
  1500.     msg $chan $2 sends out $4 $+ !
  1501.   }
  1502.   elseif ($3 == item) {
  1503.     msg $chan $2 uses a $4 on $5 $+ !
  1504.   }
  1505.   else {
  1506.     var %m = $pokemove($3).stats, %name = $gettok(%m,1,9), %cat = $gettok(%m,3,9), %type = $gettok(%m,2,9), %acc = $gettok(%m,5,9), %power = $gettok(%m,5,9)
  1507.     if (%cat == status) { msg $chan $2 $+ : $4 uses %name $+ ! status type move, not coded yet }
  1508.     else {
  1509.       var %op = $pb_op($1,$2), %opactive = $pb_active($1,%op), %opstat = $pb_pkstat($1,%op,%opactive), %optype = $pokemon(%opactive).type, %atkstat = $iif(%cat == special,$10,$8), %defstat = $gettok(%opstat,$iif(%cat == special,$iif(%crit > 1,12,7),$iif(%crit > 1,10,5)),124)
  1510.       var %stab = $iif($istok($pokemon($4).type,%type,47),1.5,1), %crit = $iif($rand(1,10000) > 9374,2,1), %other = 1, %mod = $calc(%stab * $p_type(%type,%optype) * %crit * %other * $calc($rand(85,100) / 100)), %damage = $floor($calc(((((2 * $6 + 10) / 250)) * (%atkstat / %defstat) * %power + 2) * %mod))
  1511.       if (%damage >= $gettok(%opstat,3,124)) {
  1512.         msg $chan $2 $+ : $4 uses %name $+ ! Damage: %damage - %opactive fainted!
  1513.         sqlite_exec %pdb UPDATE $1 SET chp='0' WHERE pokemon=' $+ $sql_esc(%opactive) $+ ' AND trainer=' $+ $sql_esc($.nick(%op)) $+ ' AND id!='0'
  1514.       }
  1515.       else {
  1516.         msg $chan $2 $+ : $4 uses %name $+ ! Damage: %damage
  1517.         sqlite_exec %pdb UPDATE $1 SET chp=chp - %damage WHERE pokemon=' $+ $sql_esc(%opactive) $+ ' AND trainer=' $+ $sql_esc($.nick(%op)) $+ ' AND id!='0'
  1518.  
  1519.       }
  1520.     }
  1521.   }
  1522. }
  1523. alias battle_insertinfo {
  1524.   var %n = $.nick($1), %x = 1, %a, %id = $hget(pbattle,$1), %t = $+($p_active(%n),|,$remtok($p_team(%n),$p_active(%n),124))
  1525.   sqlite_exec %pdb INSERT INTO %id (id,trainer,status,pokemon) VALUES ('0',' $+ %n $+ ','ready',' $+ $p_active(%n) $+ ')
  1526.   while (%x <= 6) {
  1527.     whilefix
  1528.     var %p = $gettok(%t,%x,124), %stat = $p_stat(%n,%p), %item = $iif($gettok(%stat,6,9) != -,$v1,$null), %lvl = $gettok(%stat,11,9)
  1529.     var %hp = $gettok(%stat,13,9), %atk = $gettok(%stat,14,9), %def = $gettok(%stat,15,9), %spatk = $gettok(%stat,16,9), %spdef = $gettok(%stat,17,9), %spd = $gettok(%stat,18,9)
  1530.     var %m1 = $gettok(%stat,7,9), %m2 = $gettok(%stat,8,9), %m3 = $gettok(%stat,9,9), %m4 = $gettok(%stat,10,9), %pp1 = $pokemove(%m1).pp, %pp2 = $pokemove(%m2).pp, %pp3 = $pokemove(%m3).pp, %pp4 = $pokemove(%m4).pp
  1531.     %a = ' $+ %x $+ ',' $+ $sql_esc(%n) $+ ','ready',' $+ $sql_esc(%p) $+ ',' $+ $sql_esc(%item) $+ ',' $+ %lvl $+ ',' $+ %hp $+ ',' $+ %hp $+ ',' $+ %atk $+ ',' $+ %atk $+ ',' $+ %def $+ ',' $+ %def $+ ',' $+ %spatk $+ ',' $+ %spatk $+ ',' $+ %spdef $+ ',' $+ %spdef $+ ',' $+ %spd $+ ',' $+ %spd $+ ',' $+ $sql_esc(%m1) $+ ',' $+ %pp1 $+ ',' $+ $sql_esc(%m2) $+ ',' $+ %pp2 $+ ',' $+ $sql_esc(%m3) $+ ',' $+ %pp3 $+ ',' $+ $sql_esc(%m4) $+ ',' $+ %pp4 $+ '
  1532.     sqlite_exec %pdb INSERT INTO %id VALUES ( $+ %a $+ )
  1533.     inc %x
  1534.   }
  1535. }
  1536. alias pb_al {
  1537.   var %x, %a
  1538.   set -l %sql SELECT * FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND id!='0'
  1539.   set -l %query $sqlite_query(%pdb,%sql)
  1540.   while ($sqlite_fetch_row(%query,pbal,$SQLITE_ASSOC)) {
  1541.     whilefix
  1542.     if ($hget(pbal,pokemon) == $pb_active($1,$2)) { %x = $+([,$sql_re($hget(pbal,m1)),: $hget(pbal,pp1),]) $+([,$sql_re($hget(pbal,m2)),: $hget(pbal,pp2),]) $+([,$sql_re($hget(pbal,m3)),: $hget(pbal,pp3),]) $+([,$sql_re($hget(pbal,m4)),: $hget(pbal,pp4),]) }
  1543.     %a = $addtok(%a,( $+ $hget(pbal,lvl) $+ )  $+ $hget(pbal,pokemon) $+  $+([HP: ,$hget(pbal,chp),/,$hget(pbal,mhp),]) $iif($hget(pbal,status) != ready,$v1),124)
  1544.   }
  1545.   notice $2 Attacks - %x
  1546.   notice $2 Items - $pb_il($2)
  1547.   notice $2 Pokemon - $replace(%a,|,$chr(32) - $chr(32))
  1548.   pb_status $1 $2 waiting
  1549.   if ($hget(pbal)) { hfree pbal }
  1550.   sqlite_free %query
  1551. }
  1552. alias pb_ml {
  1553.   set -l %sql SELECT m1,m2,m3,m4,pp1,pp2,pp3,pp4 FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND pokemon=' $+ $pb_active($1,$2) $+ ' AND id!='0'
  1554.   set -l %query $sqlite_query(%pdb,%sql)
  1555.   set -l %fetch $sqlite_fetch_row(%query,pbml,$SQLITE_ASSOC)
  1556.   var %x = $+($hget(pbml,m1),|,$hget(pbml,m2),|,$hget(pbml,m3),|,$hget(pbml,m4),|,$hget(pbml,pp1),|,$hget(pbml,pp2),|,$hget(pbml,pp3),|,$hget(pbml,pp4))
  1557.   if ($hget(pbml)) { hfree pbml }
  1558.   sqlite_free %query
  1559.   return %x
  1560. }
  1561. alias pb_il {
  1562.   set -l %sql SELECT * FROM p_inventory WHERE name=' $+ $sql_esc($.nick($1)) $+ '
  1563.   set -l %query $sqlite_query(%pdb,%sql)
  1564.   set -l %fetch $sqlite_fetch_row(%query,pbinv,$SQLITE_ASSOC)
  1565.   var %x = $p_cug($.nick).potion ( $+ $hget(pbinv,potion) $+ ) - Revive: ( $+ $hget(pbinv,revive) $+ ) - Antidote ( $+ $hget(pbinv,Antidote) $+ ) - Paralyze heal ( $+ $hget(pbinv,Paralyze_32heal) $+ ) - Awakening ( $+ $hget(pbinv,Awakening) $+ ) - Burn heal ( $+ $hget(pbinv,Burn_32heal) $+ ) - Ice heal ( $+ $hget(pbinv,Ice_32heal) $+ ) - Full heal ( $+ $hget(pbinv,Full_32heal) $+ ) - Full restore ( $+ $hget(pbinv,Full_32restore) $+ )
  1566.   if ($hget(pbinv)) { hfree pbinv }
  1567.   sqlite_free %query
  1568.   return %x
  1569. }
  1570. alias pb_active {
  1571.   if ($isid) {
  1572.     set -l %sql SELECT pokemon FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND id='0'
  1573.     set -l %query $sqlite_query(%pdb,%sql)
  1574.     set -l %fetch $sqlite_fetch_row(%query,pbactive,$SQLITE_ASSOC)
  1575.     var %x = $hget(pbactive,pokemon)
  1576.     if ($hget(pbactive)) { hfree pbactive }
  1577.     sqlite_free %query
  1578.     return $sql_re(%x)
  1579.   }
  1580.   else { sqlite_exec %pdb UPDATE $1 SET pokemon=' $+ $sql_esc($3-) $+ ' WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND id='0' }
  1581. }
  1582. alias pb_status {
  1583.   if ($isid) {
  1584.     set -l %sql SELECT status FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND id='0'
  1585.     set -l %query $sqlite_query(%pdb,%sql)
  1586.     set -l %fetch $sqlite_fetch_row(%query,pbstatus,$SQLITE_ASSOC)
  1587.     var %x = $hget(pbstatus,status)
  1588.     if ($hget(pbstatus)) { hfree pbstatus }
  1589.     sqlite_free %query
  1590.     return $sql_re(%x)
  1591.   }
  1592.   else { sqlite_exec %pdb UPDATE $1 SET status=' $+ $sql_esc($3-) $+ ' WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND id='0' }
  1593. }
  1594. alias pb_pkstatus {
  1595.   if ($isid) {
  1596.     set -l %sql SELECT status FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND pokemon=' $+ $sql_esc($3) $+ ' AND id!='0'
  1597.     set -l %query $sqlite_query(%pdb,%sql)
  1598.     set -l %fetch $sqlite_fetch_row(%query,pkstatus,$SQLITE_ASSOC)
  1599.     var %x = $hget(pkstatus,status)
  1600.     if ($hget(pkstatus)) { hfree pkstatus }
  1601.     sqlite_free %query
  1602.     return $sql_re(%x)
  1603.   }
  1604.   else { sqlite_exec %pdb UPDATE $1 SET status=' $+ $4- $+ ' WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND pokemon=' $+ $sql_esc($3) $+ ' AND id!='0' }
  1605. }
  1606. alias pb_pkstat {
  1607.   ;status level chp mhp catk cdef cspatk cspdef cspd atk def spatk spdef spd
  1608.   if ($isid) {
  1609.     set -l %sql SELECT $iif($prop,$prop,*) FROM $1 WHERE trainer=' $+ $sql_esc($.nick($2)) $+ ' AND pokemon=' $+ $sql_esc($3) $+ ' AND id!='0'
  1610.     set -l %query $sqlite_query(%pdb,%sql)
  1611.     set -l %fetch $sqlite_fetch_row(%query,pkstat,$SQLITE_ASSOC)
  1612.     if ($prop) { var %x = $hget(pkstat,$prop) }
  1613.     else { var %x = $+($hget(pkstat,status),|,$hget(pkstat,lvl),|,$hget(pkstat,chp),|,$hget(pkstat,mhp),|,$hget(pkstat,catk),|,$hget(pkstat,cdef),|,$hget(pkstat,cspatk),|,$hget(pkstat,cspdef),|,$hget(pkstat,cspd),|,$hget(pkstat,atk),|,$hget(pkstat,def),|,$hget(pkstat,spatk),|,$hget(pkstat,spdef),|,$hget(pkstat,spd)) }
  1614.     if ($hget(pkstat)) { hfree pkstat }
  1615.     sqlite_free %query
  1616.     return $sql_re(%x)
  1617.   }
  1618. }
  1619. alias pb_op {
  1620.   if ($isid) {
  1621.     set -l %sql SELECT * FROM p_battle WHERE id=' $+ $1 $+ '
  1622.     set -l %query $sqlite_query(%pdb,%sql)
  1623.     set -l %fetch $sqlite_fetch_row(%query,pkop,$SQLITE_ASSOC)
  1624.     if ($2) { var %x = $iif($hget(pkop,p1) == $2,$hget(pkop,p2),$hget(pkop,p1)) }
  1625.     else { var %x = $hget(pkop,p1) $hget(pkop,p2) }
  1626.     if ($hget(pkop)) { hfree pkop }
  1627.     sqlite_free %query
  1628.     return $sql_re(%x)
  1629.   }
  1630. }
  1631. alias battle_end {
  1632.   msg $2 Ending battle!  
  1633.   hdel pbattle $hget(pbattle,$1)
  1634.   hdel pbattle $1
  1635.   hdel pbattle $+($1,.accept)
  1636. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement