Jump to content

need help editing my script


Jiraiya

Recommended Posts

i need help editing my script. i tried to do it my self but it didn't work. im trying to make it so my attack player script will only run if the location variable for both players is set to "Forest Of Death"

 

 

 

 

 

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());

$username = $_COOKIE['ID_my_site']; 
mysql_query("UPDATE `users` SET `location` = 'Forest Of Death' WHERE username = '$username'") or die(mysql_error());
echo "<center>You have entered the Forest of Death. death lurks around every corner, every tree, every face... " . "</center>";


$playerA = "Forest Of Death";
$playerB = "Forest Of Death";

IF ($playerA == $playerB) {
//they can attack
}
else {
//they can't attack
}






session_start();
if(!isset($_GET['user']))
{
echo "You have not selected a user to fight!<br><br>";
$NPCS = mysql_query("SELECT * FROM `users`");
while($Show = mysql_fetch_array($NPCS))
  {
  echo "<a href=\"AttackPlayer.php? Action=Attack&user=" . $Show['username'] . "\">" . $Show['username'] . "</a><br>";
  }
exit();
}
$NPC = mysql_escape_string($_GET['user']);
$username = $_COOKIE['ID_my_site'];
if($_GET[Action] = Attack)
{
if($username == $NPC){echo "You cannot fight yourself! <br><br>"; exit();}
$UserS = mysql_query("SELECT * FROM `users` WHERE username='$username'");
$UserS = mysql_fetch_array($UserS);
$UserH = $UserS['health'];
if($UserH == '0'){echo "You have no health you cannot fight! <br><br>"; exit();}
$UserA = $UserS['skill'];
$UserK = $UserS['kills'] +1;
$UserSkill = $UserS['skill'];
$UserA *= .1;
$NPCS = mysql_query("SELECT * FROM `users` WHERE username='$NPC'");
$NPCS = mysql_fetch_array($NPCS);
$NPCH = $NPCS['health'];
if($NPCH == '0'){echo "You cannot attack someone that has no health! <br><br>"; exit();}
$NPCA = $NPCS['skill'];
$NPCSkill = $NPCS['skill'];
$NPCA *= .1;


$run = 1;
While($run > 0){
$NPCH -= $UserA;
if($NPCH <= 0)
  {
  $xp = $NPCSkill * .035;
  echo "You win and have gained " . $xp . " skill from " . $NPC . "";
  $UserA = $UserSkill + $xp;
  mysql_query("UPDATE `users`
  SET skill='$UserA', health='$UserH', kills='$UserK'
  WHERE username='$username'");

  $NPCA = $NPCSkill * .97;
  mysql_query("UPDATE `users`
  SET skill='$NPCA', health='0'
  WHERE username='$NPC'");

  exit();
  }

$UserH -= $NPCA;
if($UserH <= 0)
  {
  echo "You have lost";
  $xp = $UserSkill * .035;
  $UserA = $NPCSkill + $xp;
  mysql_query("UPDATE `users`
  SET skill='$UserA', health='$UserH', kill='kill +1'
  WHERE username='$NPC'");

  $UserA = $UserSkill * .97;
  mysql_query("UPDATE `users`
  SET skill='$UserA', health='0'
  WHERE username='$username'");

  exit();
  }
}
}

?>

</body>
</html>

Link to comment
Share on other sites

UPDATE will change the value in your MySQL table.  You should use SELECT on both queries.  Then you compare the results of your queries for both players, and if they are both in the same place, have them attack.  Otherwise, spit out a message saying they aren't in the correct location.

 

I don't see two different queries for the two different players for comparison.

Link to comment
Share on other sites

Probably something like this.  Forgive me if I made any typos.  You might need to change some things to suit your needs.  I am using $_GET['target'] to get the target's name.  You can change the method to get the name though, it doesn't matter.

 

<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());

$username = $_COOKIE['ID_my_site']; 
$target = $_GET['target'];

$result = mysql_query("SELECT `location` FROM `users` WHERE `username` = '$username'") or die(mysql_error());
$row = mysql_fetch_row($result);
$mylocation = $row[0];

$result = mysql_query("SELECT `location` FROM `users` WHERE `username` = '$target'") or die(mysql_error());
$row = mysql_fetch_row($result);
$hislocation = $row[0];


IF ($mylocation == $hislocation) {
//they can attack
}
else {
//they can't attack
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.