Jump to content

i need a hand please


oldspicelong

Recommended Posts

im trying to edit my script so that it only runs the script if the "location" variable for both players is equal to "Forest Of Death"

here is what i have so far

 

<?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>";







$target = $_GET['target'];

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

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


IF ($mylocation == $hislocation) {
//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

$result = mysql_query("SELECT `location` FROM `users` WHERE `username` = '$username'") or die(mysql_error());
$row = mysql_fetch_row($result);
$mylocation = $row[0]; // should be 0 since location is the only column that should be returned.

$result = mysql_query("SELECT `location` FROM `users` WHERE `username` = '$target'") or die(mysql_error());
$row = mysql_fetch_row($result);
$hislocation = $row[0]; // should be 0 since location is the only column that should be returned.

 

Edit:

Oh and as for the needing a hand....*claps very zealously over and over*

Link to comment
Share on other sites

"I dont think it worked" ....classic, should be added to a signature.

 

<?php
session_start(); // start sessions up here.

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>";

$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) {
     echo 'Yes it still worked cause they can attack me! His Location: ' . $hislocation . ' MyLocation: ' . $mylocation;
}
else {
     echo 'Yes it still worked cause they cannot attack me! His Location: ' . $hislocation . ' MyLocation: ' . $mylocation;
}

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>

 

Now give that a try, if it does not work, report back "What is not working and How it should be working". Not just, its not working. Cause that does not tell us anything.

Link to comment
Share on other sites

i need it to only allow the player to attack the other player if both players location is set to "Forest Of Death" so a player cant attack another player that is anywere else

 

I gathered that much.

 

What does this:

$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 (strtolower($mylocation) == strtolower($hislocation)) { // strtolower added to avoid mis-types of case.
     echo 'Yes it still worked cause they can attack me! His Location: ' . $hislocation . ' MyLocation: ' . $mylocation;
}
else {
     echo 'Yes it still worked cause they cannot attack me! His Location: ' . $hislocation . ' MyLocation: ' . $mylocation;
}

 

return?

Link to comment
Share on other sites

if (strtolower($mylocation) != strtolower($hislocation)) { // strtolower added to avoid mis-types of case.
     echo 'You cannot attack that player as they are not in the same area as you.';
     exit;
}

 

Replace that if/else section with the above. If the users are not in the same area then that will display and exit.

 

Whether this is what you want or not I do not know. You are too vague and cannot seem to grasp that the above code I have posted is what you want you just have to apply your own logic to it.

 

Good luck!

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.