Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


PHP RPG

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
Viral
Grandmaster Cheater Supreme
Reputation: 22

Joined: 24 Sep 2007
Posts: 1648

PostPosted: Mon Aug 02, 2010 8:53 am    Post subject: PHP RPG Reply with quote

Project set by Holland (along with a few lines of starter code).
Quite proud of it myself, first thing I've done in php.

I tried to clean it up and comment it somewhat.

http://viral.stop.stylin-on.me/at/coding/php/rpgs/

Code:
<?php

session_start();
if(!isset($_SESSION['your_hp'])) #Starting a new game / lost session.
{
 $_SESSION['potions'] = 3;
 $_SESSION['your_hp'] = 100;
 $_SESSION['his_hp'] = 100;
}

echo "<center>";

foreach ($_POST as $key => $value) { #Turning all $_POST into $_SESSION
  $_SESSION[$key] = $value;
}


echo $_SESSION["usname"] . " " . "- Viral's RPG<br>"; #Top info.
echo "-------------------------------<br>";
echo "<a href=./fightan.html>HARRRR</a><br><br>";

$attackverb = array("swipe"=>0, "stab"=>1, "lunge"=>2, "hack"=>3, "slash"=>4, "rush"=>5,); #verb array

if($_POST["attack"]) #attacking
{
   echo "You " . array_rand($attackverb,1) . " at your opponent!<br>";
   $damage = rand(3, 14);
   $opp_dam = rand (7, 26);
   echo "You dealt " . $damage . " damage. <br>";
   
   if($_SESSION['his_hp']<1) #so opponent doesn't attack after dead
      {
      session_destroy();
      echo "Victory!<br><br>";
      echo "<a href=./>Click here to play again</a>";   
      }   
      
   echo "Your opponent dealt you " . $opp_dam . " damage. <br><br>";
   $_SESSION['his_hp'] = $_SESSION['his_hp'] - $damage;
   $_SESSION['your_hp'] = $_SESSION['your_hp'] - $opp_dam;
}

if($_POST["counter"])
{
   $damage = rand(-34, 34);
   if($damage=="0")
   echo "No damage was inflicted.<br><br>";

   elseif($damage<"0")
      {
         echo "Your counter failed, and you took " . $damage*-1 . " damage!<br><br>"; #*-1 to remove negative, so output would make sense. eg. you took -5 damage. :|
         $_SESSION['your_hp'] = $_SESSION['your_hp'] + $damage;
      }

   else
      {
         echo "Counter successful! You've inflicted " . $damage . " damage!<br><br>";
         $_SESSION['his_hp'] = $_SESSION['his_hp'] - $damage;
      }
}

$heal = rand(1, 28);

if($_POST["drink"]) #messsssy
{
   if($_SESSION['your_hp']<100)
      {
         if($_SESSION['potions']==0) echo "No potions available.<br>";
         else
         {
            $_SESSION['your_hp'] = $_SESSION['your_hp'] + $heal;
            $_SESSION['potions']--;
            echo "Health replenished.<br>";
         
               if($_SESSION['your_hp']>99) #making sure you don't get buffed health
                  {
                     $_SESSION['your_hp'] = 100;
                  }
         }
      }

         else
            {
               echo "Your health is already full!<br>";
            }
         echo "You have " . $potions . " potion(s) remaining.<br>";
      }

if($_SESSION['his_hp']<1) $_SESSION['his_hp'] = 0; #no negative health
if($_SESSION['your_hp']<1) $_SESSION['your_hp'] = 0;

echo "<b><br>You now have " . $_SESSION['your_hp'] . " health left.</b><br>";
echo "<b>Your opponent has " . $_SESSION['his_hp'] . " health left.</b><br><br>";

if($_SESSION['his_hp']<1) #victory
{
   session_destroy();
   echo "Victory!<br><br>";
   echo "<a href=./>Click here to play again</a>";
}

elseif($_SESSION['your_hp']<1) #death
{
   session_destroy();
   echo "You have died. :(<br><br>";
   echo "<a href=./>Click here to play again</a>";
}

echo "</center>";

?>

_________________
i'll shit on your face
Back to top
View user's profile Send private message
C-Dizzle
Grandmaster Cheater
Reputation: 89

Joined: 16 Mar 2008
Posts: 623

PostPosted: Mon Aug 02, 2010 9:04 am    Post subject: Reply with quote

Thanks for posting this, it should help me a lot. Smile
Back to top
View user's profile Send private message
Cryoma
Member of the Year
Reputation: 195

Joined: 14 Jan 2009
Posts: 1848

PostPosted: Mon Aug 02, 2010 3:11 pm    Post subject: Reply with quote

Quote:
Cryoma - Viral's RPG
-------------------------------
HARRRR

You lunge at your opponent!
You dealt 11 damage.
Your opponent dealt you 14 damage.


You now have 0 health left.
Your opponent has 0 health left.

Victory!

Click here to play again


Yeah I dunno, seems pretty difficult.
Back to top
View user's profile Send private message
Garavito
Master Cheater
Reputation: 0

Joined: 21 Jun 2009
Posts: 387

PostPosted: Mon Aug 02, 2010 5:10 pm    Post subject: Reply with quote

I'm not good at PHP and this looks super hard.
_________________
Back to top
View user's profile Send private message
[WQW]Xellos
Grandmaster Cheater
Reputation: 0

Joined: 21 Feb 2009
Posts: 504
Location: /dev/null

PostPosted: Mon Aug 02, 2010 6:18 pm    Post subject: Reply with quote

My code

Code:
<?php
include_once 'connect.php';
session_start();
include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php

