ErhanK Posted January 12, 2020 Share Posted January 12, 2020 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() } } } Quote Link to comment Share on other sites More sharing options...
Josh Posted January 13, 2020 Share Posted January 13, 2020 Do you want a Lua or C++ function to be called? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
ErhanK Posted January 13, 2020 Author Share Posted January 13, 2020 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? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 13, 2020 Share Posted January 13, 2020 Both of those code examples do the exact same thing. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted January 13, 2020 Share Posted January 13, 2020 Cast the Actor object to your custom actor object and the function will be available. See C++ dynamic casting. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
ErhanK Posted January 13, 2020 Author Share Posted January 13, 2020 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 :) Quote Link to comment Share on other sites More sharing options...
Josh Posted January 13, 2020 Share Posted January 13, 2020 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. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted January 13, 2020 Share Posted January 13, 2020 I should really write something on how I handle Actors. Not to brag but my system is just really nice. ? 1 Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
ErhanK Posted January 13, 2020 Author Share Posted January 13, 2020 you really must do Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.