oldspicelong Posted January 6, 2009 Share Posted January 6, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/ Share on other sites More sharing options...
dezkit Posted January 6, 2009 Share Posted January 6, 2009 Nevermind Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-731026 Share on other sites More sharing options...
oldspicelong Posted January 8, 2009 Author Share Posted January 8, 2009 can anyone help me with this please? Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732635 Share on other sites More sharing options...
Brian W Posted January 8, 2009 Share Posted January 8, 2009 Looks good, what is wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732671 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 $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* Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732673 Share on other sites More sharing options...
oldspicelong Posted January 8, 2009 Author Share Posted January 8, 2009 well im having trouble getting it to only run the the this script if both the player attacking and the target player have there location variables both set to " Forest Of Death" Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732678 Share on other sites More sharing options...
Brian W Posted January 8, 2009 Share Posted January 8, 2009 did the post from premiso fix it? (good catch premiso) If not, your going to need to be very specific about what you mean by "having trouble". Do you get an error? Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732680 Share on other sites More sharing options...
oldspicelong Posted January 8, 2009 Author Share Posted January 8, 2009 i missied the prismo fix let me try that Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732682 Share on other sites More sharing options...
oldspicelong Posted January 8, 2009 Author Share Posted January 8, 2009 i dont think it wokred Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732691 Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 "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. Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-732695 Share on other sites More sharing options...
oldspicelong Posted January 9, 2009 Author Share Posted January 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-733574 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-733577 Share on other sites More sharing options...
oldspicelong Posted January 9, 2009 Author Share Posted January 9, 2009 it replied You have entered the Forest of Death. death lurks around every corner, every tree, every face... Yes it still worked cause they cannot attack me! His Location: MyLocation: Forest Of DeathYou win and have gained 7.35 skill from Hatake Kakashi Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-733581 Share on other sites More sharing options...
premiso Posted January 9, 2009 Share Posted January 9, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/139722-i-need-a-hand-please/#findComment-733583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.