Author Topic: Adding max health on a datablock  (Read 1302 times)

I have created a datablock and I am not sure with is wrong with the code. It will set the max health based on how many players are on the server. Here is the code:

Code: [Select]
package Base100x75
{
function PlayerBase100x75::onAdd(%this, %client)
  {
%maxHP = %this.getFirstDatablock().maxDamage;
%hp = (%this.getFirstDatablock().maxDamage - %this.getDamageLevel());
%baseAddA = %maxHP + (ClientGroup.getcount();*75);
{
    %this.setDamageLevel(%this.getDatablock().maxDamage + %baseAddA);
messageClient(%client, '', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %this.getDatablock().maxDamage "<color:FF00FF>HP<color:FFFFFF>");
}
  }
};
ActivatePackage(Base100x75);

Here is the error:

%baseAddA = %maxHP + (ClientGroup.getcount();##*##75);

I don't see anything wrong.

I have created a datablock and I am not sure with is wrong with the code. It will set the max health based on how many players are on the server. Here is the code:

Code: [Select]
package Base100x75
{
function PlayerBase100x75::onAdd(%this, %client)
  {
%maxHP = %this.getFirstDatablock().maxDamage;
%hp = (%this.getFirstDatablock().maxDamage - %this.getDamageLevel());
%baseAddA = %maxHP + (ClientGroup.getcount();*75);
{
    %this.setDamageLevel(%this.getDatablock().maxDamage + %baseAddA);
messageClient(%client, '', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %this.getDatablock().maxDamage "<color:FF00FF>HP<color:FFFFFF>");
}
  }
};
ActivatePackage(Base100x75);

Here is the error:

%baseAddA = %maxHP + (ClientGroup.getcount();##*##75);

I don't see anything wrong.

Can't have a semi-colon in there like that.

Well, I have done this:
   
Code: [Select]
%baseAddA = %maxHP + (ClientGroup.getcount()*75);
But then the error was:

package Base100x75

{

^function PlayerBase100x75::onAdd(%this, %client)

  {

^%maxHP = %this.getFirstDatablock().maxDamage;

^%hp = (%this.getFirstDatablock().maxDamage - %this.getDamageLevel());

^%baseAddA = %maxHP + (ClientGroup.getcount()*75);

^{##
##
    %this.setDamageLevel(%this.getDatablock().maxDamage + %baseAddA);

^messageClient(%client, '', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %this.getDatablock().maxDamage "<color:FF00FF>HP<color:FFFFFF>");

^}

  }

};

ActivatePackage(Base100x75);

Because you have a random pair of brackets?

No...But I have heard that sometimes the error is above the ## error...

Hold on, I am going to test this code:

Code: [Select]
package Base100x75
{
function PlayerBase100x75::onAdd(%this, %client)
  {
        %clCount = ClientGroup.getcount();
%maxHP = %this.getFirstDatablock().maxDamage;
%hp = (%this.getFirstDatablock().maxDamage - %this.getDamageLevel());
%baseAddA = (%maxHP + (%clCount*75));
{
        %this.setDamageLevel(%this.getDatablock().maxDamage + %baseAddA);
messageClient(%client, '', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %this.getDatablock().maxDamage "<color:FF00FF>HP<color:FFFFFF>");
}
  }
};
ActivatePackage(Base100x75);

Ok maybe I shouldn't have used a question mark there.
Yes, you do have a random pair of brackets.
The setDamageLevel and messageClient calls are inside them, and they don't correspond with structure such as an if, a loop, etc

Would this work? Or do I need to edit it a little?

Code: [Select]
package Base100x75
{
function PlayerBase100x75::onAdd(%this, %client)
{
%newDamage = %this.getDatablock().maxDamage;
%clCount = ClientGroup.getcount();
%maxHP = %this.getFirstDatablock().maxDamage;
%hp = (%this.getFirstDatablock().maxDamage - %this.getDamageLevel());
%baseAddA = (%maxHP + (%clCount*75));
%class = %this.getClassName();
if(%class $= "AiPlayer" ||%class $= "Player")
{
%this.setDamageLevel(%this.getDatablock().maxDamage + %baseAddA);
messageClient(%client, '', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %newDamage @ "<color:FF00FF>HP");
}
}
};
ActivatePackage(Base100x75);
EDIT: I have updated this code.
NEW EDIT: It has now executed, testing right now if it works.
« Last Edit: December 16, 2012, 09:55:46 PM by Advanced Bot »

Darn. It does not work... The playertype works, but the mod didn't work.. What is wrong?

Please, for the sake of humanity, read this and learn to use it:

http://forum.blockland.us/index.php?topic=192083.0

It is not just that now. Now everytime I take out a brick or move, now it makes a death noise and then I can't move.. here is the code:

Code: [Select]
function Armor::onTrigger(%datablock,%player,%slot,%io)
{
%newDamage = %player.getDatablock().maxDamage;
%clCount = ClientGroup.getcount();
%hp = (%player.getDatablock().maxDamage - %player.getDamageLevel());
%baseAddA = (%newDamage + (%clCount*75));
%class = %player.getClassName();
if(%class $= "AiPlayer" ||%class $= "Player")
{
%player.setDamageLevel(%player.getDatablock().maxDamage + %baseAddA);
messageClient(%client, 'MsgAdminForce', "<color:FFFFFF>Your new health is:<color:00FF00>" SPC %newDamage @ "<color:FF00FF>HP");
}
Parent::onTrigger(%datablock,%player,%slot,%io);
}

Damage level is amount of damage, not amount of health. You're setting it to have taken (max health + max health + 75 * number of clients) damage, which is always greater than the maximum health, so you die instantly.

Additionally setDamageLevel can't be less than zero for 'increased health' (e.g. 'addHealth' event never increases past the starting amount) - you'd have to make a player type with some upper limit of health and then do the calculation to figure out how much health to take off that total.

Thanks for the help. I will also look at the tf2 medigun about the max damage.

Well, now I did things a different way thanks to Innocent. Instead of adding damage it adds a damage mulitplier as:

Code: [Select]
         %multiplier = clientGroup.getCount() * 50;
         %damage = %damage / %multiplier;

Now I have made 5 playertypes with different strengths and different health, now they can be bosses and don't have the same strength everytime.