Jump to content
MakeWebGames

Recommended Posts

Posted

Hi basically with the attack system i use it takes 50% of your energy when attacking a player but i want it so that for donators it takes a value of 6 energy instead of a percentage. I need it added somewhere in here whne the player picks their next weapon to attack with if anyone could help that would be great thanks.

 

if($_GET['wepid'])
{
if($_SESSION['attacking']==0 && $ir['attacking'] == 0)
{
if ($youdata['energy'] >= $youdata['maxenergy']/2)
{

$youdata['energy']-= floor($youdata['maxenergy']/2);
$me=floor($youdata['maxenergy']/2);
$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 50% energy";
$h->endpage();
exit;
Posted

So you want 50% for non-donators and a "value" of 6 for donators?

 

if($_GET['wepid'])
{
 if($_SESSION['attacking']==0 && $ir['attacking'] == 0)
 {
$energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6';
if ($youdata['energy'] >= $energy_cost)
{
     $energy_cost = floor($energy_cost);
 	$db->query("UPDATE users SET energy=energy - {$energy_cost} WHERE userid=$userid");
 	$_SESSION['attacklog']="";
 	$_SESSION['attackdmg']=0;
}
else
{
     print "You can only attack someone when you have 50% energy";
 	$h->endpage();
 	exit;

 

This is not a complete work over jsut a quick thing that should it work.

Posted
So you want 50% for non-donators and a "value" of 6 for donators?

 

if($_GET['wepid'])
{
 if($_SESSION['attacking']==0 && $ir['attacking'] == 0)
 {
$energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6';
if ($youdata['energy'] >= $energy_cost)
{
     $energy_cost = floor($energy_cost);
 	$db->query("UPDATE users SET energy=energy - {$energy_cost} WHERE userid=$userid");
 	$_SESSION['attacklog']="";
 	$_SESSION['attackdmg']=0;
}
else
{
     print "You can only attack someone when you have 50% energy";
 	$h->endpage();
 	exit;

 

This is not a complete work over jsut a quick thing that should it work.

You sure this will work? Sorry for saying this but it doesnt look like it makes sense ?(

Posted

It does make sense.

$energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6';

Is asking.... does the player have donator days if 0 days divide the energy by 2 (50%) else set the value as 6 which is what you asked for isnt it?

Posted
It does make sense.

$energy_cost = $ir['donatordays'] == 0 ? $youdata['maxenergy'] / 2 : '6';

Is asking.... does the player have donator days if 0 days divide the energy by 2 (50%) else set the value as 6 which is what you asked for isnt it?

Ok its just i have never seen a formula like that thats why i wasnt sure thanks.

Posted

Yeah the ternary operator is confusing as people seem to misunderstand it, it is very straight forward but many people on here probably didn't even know the name till just now (they won't abit that) but it's true most of them learn stuff from others IE ternary operator from lostone's codes. but yeah Alabama looks good mate.

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...