Author Topic: setRepairRate making it negative  (Read 1000 times)

The setRepairRate() function is a wonderful thing, but it can't be set to a negative number.
Is there anything that removes health like the setRepairRate function adds health?

setDamageLevel. Do math.

Code: [Select]
function Player::onDamage(%this,%obj,%delta)
{
Parent::onDamage(%this,%obj,%delta);
if(%delta > 0)
{
if(%obj.getState() !$= "Dead")
{
%obj.bleedStartSched1 = %obj.schedule(666,addHealth,-3);
%obj.bleedStartSched2 = %obj.schedule(1333,addHealth,-2);
%obj.bleedStartSched3 = %obj.schedule(2000,addHealth,-1);
}
}
}
I want the player to bleed after he is hit for a short time but when he's hit he keeps loosing health.
It is because when health is removed onDamage is called again.
This is why I want a negative setRepairRate.
« Last Edit: February 08, 2011, 07:41:35 PM by Kiwi »

couldn't you just have a function that takes a damage amount and a loopcount? sorta like a for loop i guess (in that it counts down a # of times, but is delayed)


Yes, I try to get right this effect.
Problem is when you remove health from the player onDamage is called again.
I just need help with this simple thing because I'm no scripter.

Yes, I try to get right this effect.
Problem is when you remove health from the player onDamage is called again.
I just need help with this simple thing because I'm no scripter.
oh, i see now, so when they get hit, it triggers an inf loop?

I don't think .setDamageLevel calls onDamage

Code: [Select]
function Player::onDamage(%this,%obj,%delta)
{
Parent::onDamage(%this,%obj,%delta);
%currentDamage = %obj.getDamageLevel();
if(%delta > 0)
{
if(%obj.getState() !$= "Dead")
{
%obj.bleedSched1 = %obj.schedule(1000,setDamageLevel,%currentDamage+3);
%obj.bleedSched2 = %obj.schedule(2000,setDamageLevel,%currentDamage+2);
%obj.bleedSched3 = %obj.schedule(3000,setDamageLevel,%currentDamage+1);
}
}
}
This has a similar effect, loops infinite.
Why can't you make setRepairRate negative?
« Last Edit: February 09, 2011, 08:29:51 PM by Kiwi »

Why can't you make setRepairRate negative?
It wasn't programmed that way

A simple way to do this would be as follows:
Code: [Select]
function Player::bleed(%obj, %damage, %interval, %ticks, %sourceObj, %damageType)
{
for(%i = 1; %i <= %ticks; %i++)
{
%obj.schedule(%i * %interval, damage, %sourceObj, %obj.getPosition(), %damage / %ticks, %damageType);
}
}

%obj is the player, %damage is the total damage done over the course of the effect, %interval is the time between each tick, %ticks is the total number of ticks, %sourceObj is the source of the damage, and %damageType is the damage type used to deal the damage. A sample usage would be:

%col.bleed(100, 1000, 10, %obj.sourceObject, $DamageType::Gun);

This would cause the player %col to bleed for 100 total damage of type $DamageType::Gun from %obj.sourceObject, ticking a total of 10 times, once every 1000 ms.

This is working quite well but still calls onDamage.
First it does 10 damage,20 damage, 40 damage, then kills when I include it into the onDamage function of my playertype.
Now I came up with an idea:
Code: [Select]
function PlayerEliteForceArmor::onDamage(%this,%obj,%delta)
{
Parent::onDamage(%this,%obj,%delta);
if(%delta > 0)
{
if(%obj.getState() !$= "Dead")
{
%currentDamage = %obj.getDamageLevel();
%addingDamage = %activeDamage / 10;
if(%activeDamage < 10)
{
%activeDamage += 1
bleedSchedule1 = %obj.schedule(333,setDamageLevel,%currentDamage+%addingDamage);
}
else
{
%activeDamage = 0;
parent::onDamage(%this,%obj,%delta);
}
}
}
}
Now this does the bleeding sort of like I want it, but not really.
Because when I got hit 3 times it also bleeds 3 times.
But I think I'm on the right track.
What does the ::onDamage(%this,%obj,%delta) stand for?

I would think that delta means the amount.

snip
Oh, I see why you were trying to avoid ::onDamage now. I'm fairly certain the %delta in onDamage is the amount, and that there are more than three arguments. The only way I could think to make what you're trying to do work is to use a special bleeding damage type and then package player::damage rather than armor::onDamage and only trigger a bleed when the damagetype isn't a bleed itself so you don't run into that stacking effect.

Oh, I see why you were trying to avoid ::onDamage now. I'm fairly certain the %delta in onDamage is the amount, and that there are more than three arguments. The only way I could think to make what you're trying to do work is to use a special bleeding damage type and then package player::damage rather than armor::onDamage and only trigger a bleed when the damagetype isn't a bleed itself so you don't run into that stacking effect.
This is going too high for my poor scripting knowledge.
I'll just throw it since it's not easy to accomplish.
It still would be awesome if you guys contributed such a function to a realistic playertype.
Might make Gravity Cats games even more realistic. ;)