AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [L4D2] Target Entity With Hammer ID (https://forums.alliedmods.net/showthread.php?t=339269)

alasfourom 08-29-2022 10:25

[L4D2] Target Entity With Hammer ID
 
Hello Everyone

May I know Why This Doesn't Work

PHP Code:

public void OnMapStart()
{
    
int entity = -1;
    
char sMap[32];
    
GetCurrentMap(sMapsizeof(sMap));
    
    if (
strcmp(sMap"c1m4_atrium") == && (entity FindByClassTargetHammedID("prop_door_rotating_checkpoint""171930")) != -1)
        
HookSingleEntityOutput(entity"OnOpen"OnSaferoomOpened);
}

public 
void OnSaferoomOpened(const char[] outputint callerint activatorfloat delay)
{
    
PrintToChatAll("Hello World");
}

public 
int FindByClassTargetHammedID(const char[] sClass, const char[] sTarget)
{
    
char sHammerID [64];
    
int entity = -1;
    while ((
entity FindEntityByClassname(entitysClass)) != INVALID_ENT_REFERENCE)
    {
        
GetEntPropString(entityProp_Data"m_iHammerID"sHammerID sizeof(sHammerID ));
        if (
strcmp(sTargetsHammerID ) == 0) return entity;
    }
    return -
1;


Thanks

Bacardi 08-29-2022 10:44

Re: [L4D2] Target Entity With Hammer ID
 
Wild guess is, you lose hook when you spawn, so OnMapStart is too early (I guess).

You can confirm by making "test" console command to execute FindByClassTargetHammedID() manually.
- So spawn on map, use test command and look can you get hook callback working.

*would it be easier to you use HookEntityOutput on OnPluginStart ?


Another guess could be "OnOpen", maybe it is not fired, don't know.
here some outputs of that door
https://raw.githubusercontent.com/am...nameoutputs.kv
Code:

                "outputs"
                {
                        "m_OnBlockedOpening"                "OnBlockedOpening"
                        "m_OnBlockedClosing"                "OnBlockedClosing"
                        "m_OnUnblockedOpening"                "OnUnblockedOpening"
                        "m_OnUnblockedClosing"                "OnUnblockedClosing"
                        "m_OnFullyClosed"                "OnFullyClosed"
                        "m_OnFullyOpen"                "OnFullyOpen"
                        "m_OnClose"                "OnClose"
                        "m_OnOpen"                "OnOpen"
                        "m_OnLockedUse"                "OnLockedUse"
                        "m_pOutputAnimBegun"                "OnAnimationBegun"
                        "m_pOutputAnimOver"                "OnAnimationDone"
                        "m_OnBreak"                "OnBreak"
                        "m_OnHealthChanged"                "OnHealthChanged"
                        "m_OnTakeDamage"                "OnTakeDamage"
                        "m_OnPhysCannonDetach"                "OnPhysCannonDetach"
                        "m_OnPhysCannonAnimatePreStarted"                "OnPhysCannonAnimatePreStarted"
                        "m_OnPhysCannonAnimatePullStarted"                "OnPhysCannonAnimatePullStarted"
                        "m_OnPhysCannonAnimatePostStarted"                "OnPhysCannonAnimatePostStarted"
                        "m_OnPhysCannonPullAnimFinished"                "OnPhysCannonPullAnimFinished"
                        "m_OnIgnite"                "OnIgnite"
                        "m_OnUser1"                "OnUser1"
                        "m_OnUser2"                "OnUser2"
                        "m_OnUser3"                "OnUser3"
                        "m_OnUser4"                "OnUser4"
                }


Marttt 08-29-2022 11:00

Re: [L4D2] Target Entity With Hammer ID
 
Yeah too early, better do OnEntityCreated+SpawnPost (if you need it ASAP) and/or in lateload call.

Also hammerid is a integer AFAIK
PHP Code:

        int iHammerID;
        
iHammerID GetEntProp(entityProp_Data"m_iHammerID"); 


Bacardi 08-29-2022 11:26

Re: [L4D2] Target Entity With Hammer ID
 
...L4D2 have also events like
round_start
round_freeze_end

if want try use hook single entity

alasfourom 08-29-2022 16:13

Re: [L4D2] Target Entity With Hammer ID
 
PHP Code:

#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required
#define PLUGIN_VERSION "1.0"

public void OnMapStart()
{
    
int entity = -1;
    
char sMap[32];
    
GetCurrentMap(sMapsizeof(sMap));
    
    while ((
entity FindEntityByClassname(entity"prop_door_rotating_checkpoint")) != INVALID_ENT_REFERENCE)
    {
        if (
strcmp(sMap"c1m4_atrium") == && GetEntProp(entityProp_Data"m_iHammerID") == 171930)
        {
            
HookSingleEntityOutput(entity"OnOpen"OnSaferoomOpened);
            break;
        }
    }
}

public 
void OnSaferoomOpened(const char[] outputint callerint activatorfloat delay)
{
    
PrintToChatAll("Hello World");


Worked For Me

Marttt 08-29-2022 16:38

Re: [L4D2] Target Entity With Hammer ID
 
it won't work always,
OnMapStart may run before the entity is created.
If you load the plugin mid-game it will work
but if you start the map from zero it may fail sometimes.
do some tests.

The safe way is to do as I said, never had issues

alasfourom 08-29-2022 16:41

Re: [L4D2] Target Entity With Hammer ID
 
I will use it for different entity, with round start, I will also create timer for it

thank you Marttt and Bacardi


All times are GMT -4. The time now is 01:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.