Jump to content
MakeWebGames

I know its huge, but it is over my head now.


MobTown

Recommended Posts

I have owned a game since mid April, and since then coded many things myself. Trying to stray away from mods, so that my site is unique. Unfortunately my attack feature has been driving me and my players mad.

For some reason the attack is totally random you can attack someone and win, then ten minutes later attack and lose.

As mentioned in thread title, I know this is a huge script, but would really appreciate someone helping me to find my failings, and point out any other issues with the code.

 

<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm,0);
$_GET['ID'] == (int) $_GET['ID'];

die("Sincerist of apologies, but this thing is downright evil...

[url='index.php']Return to Index[/url]");

if($ir['jail'] > 0)
{
die("[b]<font color=red>Criminals are not allowed here. You are in Jail for {$ir['jail']} more minute(s).

Until you are out you can't view this page</font>[/b]


[url='jail.php']Return to Jail[/url]");
}
if($ir['hospital'] > 0)
{
die("[b]<font color=red>While in hospital you are not allowed here. You are in the Hospital for {$ir['hospital']} more minute(s).

Until you are out you can't view this page</font>[/b]


[url='hospital.php']Return to Hospital[/url]");
}
$_GET['ID'] == (int) $_GET['ID'];
if($ir['jail'] > 0)
{
die("[b]<font color=red>Criminals are not allowed here. You are in Jail for {$ir['jail']} more minute(s).

Until you are out you can't view this page</font>[/b]


[url='jail.php']Return to Jail[/url]");
}
if($ir['hospital'] > 0)
{
die("[b]<font color=red>While in hospital you are not allowed here. You are in the Hospital for {$ir['hospital']} more minute(s).

Until you are out you can't view this page</font>[/b]


[url='hospital.php']Return to Hospital[/url]");
}
if(!$_GET['ID'])
{
print "<font color='red'>WTF you doing, bro?</font>[/b]";
$h->endpage();
exit;
}
else if($_GET['ID'] == $userid)
{
print "<font color='red'>[b]Only the crazy attack themselves.</font>[/b]";
$h->endpage();
exit;
}
//get player data
$youdata=$ir;
$q=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}",$c);
$odata=mysql_fetch_array($q);
if ($odata['user_level']==2)
{
die("<center>You cannot attack admin, we have work to do.

<a href=index.php>Back</a></center>");
}
if($odata['hp'] == 1)
{
print "[b]<font color='red'>This player is unconscious.</font>[/b]

[url='index.php']> Back[/url]";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($odata['hospital'] and $ir['hospital']==0)
{
print "<font color='red'>[b]This player is in hospital.[/b]<font>

[url='index.php']> Back[/url]";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($odata['jail'] and $ir['jail']==0)
{
print "<font color='red'>[b]This player is in jail.[/b]<font>

[url='index.php']> Back[/url]";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if($ir['hospital'])
{
print "[b]<font color='red'>You can not attack while in hospital.</font>[/b]

[url='hospital.php']> Back[/url]";
$h->endpage();
$_SESSION['attacking']=0;
exit;
}
else if ($odata['casino']==1)
{
die ("<center>You walk to the casino where your victim is, you get to the door and the security guard checks you.
He knows you are here to cause trouble and turns you away
Click <a href=viewuser.php?u={$_GET['ID']}>here</a> to go back to there profile.");
}
print "<table width=100%><tr><td colspan=2 align=center>";
if($_GET['wepid'])
{

if($_SESSION['attacking']==0)
{
if ($youdata['energy'] >= $youdata['maxenergy']/4)
{

$youdata['energy']-= $youdata['maxenergy']/2;
$me=$youdata['maxenergy']/4;
mysql_query("UPDATE users SET energy=energy- {$me} WHERE userid=$userid",$c);
$_SESSION['attacklog']="";
}
else
{
print "<font color='red'>[b]You can only attack someone when you have 25% energy</font>[/b]";
$h->endpage();
exit;
}
}
$_SESSION['attacking']=1;
$_GET['wepid'] = (int) $_GET['wepid'];
$_GET['nextstep'] = (int) $_GET['nextstep'];
$qr=mysql_query("SELECT * FROM equipped WHERE eq_itemid={$_GET['wepid']} and eq_userid=$userid",$c);
if(mysql_num_rows($qr)==0)
{
print "<font color='red'>Stop trying to abuse a game bug. You could get hospitalized for that.</font>[/b]

[url='index.php']> Home[/url]";
mysql_query("UPDATE users SET hospital=10 hospreason='Trying to cheat' where userid=$userid",$c);
die("");
}
$qo=mysql_query("SELECT i.*,w.* FROM items i LEFT JOIN weapons w ON i.itmid=w.item_id WHERE w.item_id={$_GET['wepid']}",$c);
$r1=mysql_fetch_array($qo);
$mydamage=(int) (($r1['damage']*$youdata['strength']/$odata['guard'])*(rand(8000,12000)/10000));
$hitratio=min(50*$ir['agility']/$odata['agility'],95);
if($userid==1) { $hitratio=100; }
$ohit=0;
$yhit=0;
print "$wep";
$oogly=0;


While ($youdata['hp']>0 OR $odata['hp']>0 OR $oogly<50)
{
$oogly+=1;
if ($wep=="")
{
$wep="mind but failed every time";
}
if(rand(1,100) <= $hitratio)
{
//choose opp gun
$eq=mysql_query("SELECT iv.*,i.*,w.* FROM equipped iv LEFT JOIN items i ON iv.eq_itemid=i.itmid LEFT JOIN weapons w ON iv.eq_itemid=w.item_id WHERE iv.eq_userid={$_GET['ID']} AND ( i.itmtype=3 OR i.itmtype=4 )",$c);
if(mysql_num_rows($eq) == 0)
{
$wep="Fists";
$dam=(int)((((int) ($odata['strength']/100)) +1)*(rand(8000,12000)/10000));
}
else if(mysql_num_rows($eq) == 1)
{
$r=mysql_fetch_array($eq);

$wep=$r['itmname'];
$dam=(int) (($r['damage']*$odata['strength']/$youdata['guard'])*(rand(8000,12000)/10000));
}
else
{
$cnt=0;
while($r=mysql_fetch_array($eq))
{
$enweps[]=$r;
$cnt++;
}
$weptouse=rand(0,$cnt-1);
$wep=$enweps[$weptouse]['itmname'];
$dam=(int) (($enweps[$weptouse]['damage']*$odata['strength']/$youdata['guard'])*(rand(8000,12000)/10000));
}
$q3=mysql_query("SELECT a.Defence FROM equipped iv LEFT JOIN items i ON iv.eq_itemid = i.itmid LEFT JOIN armour a ON i.itmid=a.item_ID WHERE i.itmtype=7 AND iv.eq_userid={$_GET['ID']}",$c);
if(mysql_num_rows($q3))
{
$mydamage-=mysql_result($q3,0,0);
}
$shifoo1+=$mydamage;
if($mydamage < 1) { $mydamage=1; }
$odata['hp']-=$mydamage;
if($odata['hp']==1) { $odata['hp']=0;$mydamage+=1; }
mysql_query("UPDATE users SET hp=hp-$mydamage WHERE userid={$_GET['ID']}",$c);
$ohit+=1;
$_SESSION['attacklog'].="<font color=red>{$_GET['nextstep']}. Using his {$r1['itmname']} {$ir['username']} hit {$odata['username']} doing $mydamage damage ({$odata['hp']})</font>
\n";
}
else
{
$_SESSION['attacklog'].="<font color=red>{$_GET['nextstep']}. {$ir['username']} tried to hit {$odata['username']} but missed ({$odata['hp']})</font>
\n";
}
if ($wep=="")
{
$wep="mind but failed every time";
}
if($odata['hp'] <= 0 || $oogly==50)
{
if ($shifoo1< $shifoo2)
{
$youdata['hp']=0;
mysql_query("UPDATE users SET hp=0 WHERE userid=$userid",$c);
die ("<font color=green><center>You hit {$odata['username']} $ohit times with your {$r1['itmname']}</center></font>
<font color=red><center>{$odata['username']} hit you $yhit times with their $wep</center></font>

<form action='attacklost.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Continue' />");
}
else
{
$odata['hp']=0;
$_SESSION['attackwon']=$_GET['ID'];
mysql_query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}",$c);
die ("<font color=green><center>You hit {$odata['username']} $ohit times with your {$r1['itmname']}</center></font>
<font color=red><center>{$odata['username']} hit you $yhit times with their $wep </center></font>


<table class=sample><tr><td align=center>Use this option to keep victim in hospital for half hour.</td></tr><tr><td>
<form action='attackleave.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Leave Them' style='width:100%'/>
</form>
</td></tr>
<tr><td align=center>Use this option to to steal a small amount of the victims money.</td></tr><tr><td>
<form action='attackmug.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Mug Them' style='width:100%'>
</form>
</td></tr>
<tr><td align=center>Use this option to gain EXP points from a hit.
It is also the only option that the hitman bounty supports.</td></tr><tr><td>
<form action='attackhosp.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Hospitalize Them' style='width:100%'>
</form></td></tr></table>");
}
}
else 
{
$hitratio=min(50*$odata['agility']/$ir['agility'],95);
if($odata['userid']==1) { $hitratio=100; }
if(rand(1,100) <= $hitratio)
{
$q3=mysql_query("SELECT a.Defence FROM equipped iv LEFT JOIN items i ON iv.eq_itemid = i.itmid LEFT JOIN armour a ON i.itmid=a.item_ID WHERE i.itmtype=7 AND iv.eq_userid=$userid",$c);
if(mysql_num_rows($q3))
{
$dam-=mysql_result($q3,0,0);
}
$shifoo2+=$dam;
if($dam < 1) { $dam=1; }
$youdata['hp']-=$dam;
mysql_query("UPDATE users SET hp=hp-$dam WHERE userid=$userid",$c);
$ns=$_GET['nextstep']+1;
$yhit+=1;
$_SESSION['attacklog'].="<font color=blue>{$ns}. Using his $wep {$odata['username']} hit {$ir['username']} doing $dam damage ({$youdata['hp']})</font>
\n";
}
else
{
$ns=$_GET['nextstep']+1;
$_SESSION['attacklog'].="<font color=blue>{$ns}. {$odata['username']} tried to hit {$ir['username']} but missed ({$youdata['hp']})</font>
\n";
}
if ($wep=="")
{
$wep="mind but failed every time";
}
if($youdata['hp'] <= 0 || $oogly==50)
{
if ($shifoo1< $shifoo2)
{
$youdata['hp']=0;
mysql_query("UPDATE users SET hp=0 WHERE userid=$userid",$c);
die ("<font color=green><center>You hit {$odata['username']} $ohit times with your {$r1['itmname']}</center></font>
<font color=red><center>{$odata['username']} hit you $yhit times with their $wep</center></font>

<form action='attacklost.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Continue' />");
}
else
{
$odata['hp']=0;
$_SESSION['attackwon']=$_GET['ID'];
mysql_query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}",$c);
die ("<font color=green><center>You hit {$odata['username']} $ohit times with your {$r1['itmname']}</center></font>
<font color=red><center>{$odata['username']} hit you $yhit times with their $wep </center></font>


<table class=sample><tr><td align=center>Use this option to keep victim in hospital for half hour.</td></tr><tr><td>
<form action='attackleave.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Leave Them' style='width:100%'/>
</form>
</td></tr>
<tr><td align=center>Use this option to to steal a small amount of the victims money.</td></tr><tr><td>
<form action='attackmug.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Mug Them' style='width:100%'>
</form>
</td></tr>
<tr><td align=center>Use this option to gain EXP points from a hit.
It is also the only option that the hitman bounty supports.</td></tr><tr><td>
<form action='attackhosp.php?ID={$_GET['ID']}&hitmen={$_GET['hitmen']}' method='post'>
<input type='submit' value='Hospitalize Them' style='width:100%'>
</form></td></tr></table>");
}
}
}
}


}
else if ($odata['hp'] < $odata['maxhp']/2)
{
print "You can only attack those who have at least 1/2 their max health";
$h->endpage();
exit;
}
else if ($ir['gang'] == $odata['gang'] && $ir['gang'] > 0)
{
print "{$odata['username']} is in your gang. Behavior like that will see you killed.";
$h->endpage();
exit;
}
else if ($youdata['energy'] < $youdata['maxenergy']/4)
{
print "You can only attack someone when you have 25% energy";
$h->endpage();
exit;
}
else if ($youdata['location'] != $odata['location'])
{
print "You can only attack someone in the same location!";
$h->endpage();
exit;
}
else
{
}
print "</td></tr>";
if($youdata['hp'] <= 0 || $odata['hp'] <= 0 || $oogly==50)
{
print "</table>";
}
else
{
print "<tr><td align=center>Your Health: {$youdata['hp']}/{$youdata['maxhp']}       Opponents Health: {$odata['hp']}/{$odata['maxhp']}</td></tr>";
$mw=mysql_query("SELECT iv.*,i.* FROM equipped iv LEFT JOIN items i ON iv.eq_itemid=i.itmid WHERE iv.eq_userid=$userid AND (iv.eq_itemtype = 3 || iv.eq_itemtype = 4)",$c);
print "<tr><td colspan=2 align='center'>Attack with:
";
while($r=mysql_fetch_array($mw))
{
if(!$_GET['nextstep']) { $ns=1; } else { $ns=$_GET['nextstep']+2; }
print "[url='attack.php?nextstep=$ns&ID={$_GET[']{$r['itmname']}[/url]
";
}
print "</table>";
}
$h->endpage();
?>

 

P.S As you can prob see from the variable names i was watching Kung Fu Panda while trying to fix this.

Link to comment
Share on other sites

Re: I know its huge, but it is over my head now.

i am confused what you mean, sorry to sound so thick.

do you mean make that line

 

$dam=(int)((((int) ($odata['strength']/100)) +1)*(rand(8000,12000)/10000));

 

look like the one that can be seen about 5 lines down from it?

 

$dam=(int) (($r['damage']*$odata['strength']/$youdata['guard'])*(rand(8000,12000)/10000));
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...