Advertisement
Flip

Untitled

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