Raised This Month: $32 Target: $400
 8% 

Solved [L4D2] Target Entity With Hammer ID


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-29-2022 , 10:25   [L4D2] Target Entity With Hammer ID
Reply With Quote #1

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
__________________

Last edited by alasfourom; 08-29-2022 at 16:14.
alasfourom is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-29-2022 , 10:44   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #2

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"
		}
__________________
Do not Private Message @me

Last edited by Bacardi; 08-29-2022 at 10:45.
Bacardi is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-29-2022 , 11:00   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #3

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"); 
__________________

Last edited by Marttt; 08-29-2022 at 11:01.
Marttt is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-29-2022 , 11:26   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #4

...L4D2 have also events like
round_start
round_freeze_end

if want try use hook single entity
Bacardi is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-29-2022 , 16:13   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #5

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
__________________
alasfourom is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-29-2022 , 16:38   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #6

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
__________________

Last edited by Marttt; 08-29-2022 at 16:38.
Marttt is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-29-2022 , 16:41   Re: [L4D2] Target Entity With Hammer ID
Reply With Quote #7

I will use it for different entity, with round start, I will also create timer for it

thank you Marttt and Bacardi
__________________
alasfourom is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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