Jiraiya Posted December 26, 2008 Share Posted December 26, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/138474-need-help-editing-my-script/ Share on other sites More sharing options...
carrotcake1029 Posted December 26, 2008 Share Posted December 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138474-need-help-editing-my-script/#findComment-723981 Share on other sites More sharing options...
Jiraiya Posted December 26, 2008 Author Share Posted December 26, 2008 ok how then would i make it so when a player picks another player to fight the scirpt wont run unless the targeted player has the location variable set to "Forest Of Death" Quote Link to comment https://forums.phpfreaks.com/topic/138474-need-help-editing-my-script/#findComment-723984 Share on other sites More sharing options...
carrotcake1029 Posted December 26, 2008 Share Posted December 26, 2008 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138474-need-help-editing-my-script/#findComment-723989 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.