Jump to content
ErhanK

Call a custom function on hitinfo entity

Recommended Posts

Hi. How can i call a custom function on my hitinfo entity?

if (PickResult) {
	if (PickInfo.entity->GetClass() == Entity::ModelClass) {
		if (PickInfo.entity->GetKeyValue("GameObjectType") == "NpcBase") {
			//PickInfo.entity-> ?? ex. GetHurt()
		}
	}
}

 

Share this post


Link to post

I want to call the custom function in a c++ class ... I have one more question. I don't know which is better. I've created a custom actor class. This class creates an entity within itself and attaches itself to it. Should I use this, or should I create an entity, also create a custom actor and then assign that actor to that entity? I gave an example below.

//Header
class EnemyBaseActor : public Actor {
public:
    EnemyBaseActor();
};
//CPP
EnemyBaseActor::EnemyBaseActor(){
    this->entity = Model::Load("Models/Zombie.mdl"); 
    this->entity->SetActor(this);   
}

OR

// In the main ex.
Entity* myEntity = Model::Load("Models/Zombie.mdl");
Actor* zombieActor = new EnemyBaseActor(); //My custom actor.
myEntity->SetActor(zombieActor);
//zombieActor->Release(); // It's doesn't work. So i didn'n write it.

it works in two ways, but which one is right?

Share this post


Link to post

Both of those code examples do the exact same thing.

Share this post


Link to post

Cast the Actor object to your custom actor object and the function will be available. See C++ dynamic casting.

Share this post


Link to post

So i need this :

if (PickInfo.entity->GetKeyValue("GameObjectType") == "NpcBase") {
	//NPC_Base is my custom actor
	NPC_Base* tmp = dynamic_cast<NPC_Base*>(PickInfo.entity->GetActor());
	tmp->DoSomething();
}

and thank you so much :)

Share this post


Link to post

A dynamic cast will return NULL if the conversion is not valid. (A static cast can potentially return an invalid object.) So you might want to also check if the result of the cast is NULL before continuing.

  • Thanks 1

Share this post


Link to post

I should really write something on how I handle Actors. Not to brag but my system is just really nice. 🙂

  • Like 1

Share this post


Link to post

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