Frictional Games Forum (read-only)
Callback when enemy changes to inactive - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+--- Thread: Callback when enemy changes to inactive (/thread-53947.html)



Callback when enemy changes to inactive - Reminiscity - 11-17-2017

Hola!

Is there a way to check of enemy is inactive?

My first thought was to use a looping timer that checks if GetEnemyStateName is inactive but there is no such state...

Any ideas?


RE: Callback when enemy changes to inactive - Mudbill - 11-17-2017

GetEntityExists() might do what you need. If not, perhaps you can just create your own boolean and manually flip it whenever you enable/disable the enemy.


RE: Callback when enemy changes to inactive - Reminiscity - 11-17-2017

(11-17-2017, 06:38 PM)Mudbill Wrote: GetEntityExists() might do what you need. If not, perhaps you can just create your own boolean and manually flip it whenever you enable/disable the enemy.

The problem is that it seems like the enemy exists while being inactive. The boolean thing can't work because I have no way to manually flip it when the enemy despawns automatically(when the enemy is out of pathnodes and the player is not looking at it)

(11-17-2017, 07:25 PM)Reminiscity Wrote:
(11-17-2017, 06:38 PM)Mudbill Wrote: GetEntityExists() might do what you need. If not, perhaps you can just create your own boolean and manually flip it whenever you enable/disable the enemy.

The problem is that it seems like the enemy exists while being inactive. The boolean thing can't work because I have no way to manually flip it when the enemy despawns automatically(when the enemy is out of pathnodes and the player is not looking at it)

GOTTEM!!

void checkExist(string &in asTimer){

if(GetEnemyStateName("enemy") != "Hunt" && GetEnemyStateName("enemy") != "Search" && GetEnemyStateName("enemy") != "Patrol"
&& GetEnemyStateName("enemy") != "Wait" && GetEnemyStateName("enemy") != "Alert" && GetEnemyStateName("enemy") != "Investigate"
&& GetEnemyStateName("enemy") != "Track" && GetEnemyStateName("enemy") != "BreakDoor"){

//Do stuff

}

AddTimer("timer_checkExist", 2, "checkExist");

}


RE: Callback when enemy changes to inactive - Mudbill - 11-17-2017

Clever! I would suggest making that into its own function alone, something like

PHP Code:
bool GetEnemyActive(string &in asEnemyName) {
    if(
GetEnemyStateName(asEnemyName) != "Hunt" 
    
&& GetEnemyStateName(asEnemyName) != "Search" 
    
&& GetEnemyStateName(asEnemyName) != "Patrol"
    
&& GetEnemyStateName(asEnemyName) != "Wait" 
    
&& GetEnemyStateName(asEnemyName) != "Alert" 
    
&& GetEnemyStateName(asEnemyName) != "Investigate"
    
&& GetEnemyStateName(asEnemyName) != "Track" 
    
&& GetEnemyStateName(asEnemyName) != "BreakDoor")
        return 
true;
    return 
false;


Then you could just do

PHP Code:
void doStuff(string &in asTimer) {
    if(
GetEnemyActive("enemy")) {
        
//do stuff
    
}




RE: Callback when enemy changes to inactive - FlawlessHappiness - 11-18-2017

Hey. Quick thought.

Instead of checking whether the state is not all of those values, why not just check for the default value when the enemy is inactive?
Presumably, the default value is the empty string: ""


RE: Callback when enemy changes to inactive - Romulator - 11-18-2017

(11-18-2017, 12:14 AM)FlawlessHappiness Wrote: Hey. Quick thought.

Instead of checking whether the state is not all of those values, why not just check for the default value when the enemy is inactive?
Presumably, the default value is the empty string: ""

The default value may actually be "idle", since if the enemy state is not anything else, it should instead become idle.

(I think. Don't have the Model Editor on me right now)

Another option is to use ReplaceEntity or something similar. Having two enemies, say suitor_1 and suitor_2. Suitor_1 is the main enemy, and when he is disabled, replace him with suitor_2, then use GetEntityExists on suitor_1.


RE: Callback when enemy changes to inactive - FlawlessHappiness - 11-18-2017

Wouldn't "idle" also be a possible state if it was active? If so, it should currently be checked for as well in the GetEnemyActive method.

For your second thing, how would you know when Suitor_1 is disabled? Isn't that the problem?


RE: Callback when enemy changes to inactive - Romulator - 11-18-2017

(11-18-2017, 01:37 AM)FlawlessHappiness Wrote: For your second thing, how would you know when Suitor_1 is disabled? Isn't that the problem?

ReplaceEntity should remove one entity and replace with another, deleting the first, thus having GetEntityExists return false. should though, doesn't mean it will.

Thomas Grip, y u no release source code?