Jump to content
MakeWebGames

Community work on attack system :D (for coders only)


plintu

Recommended Posts

I am writing an attack system and I thought it might be cool to put it out here and see what the coders here thinks of it, it is about half way done, and if you got any ideas to add to it let me know ;)

<?php
include "globals.php";
$gets=mysql_real_escape_string($_GET['ID']);
$get=abs((int) $gets);
$mestr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$get");
$me=mysql_fetch_array($mestr);
$ustr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid");
$u=mysql_fetch_array($ustr);
$msecondary=$me['equip_secondary'];
$usecondary=$u['equip_secondary'];
$mprimary=$me['equip_primary'];
$uprimary=$u[equip_primary
$marmor=$me['armor'];
$uarmor=$u['armor'];
$magi=$me['agi'];
$uagi=$u['agi'];
$mehp=$me['hp'];
$uhp=$u['hp'];
$ugang=("SELECT COUNT('gang') FROM users WHERE userid=$get");
$megang=("SELECT COUNT('gang') FROM users WHERE userid=$userid");
$mpstr=$me['strength']*$mprimary*$megang/(floor($me['level'])/10);
$upstr=$u['strength']*$uprimary*ugang/(floor($me['level'])/10);
$msstr=$me['strength']*$msecondary*$megang/(floor($me['level'])/10);
$usstr=$u['strength']*$usecondary*$ugang/(floor($me['level'])/10);
$mdef=$me['def']*$megang*marmor/(floor($me['level'])/10);
$udef=$u['def']*$ugang*$uarmor/(floor($me['level'])/10);
$wait=$u['agi']-$me['agi'];
$mypdamage=$mpstr-$udef;
$urpdamage=$upstr-$mdef;
$mysdamage=$msstr-$udef;
$ursdamage=$usstr-$mdef;
$mylife=rand(1,(floor($mehp/2)));
$ulife=rand(1,(floor($uhp/2)));
$myslife=rand(1,(floor($mehp/4)));
$uslife=rand(1,(floor($uhp/4)));
$exp=floor($u['level']-$me['level']*10);
if($exp<1){$exp=20;}
$lexp=floor($u['level']-$me['level']*10*1.5);
if($exp<1){$exp=25;}
if($lexp<1){$lexp=25;}

//end variables//
if($me['userid']==$u['userid']){mysql_query("UPDATE users SET hp=0, hospital=20, hospreason='committed suicide' WHERE userid=$userid");}
die("<font size='4' color='red'>It wasn't very smart to try to kill yourself but you succeded!</font>");}
if($me['level']-$u['level']>20){die("Quit trying to be a bully![url='index.php']GO HOME![/url]");}
if($u['level']<10 && $me['level']>10){die("Come on give the little guy a chance!![url='index.php']GO HOME![/url]");}
if($me['gang'] > 0 && $me['gang'] == $u['gang']){
die("Hey jerk watch it I am in your gang[url='index.php']GO AWAY[/url]");}
if($u['userid']==1){die("You are no where near strong enough to beat God, try it again and you will be smacked down like never before!");}
if($me['energy']<$me['maxenergy']/10){die("You must have at least 10% of your energy to attack![url='index.php']GO HOME![/url]");}
if($mehp<10){die("You do not have enough Health to fight! [url='hospital.php']Go to hospital and heal[/url] or [url='index.php']Go Home[/url]");}
if($uhp<10 && $u['gender']==male){die("Why are you try to kick a man while he's down! You are ruthless!");}
if($uhp<10 && $u['gender']==female){die("Why are you try to kick a girl while she's down! You are ruthless!");}

//end ifs run attack//

print"You see {$u['username']} and decide they have lived long enough! it is time to get that ass!

for your level with your primary weapon you have an attack strength of $mpstr , with your secondary weapon you 

