2Pacalypse Posted April 14, 2009 Posted April 14, 2009 Ok, I'm more ore less a useless coder, but I thought this would be a simple enough task, all I wanted to do was change the damage made by players. What I intended to do was bring up the weapon power & armor.. power.. or both players and make an equation for the damage done by each of them However this turned out to be quite nasty! I got the weapon & armor 'power' and divided the strength/defense by 100 and multiply it by weapon/armor power! Then added the original strength/guard. Anyway... can someone please help out with this. I've doen what I can but totally lost now :( <?php $menuhide=1; $atkpage=1; include "globals.php"; $_GET['ID'] == (int) $_GET['ID']; //get opponent data $o=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$_GET['ID']}"); $oppattack=$db->fetch_row($o); $oppabbr=($q['gender']=="Male") ? "his" : "her"; //get my data $m=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid={$userid}"); $myattack=$db->fetch_row($m); $myabbr=($m['gender']=="Male") ? "his" : "her"; //check if someone else is attacking that person $check=$db->query("SELECT * FROM users WHERE attacking={$_GET['ID']} AND userid!=$userid"); $checkit=mysql_num_rows($check); if ($checkit>0) { $att=$db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); print "Someone is already attacking that person. Try again later. [url='index.php']Back[/url]"; $h->endpage(); exit; } //additional checks if(!$_GET['ID']){ print "Excuse me. Looking for something? [url='index.php']Back[/url]"; $h->endpage(); exit; }else if($_GET['ID'] == $userid){ print "Only the crazy attack themselves. [url='index.php']Back[/url]"; $h->endpage(); exit; }else if ($myattack['hospital'] > 0){ print "You can't fight when you're in hospital. [url='index.php']Back[/url]"; $h->endpage(); exit; }else if ($oppattack['daysold'] < 2){ print "This Person Is Less Than 2 Days Old, Give 'Em A Chance [url='index.php']Back[/url]"; $h->endpage(); exit; }else if ($_SESSION['attacklost'] == 1){ print "Only the losers attack when they've already lost. [url='index.php']Back[/url]"; $_SESSION['attacklost']=0; $h->endpage(); exit; }else if ($myattack['location'] != $oppattack['location']){ print "You can only attack someone in the same location! [url='index.php']Back[/url]"; $h->endpage(); exit; } if($oppattack['hp'] <= 1){ print "This player is unconscious. [url='index.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($oppattack['hospital']){ print "This player is in hospital. [url='index.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($myattack['hospital']){ print "While in hospital you can't attack. [url='hospital.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($oppattack['jail']){ print "This player is in jail. [url='index.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($myattack['jail']){ print "While in jail you can't attack. [url='jail.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($oppattack['travelling']){ print "That player is travelling. [url='index.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; }else if($oppattack['fedjail']){ print "That player is in Federal Jail. [url='index.php']> Back[/url]"; $h->endpage(); $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); exit; } $mw=$db->query("SELECT i.* FROM items i WHERE i.itmid IN({$myattack['equip_primary']}, {$myattack['equip_secondary']})"); if($db->num_rows($mw) > 0){ while($r=$db->fetch_row($mw)){ if($r['itmid']==$myattack['equip_primary']) { print "[b]Are you sure you want to attack this person?[/b] "; } print " [url='?ID={$_GET[']Yes![/url] "; } }else{ print "You have no weapon to fight with. [url='index.php']Back[/url]"; } if($_GET['wepid']){ //checks user for enough energy if($_SESSION['attacking']==0 && $myattack['attacking'] == 0){ if ($myattack['energy'] >= $myattack['maxenergy']/4){ $myattack['energy']-= floor($myattack['maxenergy']/4); $me=floor($myattack['maxenergy']/4); $db->query("UPDATE users SET energy=energy- {$me} WHERE userid=$userid"); $_SESSION['attacklog']=""; $_SESSION['attackdmg']=0; }else{ print "You can only attack someone when you have 25% energy [url='index.php']Back[/url]"; $h->endpage(); exit; } } //Ensures the weapon chosen is owned by the player if($_GET['wepid'] != $myattack['equip_primary'] && $_GET['wepid'] != $myattack['equip_secondary']){ print "Not your weapon... You lost all exp for that [url='index.php']> Home[/url]"; $db->query("UPDATE users SET exp=0 where userid=$userid",$c); die(""); } print " Attack Log. "; $i=1; for($i=1;$i<100;$i++) { $vars['hpperc']=round($myattack['hp']/$myattack['maxhp']*100); $vars['hpopp']=100-$vars['hpperc']; $vars2['hpperc']=round($oppattack['hp']/$oppattack['maxhp']*100); $vars2['hpopp']=100-$vars2['hpperc']; if($oppattack['hp'] <= 0) { $oppattack['hp']=0; $_SESSION['attackwon']=$_GET['ID']; $db->query("UPDATE users SET hp=0 WHERE userid={$_GET['ID']}",$c); print " Your opponent is unconscious. [b]What do you want to do with {$oppattack['username']} now?[/b] <form action='attackwon.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Mug Them' /></form> <form action='attackbeat.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Hospitalize Them' /></form> <form action='attacktake.php?ID={$_GET['ID']}' method='post'><input type='submit' value='Leave Them' /></form>"; print " "; exit; }else{ //make it random $skit= mt_rand(int 80000, int 120000); //Select My Weapon/Armor details $qo=$db->query("SELECT i.* FROM items i WHERE i.itmid={$_GET['wepid']}"); $r1=$db->fetch_row($qo); $w1p=$db>query("SELECT weapon FROM items WHERE itmid={$myattack['equip_primary']}"); $qo2=$db->query("SELECT i.* FROM items i WHERE i.itmid={$myattack['equip_armor']}"); $r2=$db->fetch_row($qo2); //attackers armor $a1p=$db->query("SELECT armor FROM items WHERE itmid={$myattack['equip_armor']}"); //attacks overall guard $atkgrd=((($myattack['guard'])/100)*($a1p) +($myattack['guard']); //Select Their Weapon/Armor details $q3=$db->query("SELECT i.armor FROM items i WHERE itmid={$oppattack['equip_armor']}"); $oarmor=$db->fetch_single($q3); //opponents final guard $opgrd=((($oarmor)/100)*($oppattack['guard'])); $q4=$db->query("SELECT i.* FROM items i WHERE i.itmid IN({$oppattack['equip_primary']}, {$oppattack['equip_secondary']})"); if(mysql_num_rows($q4) == 0){ $wep="Fists"; $defratio=0.000000000001; }else{ $cnt=0; while($r=$db->fetch_row($q4)) { $enweps[]=$r; $cnt++; } $weptouse=rand(0,$cnt-1); $wep=$enweps[$weptouse]['itmname']; if(mysql_num_rows($qo2) == 0){ $defratio=($enweps[$weptouse]['weapon']*($oppattack['strength']+$oppattack['agility']))/($myattack['guard']+$myattack['agility']); }else{ $defratio=($enweps[$weptouse]['weapon']*($oppattack['strength']+$oppattack['agility']))/($r2['armor']*($myattack['guard']+$myattack['agility'])); } } //calculate attack if($oarmor == 0){ $attratio=(((($r1['weapon'])/100)*($myattack['strength']))-($oppattack['guard'])+($myattack['strength']); }else{ $attratio=(((($r1['weapon'])/100)*($myattack['strength']))-(($oarmor)/100)*($oppattack['guard'])+($myattack['strength'])); } if ($attratio > 1) { if ($attratio > 1000000) { $attdamage = 1000000; }else{ $attdamage=$attratio*($attratio*500); $attdamage=rand(($attdamage/4),$attdamage); } $db->query("UPDATE users SET hp=hp-$attdamage WHERE userid={$_GET['ID']}",$c); $oppattack['hp']-=$attdamage; $ns=$i; //print attack results print" {$i}. Using your {$r1['itmname']} you hit {$oppattack['username']} doing $attdamage damage \n"; $_SESSION['attackdmg']+=$attdamage; $_SESSION['attacklog'].="{$i}. Using {$myabbr} {$r1['itmname']} {$myattack['username']} hit {$oppattack['username']} doing $attdamage damage \n"; }else{ $attdamage = 0; $ns=$i; print " {$ns}. You tried to hit {$oppattack['username']} you but missed \n"; $_SESSION['attacklog'].="{$ns}. You tried to hit {$oppattack['username']} but missed \n"; } //calculate defense if ($defratio > 1) { if ($defratio > 1000000) { $defdamage = 1000000; }else{ $defdamage=$defratio*($defratio*500); $oppdamage=rand(($defdamage/2),$defdamage); } $db->query("UPDATE users SET hp=hp-$oppdamage WHERE userid=$userid",$c); $myattack['hp']-=$oppdamage; $ns=$i+1; print " {$ns}. Using $oppabbr $wep {$oppattack['username']} hit you doing $oppdamage damage \n"; $_SESSION['attacklog'].="{$ns}. Using $oppabbr $wep {$oppattack['username']} hit {$myattack['username']} doing $oppdamage damage ({$oppattack['hp']}) \n"; }else{ $oppdamage = 0; $ns=$i+1; print " {$ns}. {$oppattack['username']} tried to hit you but missed \n"; $_SESSION['attacklog'].="{$ns}. {$oppattack['username']} tried to hit {$myattack['username']} but missed \n"; } if($myattack['hp'] <= 0) { $od=$db->query("SELECT * FROM users WHERE userid={$_GET['ID']}"); if($db->num_rows($od)) { $r=$db->fetch_row($od); print "You lost to {$r['username']}"; $expgain=abs(($ir['level']-$r['level'])^3); $expgainp=$expgain/$ir['exp_needed']*100; $hosptime=20; print " and lost $expgainp% EXP!"; $db->query("UPDATE users SET hp=1,exp=exp-$expgain, attacking=0, hospital=$hosptime,hospreason='Lost to <a href=\'viewuser.php?u={$r['userid']}\'>{$r['username']}</a>' WHERE userid=$userid"); $db->query("UPDATE users SET exp=0 WHERE exp<0"); event_add($r['userid'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] attacked you and lost.",$c); $atklog=mysql_escape_string($_SESSION['attacklog']); $db->query("INSERT INTO attacklogs VALUES('',$userid,{$_GET['ID']},'lost',unix_timestamp(),0,'$atklog');"); $warq=$db->query("SELECT * FROM gangwars WHERE (warDECLARER={$ir['gang']} AND warDECLARED={$r['gang']}) OR (warDECLARED={$ir['gang']} AND warDECLARER={$r['gang']})"); if ($db->num_rows($warq) > 0) { $war=$db->fetch_row($warq); $db->query("UPDATE gangs SET gangRESPECT=gangRESPECT+1 WHERE gangID={$r['gang']}"); $db->query("UPDATE gangs SET gangRESPECT=gangRESPECT-1 WHERE gangID={$ir['gang']}"); print " You lost 1 respect for your gang!"; } }else{ print "You lost to Mr. Non-existant! =O"; } print " <a href='index.php>Go Back.</a></br>'"; exit; } print ' '; } $i=$i+1; if($i >= 99) { print"<center><h1><font color='red'>STALEMATE!</h1> <h2>This fight is going nowhere you may as well go home!</h2> [url='index.php']> Back[/url]</center>"; $_SESSION['attacking']=0; $myattack['attacking']=0; $db->query("UPDATE users SET attacking=0 WHERE userid=$userid"); $h->endpage(); event_add($odata['userid'],"[url='viewuser.php?u=$userid']{$myattack['username']}[/url] Tried to beat you but stalemated.",$c); event_add($myattack['userid']," You Tried to beat [url='viewuser.php?u={$odata[']{$odata['username']}[/url] but stalemated.",$c); exit; } } } $h->endpage(); ?> Quote
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.