///////////////////////////////////


if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>
<?php
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerhp = $playerinfo3['hpoints'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];


if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$name = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];

if ($type == "healing")
{
   $newhp = $statadd + $playerhp;
   if ($newhp > $playerinfo3['maxhp'])
   {
    $newhp = $playerinfo3['maxhp'];
   }
    $updateplayer="update players set hpoints='$newhp' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where name='$name' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");
   
   $playerhp = $newhp;
 
  echo "Used " . $name . " and recovered " . $statadd . ".<br>";
}

}}
////////////////////////////////



if (isset($_GET['creature']))
{
   $creature=$_GET['creature'];
   $creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
  $creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['hpoints'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];


?>
<div id="player">
<?php
/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Hit points = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";
?>
</div>
<div id="creature">
<?php
///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Hit points = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php?creature=$creature'>Attack!";

echo "<br><a href='useitem.php?creature=$creature'>Use Item";
echo "<br><a href='store.php?creature=$creature'>Go to Store";


?>
</div>

<div id="logout">
<?php
echo "<br><a href='logout.php'><img src='images/logout.gif'>";
?>
</div>
Back to top
View user's profile Send private message
Viral
Grandmaster Cheater Supreme
Reputation: 22

Joined: 24 Sep 2007
Posts: 1648

PostPosted: Tue Aug 03, 2010 2:04 am    Post subject: Reply with quote

Fixed, Cryoma.

Code:
if($_POST["attack"]) #attacking
{
   echo "You " . array_rand($attackverb,1) . " at your opponent!<br>";
   $damage = rand(3, 14);
   $opp_dam = rand (7, 26);
   echo "You dealt " . $damage . " damage. <br>";
   $_SESSION['his_hp'] = $_SESSION['his_hp'] - $damage;
   
   if($_SESSION['his_hp']<1) #so opponent doesn't attack after dead
      {
         echo "<br><br><b>You now have " . $_SESSION['your_hp'] . " health left.</b><br>";
         echo "<b>Your opponent now has 0 health left.</b><br><br>";
         echo "<br>Victory!<br><br>";
         echo "<a href=./>Click here to play again</a>";   
         session_destroy();
         exit;
      }   
      
      echo "Your opponent dealt you " . $opp_dam . " damage. <br><br>";
      $_SESSION['your_hp'] = $_SESSION['your_hp'] - $opp_dam;
}


Also fixed potions telling you that you have none remaining in two different ways.

Code:
if($_POST["drink"]) #messsssy
{
   if($_SESSION['your_hp']<100)
      {
         if($_SESSION['potions']==0) echo "No potions available.<br>";
         else
         {
            $_SESSION['your_hp'] = $_SESSION['your_hp'] + $heal;
            $_SESSION['potions']--;
            echo "Health replenished.<br>";
            echo "You have " . $potions . " potion(s) remaining.<br>";
         
               if($_SESSION['your_hp']>99) #making sure you don't get buffed health
                  {
                     $_SESSION['your_hp'] = 100;
                  }
         }
      }
   else
      {
         echo "Your health is already full!<br>";
      }
}

_________________
i'll shit on your face
Back to top
View user's profile Send private message
Cryoma
Member of the Year
Reputation: 195

Joined: 14 Jan 2009
Posts: 1848

PostPosted: Tue Aug 03, 2010 4:06 pm    Post subject: Reply with quote

Did you add a tie for dual-KO?
And maybe the enemy can use potions too?
Back to top
View user's profile Send private message
EasSidezz
Master Cheater
Reputation: 2

Joined: 20 Jul 2010
Posts: 284
Location: Somewhere around the netz...

PostPosted: Tue Aug 03, 2010 4:09 pm    Post subject: Reply with quote

1st thing i noticed was

HARRRR

And the link says Arepeegee.

Best
Thing
Evar
Back to top
View user's profile Send private message
Maes
Advanced Cheater
Reputation: 10

Joined: 09 Apr 2009
Posts: 53

PostPosted: Tue Aug 03, 2010 5:31 pm    Post subject: Reply with quote

Would it be a good idea to make it where you can login and store items?
_________________
Account reclaimed by former owner?
Back to top
View user's profile Send private message
Viral
Grandmaster Cheater Supreme
Reputation: 22

Joined: 24 Sep 2007
Posts: 1648

PostPosted: Wed Aug 04, 2010 12:03 am    Post subject: Reply with quote

Cryoma wrote:
Did you add a tie for dual-KO?
And maybe the enemy can use potions too?

Possibly.
If I add a new enemy type, perhaps they'll be able to heal.
The reason I didn't for this one is that I made him somewhat OP, so you'd actually need potions.

Rokurai wrote:
Would it be a good idea to make it where you can login and store items?

Yes.
Though I assume that'd require mysql and such, and I've got less than no idea how to do that currently.

_________________
i'll shit on your face
Back to top
View user's profile Send private message
Lyfa
The Lonely Man
Reputation: 11

Joined: 02 Nov 2008
Posts: 744

PostPosted: Sat Aug 07, 2010 5:02 am    Post subject: Reply with quote

Just saw this and tested on your site:
Your script is open to XSS (Cross site scripting) because you're not sanitizing the user's name.
Change
Code:
echo $_SESSION["usname"] . " " . "- Viral's RPG<br>"; #Top info.
to
Code:
echo htmlspecialchars($_SESSION["usname"]) . " " . "- Viral's RPG<br>"; #Top info.

That'll make it so it echos out stuff like <script> and it's contents as text and not HTML

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Web Development All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites