This script logs into tppcrpg.net, starts a battle with this trainer, and automatically kills the first pokemon. Is there anything wrong with this that anyone sees? because I can’t get it to work properly. it automatically resets the battle to a gym battle. this has been bugging me all day because it should be so simple but i cant get it to work.
[code=php]
<?php
// this function gets the encryption key
// i think this might be the problem
// it works but then it adds some other part of the string to the end which
// makes the key useless
function get_encryption($string){
$position=strlen(‘name=”Encrypt” value=”‘)+strpos($string, ‘name=”Encrypt” value=”‘);
$length=strpos($string, ‘”><input type=”button” value=”Attack!” onclick=’)-$position;
$extraction=substr($string, $position, $length);
return $extraction;
}
// this function is repeated
function pokemanz(){
$ch = curl_init();
//login
curl_setopt($ch, CURLOPT_URL, ‘http://tppcrpg.net/login.php’);
curl_setopt($ch, CURLOPT_POST, 1);
//username and password
curl_setopt($ch, CURLOPT_POSTFIELDS, ‘LoginID=username&NewPass=pass’);
curl_setopt($ch, CURLOPT_COOKIEJAR, cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, cookiefile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
//select battle trainer
curl_setopt($ch, CURLOPT_URL, ‘http://tppcrpg.net/battle.php?Battle=Trainer&Against=1212849’);
$string=curl_exec($ch);
echo $string;
//keep attacking until someone faints
while (strpos($string, ‘fainted’)==FALSE) {
//find encryption key in $string
$encrypt=get_encryption($string);
echo $encrypt;
curl_setopt($ch, CURLOPT_URL, ‘http://tppcrpg.net/battle.php’);
//set move and encryption key
curl_setopt($ch, CURLOPT_POSTFIELDS, “Encrypt={$encrypt}&Move=FIREBLAST”);
$string=curl_exec($ch);
echo $string;
}
echo $string;
curl_close($ch);
}
//run script until i feel like stopping it (dont worry its on my own server)
while (1<2)
{
pokemanz();
}
?>