have an attack strength of $msstr , and for your level your defense is $mdef";
if($wait>0){
if($mypdamage>0){
mysql_query("UPDATE `users` SET `hp`=hp-$ulife WHERE userid=$get");
print"You caused $mypdamage damage, using your primary weapon, to {$u['username']}with that hit and taking <font color='green'>$ulife</font> away from their health!";
mysql_query("UPDATE `users` SET `hp`=hp-$mylife WHERE userid=$userid");
print"{$u['username']} took a shot at you and hit you with $urpdamage using their primary weapon you lost <font color='red'>$mylife</font> with that hit!";

if($myhp>10 && $uhp<10){
if($u['money']>10){$umoney=rand(1,$u['money']/4);}else{$umoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='Beat down by {$me['username']}',hp=0, money=money-$umoney WHERE userid=$get");
mysql_query("UPDATE `users` SET `exp`=exp+$exp, money=money+$umoney WHERE userid=$userid");
event_add($u['userid'],"{$me['username']}, just whooped you and put you in the hospital!", $c);
die("You destroyed {$u['username']} and sent them to the hospital! You gained $exp exp and stole $ $umoney!");
}
elseif($myhp<10 && $uhp>10){
if($u['money']>10){$mymoney=rand(1,$me['money']/4);}else{$mymoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20',`money`=`money`+$mymoney, `exp`=exp-$lexp, hospreason='Lost to {$u['username']}'in a fight!',hp=0, exp=exp-$lexp WHERE userid=$userid");
mysql_query("UPDATE `users` SET money=money+$mymoney, exp=exp+$lexp WHERE userid=$get");
event_add($get,"{$me['username']} tried to beat you up but sadly got whooped You took $ $mymoney and gained $lexp exp!", $c);
die("{$u['username']} destroyed you and you lost $lexp and $ $mymoney because you started the fight and sadly lost!
}elseif($myhp<10 && $uhp<10){
event_add($get,"{$me['username']} tried to beat you up, you both sustained fatal injuries in the battle!", $c);
event_add($userid,"You tried to beat up {$u['username']}, you both sustained fatal injuries in the battle!!", $c);
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$get");
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$userid");
}
if($myhp>10 && $uhp>10){
mysql_query("UPDATE `users` SET `hp`=hp-$ulife WHERE userid=$get");
print"You caused $mysdamage damage, using your secondary weapon, to {$u['username']}with that hit and taking <font color='green'>$uslife</font> away from their health!";
mysql_query("UPDATE `users` SET `hp`=hp-$mylife WHERE userid=$userid");
if($myhp>10 && $uhp<10){
if($u['money']>10){$umoney=rand(1,$u['money']/4);}else{$umoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='Beat down by {$me['username']}',hp=0, money=money-$umoney WHERE userid=$get");
mysql_query("UPDATE `users` SET `exp`=exp+$exp, money=money+$umoney WHERE userid=$userid");
event_add($u['userid'],"{$me['username']}, just whooped you and put you in the hospital!", $c);
die("You destroyed {$u['username']} and sent them to the hospital! You gained $exp exp and stole $ $umoney!");
}
elseif($myhp<10 && $uhp>10){
if($u['money']>10){$mymoney=rand(1,$me['money']/4);}else{$mymoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20',`money`=`money`+$mymoney, `exp`=exp-$lexp, hospreason='Lost to {$u['username']}'in a fight!',hp=0, exp=exp-$lexp WHERE userid=$userid");
mysql_query("UPDATE `users` SET money=money+$mymoney, exp=exp+$lexp WHERE userid=$get");
event_add($get,"{$me['username']} tried to beat you up but sadly got whooped You took $ $mymoney and gained $lexp exp!", $c);
die("{$u['username']} destroyed you and you lost $lexp and $ $mymoney because you started the fight and sadly lost!
}elseif($myhp<10 && $uhp<10){
event_add($get,"{$me['username']} tried to beat you up, you both sustained fatal injuries in the battle!", $c);
event_add($userid,"You tried to beat up {$u['username']}, you both sustained fatal injuries in the battle!!", $c);
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$get");
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$userid");
}
print"{$u['username']} took a shot at you and hit you with $ursdamage using their secondary weapon, you lost <font color='red'>$myslife</font> with that hit!";
}


}
}
Link to comment
Share on other sites

Re: Community work on attack system :D (for coders only)

 

Impress me.

Make a one click attack system that leaves you the option of leave, mug and hospitalize :P

that wouldn't be a problem, the funding would be :D anything can be made, but at least for a little $$ to help with time spent writing everything out!

Link to comment
Share on other sites

Re: Community work on attack system :D (for coders only)

 

<?php
include "globals.php";
$gets=mysql_real_escape_string($_GET['ID']);
$get=abs((int) $gets);
$mestr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$get");
$me=mysql_fetch_array($mestr);
$ustr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid");
$u=mysql_fetch_array($ustr);
$msecondary=$me['equip_secondary'];
$usecondary=$u['equip_secondary'];
$mprimary=$me['equip_primary'];
$uprimary=$u[equip_primary
$marmor=$me['armor'];
$uarmor=$u['armor'];
$magi=$me['agi'];
$uagi=$u['agi'];
$mehp=$me['hp'];
$uhp=$u['hp'];
$ugang=("SELECT COUNT('gang') FROM users WHERE userid=$get");
$megang=("SELECT COUNT('gang') FROM users WHERE userid=$userid");
$mpstr=$me['strength']*$mprimary*$megang/(floor($me['level'])/10);
$upstr=$u['strength']*$uprimary*ugang/(floor($me['level'])/10);
$msstr=$me['strength']*$msecondary*$megang/(floor($me['level'])/10);
$usstr=$u['strength']*$usecondary*$ugang/(floor($me['level'])/10);
$mdef=$me['def']*$megang*marmor/(floor($me['level'])/10);
$udef=$u['def']*$ugang*$uarmor/(floor($me['level'])/10);
$wait=$u['agi']-$me['agi'];
$mypdamage=$mpstr-$udef;
$urpdamage=$upstr-$mdef;
$mysdamage=$msstr-$udef;
$ursdamage=$usstr-$mdef;
$mylife=rand(1,(floor($mehp/2)));
$ulife=rand(1,(floor($uhp/2)));
$myslife=rand(1,(floor($mehp/4)));
$uslife=rand(1,(floor($uhp/4)));
$exp=floor($u['level']-$me['level']*10);
if($exp<1){$exp=20;}
$lexp=floor($u['level']-$me['level']*10*1.5);
if($exp<1){$exp=25;}
if($lexp<1){$lexp=25;}

//end variables//
if($me['userid']==$u['userid']){mysql_query("UPDATE users SET hp=0, hospital=20, hospreason='committed suicide' WHERE userid=$userid");}
die("<font size='4' color='red'>It wasn't very smart to try to kill yourself but you succeded!</font>");}
if($me['level']-$u['level']>20){die("Quit trying to be a bully![url='index.php']GO HOME![/url]");}
if($u['level']<10 && $me['level']>10){die("Come on give the little guy a chance!![url='index.php']GO HOME![/url]");}
if($me['gang'] > 0 && $me['gang'] == $u['gang']){
die("Hey jerk watch it I am in your gang[url='index.php']GO AWAY[/url]");}
if($u['userid']==1){die("You are no where near strong enough to beat God, try it again and you will be smacked down like never before!");}
if($me['energy']<$me['maxenergy']/10){die("You must have at least 10% of your energy to attack![url='index.php']GO HOME![/url]");}
if($mehp<10){die("You do not have enough Health to fight! [url='hospital.php']Go to hospital and heal[/url] or [url='index.php']Go Home[/url]");}
if($uhp<10 && $u['gender']==male){die("Why are you try to kick a man while he's down! You are ruthless!");}
if($uhp<10 && $u['gender']==female){die("Why are you try to kick a girl while she's down! You are ruthless!");}

//end ifs run attack//

print"You see {$u['username']} and decide they have lived long enough! it is time to get that ass!

for your level with your primary weapon you have an attack strength of $mpstr , with your secondary weapon you 

have an attack strength of $msstr , and for your level your defense is $mdef";
if($wait>0){
if($mypdamage>0){
mysql_query("UPDATE `users` SET `hp`=hp-$ulife WHERE userid=$get");
print"You caused $mypdamage damage, using your primary weapon, to {$u['username']}with that hit and taking <font color='green'>$ulife</font> away from their health!";
mysql_query("UPDATE `users` SET `hp`=hp-$mylife WHERE userid=$userid");
print"{$u['username']} took a shot at you and hit you with $urpdamage using their primary weapon you lost <font color='red'>$mylife</font> with that hit!";

if($myhp>10 && $uhp<10){
if($u['money']>10){$umoney=rand(1,$u['money']/4);}else{$umoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='Beat down by {$me['username']}',hp=0, money=money-$umoney WHERE userid=$get");
mysql_query("UPDATE `users` SET `exp`=exp+$exp, money=money+$umoney WHERE userid=$userid");
event_add($u['userid'],"{$me['username']}, just whooped you and put you in the hospital!", $c);
die("You destroyed {$u['username']} and sent them to the hospital! You gained $exp exp and stole $ $umoney!");
}
elseif($myhp<10 && $uhp>10){
if($u['money']>10){$mymoney=rand(1,$me['money']/4);}else{$mymoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20',`money`=`money`+$mymoney, `exp`=exp-$lexp, hospreason='Lost to {$u['username']}'in a fight!',hp=0, exp=exp-$lexp WHERE userid=$userid");
mysql_query("UPDATE `users` SET money=money+$mymoney, exp=exp+$lexp WHERE userid=$get");
event_add($get,"{$me['username']} tried to beat you up but sadly got whooped You took $ $mymoney and gained $lexp exp!", $c);
die("{$u['username']} destroyed you and you lost $lexp and $ $mymoney because you started the fight and sadly lost!
}elseif($myhp<10 && $uhp<10){
event_add($get,"{$me['username']} tried to beat you up, you both sustained fatal injuries in the battle!", $c);
event_add($userid,"You tried to beat up {$u['username']}, you both sustained fatal injuries in the battle!!", $c);
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$get");
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$userid");
}
if($myhp>10 && $uhp>10){
mysql_query("UPDATE `users` SET `hp`=hp-$ulife WHERE userid=$get");
print"You caused $mysdamage damage, using your secondary weapon, to {$u['username']}with that hit and taking <font color='green'>$uslife</font> away from their health!";
mysql_query("UPDATE `users` SET `hp`=hp-$mylife WHERE userid=$userid");
if($myhp>10 && $uhp<10){
if($u['money']>10){$umoney=rand(1,$u['money']/4);}else{$umoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='Beat down by {$me['username']}',hp=0, money=money-$umoney WHERE userid=$get");
mysql_query("UPDATE `users` SET `exp`=exp+$exp, money=money+$umoney WHERE userid=$userid");
event_add($u['userid'],"{$me['username']}, just whooped you and put you in the hospital!", $c);
die("You destroyed {$u['username']} and sent them to the hospital! You gained $exp exp and stole $ $umoney!");
}
elseif($myhp<10 && $uhp>10){
if($u['money']>10){$mymoney=rand(1,$me['money']/4);}else{$mymoney=0;}
mysql_query("UPDATE `users` SET `hospital`='20',`money`=`money`+$mymoney, `exp`=exp-$lexp, hospreason='Lost to {$u['username']}'in a fight!',hp=0, exp=exp-$lexp WHERE userid=$userid");
mysql_query("UPDATE `users` SET money=money+$mymoney, exp=exp+$lexp WHERE userid=$get");
event_add($get,"{$me['username']} tried to beat you up but sadly got whooped You took $ $mymoney and gained $lexp exp!", $c);
die("{$u['username']} destroyed you and you lost $lexp and $ $mymoney because you started the fight and sadly lost!
}elseif($myhp<10 && $uhp<10){
event_add($get,"{$me['username']} tried to beat you up, you both sustained fatal injuries in the battle!", $c);
event_add($userid,"You tried to beat up {$u['username']}, you both sustained fatal injuries in the battle!!", $c);
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$get");
mysql_query("UPDATE `users` SET `hospital`='20', hospreason='{$me['username']} and {$u['username']} died while {$me['username']} started the fight',hp=0 WHERE userid=$userid");
}
echo sprintf("%s took a shot at you and hit you with %s using their secondary weapon, you lost <font color='red'>%s</font> with that hit!", htmlentities($u['username']), number_format($ursdamage), number_format($myslife));
}


}
}

dont really have time to do a lot so i just sorted the end out slightly should be a helping hand and maybe someone else will do a bit :)

Link to comment
Share on other sites

Re: Community work on attack system :D (for coders only)

1# No need to mysql_real_escape_string(), $_GET['ID']. Could just do.

$_GET['ID'] = isset($_GET['ID']) && preg_match("/^\d+$/ims", $_GET['ID']) ? intval($_GET['ID']) : 0;
$checkUser = $db->query('SELECT userid FROM users WHERE userid = '. $_GET['ID']);
if(!$_GET['ID'] || $db->num_rows($checkUser) < 1)
{
  echo 'This user don\'t exist.';
  die(headers::endpage());
}

2#

$ustr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid");
$u=mysql_fetch_array($ustr);

That is point less, its already being called from globals.

3#

$mestr=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$get");
$me=mysql_fetch_array($mestr);

All of the coloums from users/userstats don't all need to be called.

4# There is loads of error's in the script.

5# Why use so many variables. EG

$marmor=$me['armor'];
$uarmor=$u['armor'];
$magi=$me['agi'];
$uagi=$u['agi'];
$mehp=$me['hp'];

Point less and slowing the code down.

Hope it helps you. lol

Link to comment
Share on other sites

Re: Community work on attack system :D (for coders only)

actally that did help I don't know why I wasn't using the $ir variable, and I noticed I forgot to actually query for the weapons strength, I knew there was errors in this and that it wasn't complete that is kind of what the topic was about, I wanted to see if some coders would do some adds to it and see how creative of an attack script we could come up with! as for the get variable do you really think

$_GET['ID'] = isset($_GET['ID']) && preg_match("/^\d+$/ims", $_GET['ID']) ? intval($_GET['ID']) : 0;
$checkUser = $db->query('SELECT userid FROM users WHERE userid = '. $_GET['ID']);
if(!$_GET['ID'] || $db->num_rows($checkUser) < 1)
{
  echo 'This user don\'t exist.';
  die(headers::endpage());
}

is better than

$gets=mysql_real_escape_string($_GET['ID']);
$get=abs((int) $gets);

and why? I am not trying to be a jerk I am just wondering, I am still learning php and trying to learn the why's of everything!

Link to comment
Share on other sites

Re: Community work on attack system :D (for coders only)

1# Check if its set.. isset(), check if its all numbers.. preg_match()/ctype_*/is_numeric/ ect

2# if anythink is not set if (!$_GET['ID'], || $db->num_rows($sql) < 1,,,, Does the user exist?

3# You script dont check all that..

Witch is what i see on loads of mods, they dont check what is what, if it exists or what..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...