currend Posted November 29, 2008 Share Posted November 29, 2008 Hello. I am having a problem with a game. Let me explain. I am working on a game and there seems to be a problem. In the game a user can go into a "SafeHouse" to prevent them from being attacked. This is as follows: else if ($r['safehouse'] == 1) { print "This person is in a safehouse. You cannot attack this player.<br /> <a href='index.php'>Back</a>"; $h->endpage(); exit; } else if ($ir['safehouse'] == 1) { print "You are in a safe house you cannot attack other players.<br /> <a href='index.php'>Back</a>"; $h->endpage(); exit; } The problem with this is. If i go into a safe house someone can still attack me. Yet if i try to attack someone I get the message saying i can't attack because im in a safehouse. (which is how that one should be handled). I just dont know how to fix whatever is causing the users to still be able to attack people who are in the safe house. I have tried the > 0 but that still doesn't work. Can someone enlighten me on what i am doing wrong? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 29, 2008 Share Posted November 29, 2008 Check the respective values of $r['safehouse'] and $ir['safehouse'].... because that's what determines who can attack whom, and we have no idea how you are setting the two arrays. Quote Link to comment Share on other sites More sharing options...
currend Posted November 29, 2008 Author Share Posted November 29, 2008 What can i show you to give you more detail? 0 = Not in safehouse 1 = In safehouse I guess this is what you wanted to see Even when my accounts 'safehouse' value is 1 it still allows other users to attack me Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 29, 2008 Share Posted November 29, 2008 OK then, what was the if test and related code that came before else if ($r['safehouse'] == 1) Quote Link to comment Share on other sites More sharing options...
currend Posted November 29, 2008 Author Share Posted November 29, 2008 Here is everything above it <?php $menuhide=1; $atkpage=1; include "globals.php"; $_GET['ID'] == (int) $_GET['ID']; if(!$_GET['ID']) { print "WTF you doing, bro?"; $h->endpage(); exit; } else if($_GET['ID'] == $userid) { print "Only the crazy attack themselves."; $h->endpage(); exit; } else if ($i['safehouse'] == 1) { print "This person is in a safehouse. You cannot attack this player.<br /> <a href='index.php'>Back</a>"; $h->endpage(); exit; } else if ($ir['safehouse'] == 1) { print "You are in a safe house you cannot attack other players.<br /> <a href='index.php'>Back</a>"; $h->endpage(); exit; } Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 29, 2008 Share Posted November 29, 2008 I still can't see where the arrays $i, $r and $ir are coming from. From the code you're showing, what message is actually being displayed? Is it showing the "WTF you doing, bro?" or "Only the crazy attack themselves" messages? Or is it dropping through the entire if test to whatever comes after? Quote Link to comment Share on other sites More sharing options...
currend Posted November 29, 2008 Author Share Posted November 29, 2008 Yea its going down the list and if any of the values are met it gives the message associated. It starts from the top and works its way down. Any ideas? Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 29, 2008 Share Posted November 29, 2008 In that case, it's not meeting the conditions. Suggest you go back and look at what the values in $i, $r and $ir actually are. Quote Link to comment Share on other sites More sharing options...
currend Posted November 29, 2008 Author Share Posted November 29, 2008 In that case, it's not meeting the conditions. Suggest you go back and look at what the values in $i, $r and $ir actually are. Where would i look to find these? I have searched everywhere and can't find anything that is associated with it. Also, if i modify the line in question then i can't attack anyone else when im NOT in safehouse... just a strange script. If i send you what you need to know can you modify ti for me as i dont want to screw anything up Quote Link to comment Share on other sites More sharing options...
chronister Posted November 29, 2008 Share Posted November 29, 2008 Basically you have to look closer at your logic.... echo stuff to see what is failing where. If you expecting a var to be equal to 1, then echo it out and see what it is set to. Echoing stuff is the best way to find flawed logic. You have to test each step and even set things to what you want, to get the results you want. echo echo echo... that is my #1 solution to problems like this... echo all the vars you are using in the if/elseif/else chain you got going on there... Nate Quote Link to comment Share on other sites More sharing options...
currend Posted November 29, 2008 Author Share Posted November 29, 2008 I have no idea what echo is altho i have seen it. I am not LITERATE at all in this. This was a simple MOD that I added. All other parts of the mod work except this one. I just dont understand WHY its failing. Would anyone be willing to take the PHP file and modify it or play around with it even if i must give access to myPhPadmin. I seriously dont mind as long as i can get this problem resolved. Quote Link to comment Share on other sites More sharing options...
chronister Posted November 30, 2008 Share Posted November 30, 2008 Then you need to take a look at php coding 101.... your trying to debug a script but don't know what it really means to echo stuff <?php $var1 = 'This is variable 1'; echo $var1; ?> Learn what that really does for you and you will be a step closer to learning this stuff. Nate 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.