Re: [mccode v2] Attack :)
Well gotta say I love this site. I have read and changed more php in the past few days then ever before. This site is very useful for learning.
That being said I here is my first post on this site.
I noticed when using this mod that when you attack someone you do not loose health. It always stood at 100% on my game. Now I'm not very good at php but I did get it to work for me.
This is how I did it. Any advice and changes would be appreciative.
Find:
if($theirhp <= 0){ // attacker won
$winner = $user_class['ID'];
$theirhp = 0;
$moneywon = floor($attack_person['money'] /10);
$expwon = 150 - (25 * ($user_class['level'] - $attack_person['level']));
$expwon = ($expwon < 0) ? 0 : $expwon;
$hosptime=20;
$hospreason = "Attacked by ".$user_class['username']."" ;
$newexp = $expwon + $user_class['exp'];
$newmoney = $user_class['money'] + $moneywon;
$result = $db->query("UPDATE `users` SET `exp` = '".$newexp."', money = '".$newmoney."' WHERE `userid`='".$user_class['userid']."'");
$newmoney = $attack_person['money'] - $moneywon;
$result = $db->query("UPDATE `users` SET `hp`= 1,`hospital` ='".$hosptime."', `money` = '".$newmoney."', `hospreason` = '".$hospreason."' WHERE `userid`='".$attack_person['userid']."'");
$atklog=mysql_escape_string($_SESSION['attacklog']);
$db->query("INSERT INTO attacklogs VALUES('',".$user_class['userid'].",".$attack_person['userid'].",'won',unix_timestamp(),".$moneywon.",'$atklog');");
event_add($attack_person['userid'], "You were hospitalized by ".$user_class['username']." for 20 minutes.");
$final ="<center>You hospitalized " .$attack_person['username']. ".
You gain $expwon exp and stole $".$moneywon." from " .$attack_person['username']. ".
</center>";
$pwnd ="";
Replace with:
if($theirhp <= 0){ // attacker won
$winner = $user_class['ID'];
$theirhp = 0;
$yourhp = $yourhp - $damage;
$moneywon = floor($attack_person['money'] /10);
$expwon = 150 - (25 * ($user_class['level'] - $attack_person['level']));
$expwon = ($expwon < 0) ? 0 : $expwon;
$hosptime=20;
$hospreason = "Attacked by ".$user_class['username']."" ;
$newexp = $expwon + $user_class['exp'];
$newmoney = $user_class['money'] + $moneywon;
$result = $db->query("UPDATE `users` SET `exp` = '".$newexp."', `hp` = '".$yourhp."', money = '".$newmoney."' WHERE `userid`='".$user_class['userid']."'");
$newmoney = $attack_person['money'] - $moneywon;
$result = $db->query("UPDATE `users` SET `hp`= 1,`hospital` ='".$hosptime."', `money` = '".$newmoney."', `hospreason` = '".$hospreason."' WHERE `userid`='".$attack_person['userid']."'");
$atklog=mysql_escape_string($_SESSION['attacklog']);
$db->query("INSERT INTO attacklogs VALUES('',".$user_class['userid'].",".$attack_person['userid'].",'won',unix_timestamp(),".$moneywon.",'$atklog');");
event_add($attack_person['userid'], "You were hospitalized by ".$user_class['username']." for 20 minutes.");
$final ="<center>You hospitalized " .$attack_person['username']. ".
You gain $expwon exp and stole $".$moneywon." from " .$attack_person['username']. ".
</center>";
$pwnd ="";
It seems to work in my game. I have tried attacking 25 times and I did not notice an error. Health seems to drop as well.
Hope it was useful to anyone.