Phpfr3ak Posted October 17, 2010 Share Posted October 17, 2010 The issue is that if you f5 once attacking another player you can attack them again without any error message... Below is the code, is there a way to prevent the refresh from making the attack happen again? <?php $sql = "SELECT * FROM messages WHERE to_username = '$defender_info[username]' AND from_username = '$playerdata[username]' AND type = 'Combat' ORDER BY id DESC LIMIT 1"; $que = mysql_query($sql) or die(mysql_error()); $res = mysql_fetch_array($que); $now = time(); $lastattack = strtotime($res['timestamp']); $timesince = $now - $lastattack; $nextatk = round((10800 - $timesince) / 60); if($timesince < 10800){ echo "You can only attack the same player once every 3 hours.<br><br> You can attack this player again in $nextatk minutes."; } else{ $sql = "SELECT hits FROM users WHERE id = $playerID"; $que = mysql_query($sql) or die(mysql_error()); $res = mysql_fetch_array($que); $hits = $res['hits']; if($hits < 1){ echo "You have no available hits. New hit allowances are granted every ten minutes on the :05's"; } else{ ?> Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted October 17, 2010 Share Posted October 17, 2010 The best way to deal with this is to log the attack in it's own table called Attack_Log or whatever. Fields called attack_id, attacker_id, defender_id, attack_time. Then insert the data after the attack has took place, when the attack is completed and logged. Search the log for the attacker_id and defender_id and then compare the attack time to the current time and check the difference, if it is less than allowed cancel attack and show error message of some sort, if not the continue with attack. How that makes sense? Regards, Paul. Quote Link to comment Share on other sites More sharing options...
Phpfr3ak Posted October 17, 2010 Author Share Posted October 17, 2010 Thats exactly how i have it set up at the moment via the message is sent as an attack message instead of say player message... yet its still not working if i leave the page and go to attack again the error message is there... yet if i refresh the page after the attack i can use all the hits/as many attacks as i want. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted October 17, 2010 Share Posted October 17, 2010 Are you actually inserting the attack into the log on the same page as you are attacking another player/NPC? If so, show us that code also, it may be that it is not inserting correctly. I'm not too sure atm, with only a small snippet of code on hand. Regards, Paul. 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.