SoireeExtreme Posted December 20, 2007 Share Posted December 20, 2007 Hi, I have created a very simple attack scripted for an online game I'm working on. But there is a little problem with it. And I've been trying to figure out how to fix it but I can't. See my problem is I need the script to deny a player a fight if the a player tries to fight themselves. If anyone could help me that would be great. Here is my code..... Thanks in advance. Everything here seems to be working pretty well so far. Just need help with what I said about thanks. <?php if (isset($_SESSION['player'])) { $player=$_SESSION['player']; $userstats="SELECT * from ac_users where playername='$player'"; $userstats2=mysql_query($userstats) or die("Could not get user stats"); $userstats3=mysql_fetch_array($userstats2); $atk1=$userstats3['attack']+$userstats3['attack']; if (!isset($_GET['ID'])) { print "No player was selected to attack.<br>"; } else { $playerID = $_GET['ID']; } $playertwo="SELECT * from ac_users where ID='$playerID'"; $playertwo2=mysql_query($playertwo) or die("Blah"); $playertwo3=mysql_fetch_array($playertwo2); $atk2=$playertwo3['defence']+$playertwo3['defence']; echo "<u>Player Challenge</u><P>"; echo "$userstats3[playername] VS $playertwo3[playername]"; $update=$userstats3['attack']/4; $update2=$playertwo3['attack']/4; if($userstats3[playername] =$playertwo3[playername]) { echo "<br>THis needs to be where a player can't attack themselves "; } else if($atk1>$atk2) { echo "<br>You Won!"; $skill="update ac_users set experience=experience+'$update' where playername='$player'"; mysql_query($skill); $skill2="update ac_users set experience=experience+'$update2' where ID='$playerID'"; mysql_query($skill2); } else if($atk2>$atk1) { echo "<br>You Lose! "; } else if($atk1=$atk2) { echo "<br>Its a Draw. "; } } else { print "Nope"; } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 just compare the user's ID to the one they're attacking. If they're the same, there's your error. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted December 20, 2007 Author Share Posted December 20, 2007 I've tried, and with the way the coding is I can't exactly figure it out. I'm gonna keep trying but in the mean time if someone could explain to me how to do it. That would be great. Or you can just tell me but then I wouldn't be learning anything. Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 I don't see anywhere you have tried. The user who is logged in, their ID should be in here: <?php $userstats3=mysql_fetch_array($userstats2); ?> Then do <?php if($userID == $playerID){ } ?> You might want to use a better name than $playerID, like $attackedPlayerID or something descriptive, since $player is the username of the logged in player, yes? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted December 20, 2007 Share Posted December 20, 2007 You do not under any circumstances do not want to try a game with procedural. You are going to want to rewrite it using OOP. I can't even imagine trying to quickly add features into an ever-growing game having to cut through procedural. YOu need to handle all of those things with OOP functions. You would have a function for attack inside your class. class Basics extends Core { function attack () { } } Your going to want to redo most of that in OOP if you try to cut through that code to update/change/enhance code you'll notice later on down the road that you will have 4-5 times the amount of time to enhance it as opposed to OOP. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted December 20, 2007 Author Share Posted December 20, 2007 Thanks for the help but I figured it out myself. Quote Link to comment 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.