Game Development Community

dev|Pro Game Development Curriculum

Breaking MaxHealth and Energy from the Databock

by Vince Gee · 03/17/2006 (6:59 pm) · 33 comments

Ok,

Step one, in shapebase.h add
F32 mMaxDamage;

right after
class ShapeBase : public GameBase
	{
	typedef GameBase Parent;
	friend class ShapeBaseConvex;
	friend class ShapeBaseImageData;
	friend void physicalZoneFind(SceneObject*, void *);

	public:

Then,

Do a global search and replace for mDataBlock->MaxDamage and replace it w/ mMaxDamage

Then go to ShapeBase.cc
After
ShapeBase::ShapeBase()
	{
	mTypeMask |= ShapeBaseObjectType;
add
mMaxDamage = 100;

and at the end add
ConsoleMethod( ShapeBase, setMaxDamage, void, 3, 3, "(F32 Max Damage)")
	{
	if (object->isServerObject())
		{
		object->mMaxDamage = dAtof(argv[2]);
		object->setMaskBits(object->DamageMask);
		}
	}

Thats it, basically the step we were missing all along was updating the masks, now that the masks are updated when ever you change the hp, things update correctly....

BTW, "WE" means dreamer and I... sorry dreamer...


Vince
Page«First 1 2 Next»
#21
05/22/2006 (5:43 pm)
hi:)

would there be a getmax damage function to go with this to check whats set?

I am pretty sure I am updating correctly when items are added and levels are gained, but a simple getmaxdamage to echo would be really useful :)

Regards

Graham
#22
06/30/2006 (8:08 am)
Alright this tutorial is awesome! 5/5
#23
07/05/2006 (3:32 pm)
I have a couple questions about this.
First of all how would you go about doing a script call to retrieve the value stored in mMaxDamage?
Secondly how would this function look if it were for maxEnergy?
ConsoleMethod( ShapeBase, setMaxDamage, void, 3, 3, "(F32 Max Damage)")
	{
	if (object->isServerObject())
		{
		object->mMaxDamage = dAtof(argv[2]);
		object->setMaskBits(object->DamageMask);
		}
	}
#24
09/21/2006 (1:22 am)
is this working on the client side for people?
#25
12/16/2006 (2:42 pm)
Just as a fyi
@kyle

%player.setMaxDamage(100000000);

Vince
#26
12/16/2006 (3:01 pm)
btw,

you might want to add to the console method
ConsoleMethod( ShapeBase, setMaxDamage, void, 3, 3, "(F32 Max Damage)")
	{
	if (object->isServerObject())
		{
		object->mMaxDamage = dAtof(argv[2]);
		object->setMaskBits(object->DamageMask);
		[b]

object->setDamageLevel(0);
[/b]
		}
	}

I just did that since I would kill people if I lowered their health below their current damage :)
#27
05/02/2007 (7:05 am)
hi, the resource seams to work great :D ...

but i wanted to add the shape->getMaxDamage() to the guiShapeNameHud. The function allways returns the default value set in ShapeBase.cc. The console function getmaxdamage works correct.

edit: i added getmaxdamage to see the maxdamage...
#28
07/27/2007 (2:06 am)
hey everyone,

Completed this, and it compiles with no errors. however I have two questions, you said:

Do a global search and replace for mDataBlock->MaxDamage and replace it w/ mMaxDamage

Then go to ShapeBase.cc


i find no mDataBlock->MaxDamage in ShapeBase.h, but plenty in ShapeBase.cc so i replaced them in the .cc did not you mean this?

second, it is not working for me, I added a getMaxDamage function:

ConsoleMethod( ShapeBase, getMaxDamage, F32, 2, 2, "")
{
return object->mMaxDamage;
}

when I for example use %player.setMaxDamage(50); (with %player the playerObject's handle ofcourse) and then type echo(%player.getMaxDamage()); it still echoes 100 in the console!
anyone else have this problem or know why this is happening/know how to solve it?

thanks

*Edit: extra information to my problem, when i change mMaxDamage in shapeBase::ShapeBase() %player.getMaxDamage() matches this, even when changed by %player.setMaxDamage(%val);
#29
07/27/2007 (2:21 am)
Hah, i found the fix already..

I restored to exactly! what you guys wrote, and i found out that not my getMaxDamage function was the problem (so you guys can if you have not already surely add that) but somehow the fix posted by Vince Gee was the problem,
vince are you sure it works for you?

thanks everyone
#30
07/27/2007 (2:41 am)
Oh haha, this tutorial does not work at all. it only sets the damage to be displayed, but the damage that has to be taken to invoke damageStates such as disabled or destroyed are not changed, meaning that no matter what, you will still only die when you take %datablock.maxDamage damage (100 probably), so when you have %player.setMaxDamage(200), you will die with still 100 hp on your display, and when you set mMaxDamage to below 100, you will never die since your damage will be restricted, to say, 90. and you will therefore never get to the 100 damage taken.
#31
07/27/2007 (3:14 am)
Found a fix: in player.cc find:

void Player::updateDamageLevel()
{
if (!isGhost())
setDamageState((mDamage >= mDataBlock->maxDamage)? Disabled: Enabled);
if (mDamageThread)
mShapeInstance->setPos(mDamageThread, mDamage / mDataBlock->destroyedLevel);
}

and replace with:

void Player::updateDamageLevel()
{
if (!isGhost())
setDamageState((mDamage >= mMaxDamage)? Disabled: Enabled);
if (mDamageThread)
mShapeInstance->setPos(mDamageThread, mDamage / mDataBlock->destroyedLevel);
}

also it would be best to get destroyedLevel out of the datablock and replace:

mShapeInstance->setPos(mDamageThread, mDamage / mDataBlock->destroyedLevel);

with:

mShapeInstance->setPos(mDamageThread, mDamage / mDestroyedLevel);


*Edit: Im not sure, but it might impose other glitches in the programming, someone please check it out. it runs fine for me though
#32
04/24/2008 (4:21 pm)
Has anyone been able to get this to work on 1.5.2? I've followed every step perfectly and even tried what Tijs suggested, but haven't been able to change hp, still die at 100HP.
#33
12/16/2009 (2:33 am)
Anyone know how to do the Equivalent in T3D?
Page«First 1 2 Next»