Raised This Month: $ Target: $400
 0% 

OnEntityCreated check owner


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Boonie
Member
Join Date: Aug 2015
Old 09-21-2015 , 02:21   OnEntityCreated check owner
Reply With Quote #1

So I'm checking to see if an entity that was created is owned by a client. Is this the best way to do this?

PHP Code:
public void OnEntityCreated(int entity, const char[] classname) {
    
int client;
    
client GetEntPropEnt(entityProp_Data"m_hOwnerEntity");
    if (
client >= && client <= MaxClients && IsClientInGame(client)) {
        if (
IsValidEntity(entity)) {
            
// Stuff
        
}
    }


Last edited by Boonie; 09-21-2015 at 02:23.
Boonie is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-21-2015 , 03:36   Re: OnEntityCreated check owner
Reply With Quote #2

You should check it after the entity has spawned, if you check before it may not have been set.
Mitchell is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-21-2015 , 03:43   Re: OnEntityCreated check owner
Reply With Quote #3

Sdk hook on spawned from on entity created.

On the spawned callback check for the owner.
__________________
Neuro Toxin is offline
Boonie
Member
Join Date: Aug 2015
Old 09-21-2015 , 04:56   Re: OnEntityCreated check owner
Reply With Quote #4

That worked, thanks.
Boonie is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-21-2015 , 09:53   Re: OnEntityCreated check owner
Reply With Quote #5

Quote:
Originally Posted by Mitchell View Post
You should check it after the entity has spawned, if you check before it may not have been set.
In fact, at creation time, it's guaranteed to not have a value set as that's before the game has populated any attributes on it.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
DeathChaos25
Senior Member
Join Date: Jan 2014
Location: Puerto Rico
Old 09-24-2015 , 09:27   Re: OnEntityCreated check owner
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
In fact, at creation time, it's guaranteed to not have a value set as that's before the game has populated any attributes on it.
A great example of this is the common infected in L4D2, you can't get their model OnEntityCreated, so as a rule of thumb, unless it is absolutely necessary I just create a 1 second timer and then do whatever it is that needs done with said entity.
__________________
DeathChaos25 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-24-2015 , 17:57   Re: OnEntityCreated check owner
Reply With Quote #7

Why use a timer. You should hook spawned on entity created.

Using a timer may get the same problem if it fires before spawn is dispatched by the game / plugin.
__________________
Neuro Toxin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-24-2015 , 18:12   Re: OnEntityCreated check owner
Reply With Quote #8

Quote:
Originally Posted by Neuro Toxin View Post
Why use a timer. You should hook spawned on entity created.

Using a timer may get the same problem if it fires before spawn is dispatched by the game / plugin.
Not really, timer is little bit slower and thats why works better
Thread: NoFlash/NoSmoke [CSGO]
View Single Post

*edit
RequestFrame works also tough
__________________
Do not Private Message @me

Last edited by Bacardi; 09-24-2015 at 18:18.
Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-24-2015 , 19:02   Re: OnEntityCreated check owner
Reply With Quote #9

Quote:
Originally Posted by Neuro Toxin View Post
Why use a timer. You should hook spawned on entity created.

Using a timer may get the same problem if it fires before spawn is dispatched by the game / plugin.
Actually, there are times when the game spawns an object then sets the properties of it on the next frame. OnRequestFrame would also fix that, but it wasn't available until SourceMod 1.6.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 11:53.


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