Raised This Month: $ Target: $400
 0% 

finding entity by name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 02-16-2014 , 07:02   finding entity by name
Reply With Quote #1

I need to find entity phys_hinge with "targetname" "hinge1"
Here is my code:

Version 1

Code:
public OnEntityCreated(entity, const String:classname[]) { 
	SDKHook(entity, SDKHook_Spawn, OnEntitySpawned); 
}
public OnEntitySpawned(entity) { 
	decl String:strName[50];
	GetEntPropString(entity, Prop_Data, "m_iName", strName, sizeof(strName));
	if(strcmp(strName, "hinge1") == 0)
	{
    		PrintToServer("ENT %s", strName);
	}
}
Version 2

Code:
public OnPluginStart() {
	HookEvent("round_start", Event_RoundStart);
}
public  Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast) {
        new entCount = GetEntityCount(); 
	for(new  i = 0; i != entCount; i++ )  {
		if(IsValidEntity(i)) {
			GetEntPropString(i, Prop_Data, "m_iName", strName, sizeof(strName)); 
			if(strcmp(strName, "hinge1") == 0)
			{
		    		PrintToServer("ENT!!! %s", strName);
			}
		}
	}
}
But it does not work. This only works if entityclass is not phys_hinge (prop dynamic for example)
kadet.89 is offline
Send a message via Skype™ to kadet.89
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 02-16-2014 , 07:31   Re: finding entity by name
Reply With Quote #2

I found a strange sourcemod bug:

Code:
	new ent = CreateEntityByName("phys_hinge");
	PrintToServer("ent %i", ent);
	ent = CreateEntityByName("prop_physics");
	PrintToServer("ent %i", ent);
console dump:
ent -2025748447
ent 74

How can this be?
kadet.89 is offline
Send a message via Skype™ to kadet.89
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 02-16-2014 , 07:33   Re: finding entity by name
Reply With Quote #3

Try this:
PHP Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart);
}

public 
Event_RoundStart(Handle:hEvent, const String:sName[], bool:bBroadcast)
{
    
decl iEnt;
    while (
iEnt FindEntityByClassname(-1"phys_hinge"))
    {
        if (!
IsValidEntity(iEnt)) continue;

        
decl String:sName[32];
        
GetEntPropString(iEntProp_Data"m_iName"sNamesizeof(sName)); 
        
        if (
StrEqual(sName"hinge1"false))
        {
            
PrintToServer("ENT!!! %s"sName);

            break;
        }
    }


Last edited by Marcus_Brown001; 02-16-2014 at 07:34.
Marcus_Brown001 is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 02-16-2014 , 07:46   Re: finding entity by name
Reply With Quote #4

Marcus_Brown001, does not work . Furthermore, it does not find any of the existing phys_hinge.
But I can control phys_hinge through func_button, ie it exists....

Is it SourceMod bug?

Last edited by kadet.89; 02-16-2014 at 08:53.
kadet.89 is offline
Send a message via Skype™ to kadet.89
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-16-2014 , 11:55   Re: finding entity by name
Reply With Quote #5

Quote:
Originally Posted by kadet.89 View Post
I found a strange sourcemod bug:
console dump:
ent -2025748447
That's not a bug, none-edicts are handled by entity reference, not by their entity index.
See: https://wiki.alliedmods.net/Entity_R...es_(SourceMod)
There is also an example code how to find those entities.
Could also be that that specific entity phys_hinge is for the client only and can't be found on the server...
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by bl4nk; 02-16-2014 at 12:26. Reason: fixed url
berni 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 22:24.


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