I want to be able to heal a player, so i write a member Function of EntHumanPlayerT TakeHeal() that gives the Player +20 Health
So in Think() I write a Code that starts a trace, get an EntityID if the crosshair is on a player i would heal.
So now the problem
With GetBaseEntityByID i get just a BaseEntityT, but this doesnt have the member function TakeHeal. So i need a EntHumanPlayerT.
Could I convert the BaseEntityT to EntHumanPlayerT or could I get a EntHumanPlayerT by a EntityID??
Problem with new Functions of EntHumanPlayerT
So I write
Edit: I include "CompanyBot.hpp" and it works fine
Edit:
Hmm, with EntHumanPlayerT instead of EntCompanyBotT it works fine
BaseEntityT* HitEntity = EngineFunctions->GetBaseEntityByID(EngineFunctions->Ca3DEWorldHandle, HitEntityID);
((EntCompanyBotT*)HitEntity)->TakeHeal();
Edit: I include "CompanyBot.hpp" and it works fine
Edit:
Hmm, with EntHumanPlayerT instead of EntCompanyBotT it works fine
Thank you very muchBaseEntityT* HitEntity = EngineFunctions->GetBaseEntityByID(EngineFunctions->Ca3DEWorldHandle, HitEntityID);
((EntCompanyBotT*)HitEntity)->TakeHeal();
Nice to see that you and the others solved the problem even before I noticed the first post.
Camille is right: If you are sure that the BaseEntityT* actually points to a EntHumanPlayerT*, casting the pointer as you did is no problem.
Another approach would be to keep the code that you have in "TakeHeal()" just where you want to apply it, and work with the BaseEntityT* directly, like this:
This variant is not very OO, but also works without the potentially unsafe pointer cast.
Camille is right: If you are sure that the BaseEntityT* actually points to a EntHumanPlayerT*, casting the pointer as you did is no problem.
Another approach would be to keep the code that you have in "TakeHeal()" just where you want to apply it, and work with the BaseEntityT* directly, like this:
Code: Select all
BaseEntityT* HitEntity = EngineFunctions->GetBaseEntityByID(EngineFunctions->Ca3DEWorldHandle, HitEntityID);
if (HitEntity->TypeID==TYPEID_HUMANPLAYER)
{
// "Give" heal. (This would be the code from TakeHeal().)
HitEntity->State.Health+=20;
if (HitEntity->State.Health>100) HitEntity->State.Health=100;
// etc.
}
Best regards,
Carsten
Carsten
Who is online
Users browsing this forum: No registered users and 14 guests