Raised This Month: $51 Target: $400
 12% 

Team Fortress | is there way to detect each frame how many entity is on map


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jacek2144
Senior Member
Join Date: Jun 2011
Old 12-23-2012 , 14:52   Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #1

hello is there any possiblity to detect how many specific entities example info_target is on map and be checked each frame so if we got 10 info_target it prints 10 if 5 got destroyed it prints 5 and 6 created it prints 11

Thanks
jacek2144 is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 12-23-2012 , 15:17   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #2

Certainly.
PHP Code:
#include <sourcemod>
#include <sdktools>

public OnGameFrame()
{
    new 
countString:cls[14];
    for (new 
Ent MaxClients 1Ent <= 4096Ent++)
    {
        if (!
IsValidEntity(Ent)) continue;
        
GetEntityClassname(Entclssizeof(cls));
        if (!
StrEqual(cls"info_target"false)) continue;
        
count++;
    }
    
// Print("%i", count);

I've done horrible, horrible things with strings OnGameFrame before, so that shouldn't cause any real performance loss. Probably.
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 12-23-2012 , 15:33   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #3

Additionally you can type report_entities in console to get the information you seek.
Sreaper is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-23-2012 , 15:49   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #4

Christ, that's terrible. Use FindEntityByClassname.
__________________
asherkin is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-23-2012 , 19:01   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #5

According to my profiling using FindEntityByClassName is 16x faster than MasterOfTheXP's version.
Still i doubt it's clever to do this every frame, maybe you can grab the count once and use OnEntity - (Created|Destroyed) from SdkHooks to update it.

Yours sincerely
Impact
__________________

Last edited by Impact123; 12-23-2012 at 19:03.
Impact123 is offline
MasterOfTheXP
Veteran Member
Join Date: Aug 2011
Location: Cloudbank
Old 12-23-2012 , 19:24   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
Christ, that's terrible.
I know, right??? I tried report_entities myself and it completely disappointed me.
Just kidding, I know my methods are awful compared to things that more intelligent people use
Quote:
Originally Posted by Impact123 View Post
Still i doubt it's clever to do this every frame, maybe you can grab the count once and use OnEntity - (Created|Destroyed) from SdkHooks to update it.
Yeah, it's almost always better to hook stuff rather than framing it, no matter how good/fast it is.
__________________
Plugins / My Steam / TF2 Sandbox (plugin beta testing!)
MasterOfTheXP is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 12-24-2012 , 12:53   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #7

I would use decl instead of new in OnGameFrame.
__________________
retired
shavit is offline
minimoney1
SourceMod Donor
Join Date: Dec 2010
Old 12-24-2012 , 14:41   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #8

Quote:
Originally Posted by shavit View Post
I would use decl instead of new in OnGameFrame.
It wouldn't really make that much of a difference in this case. It's a very small string.
__________________
Need help? PM me or add me on Steam.
My Steam




Quote:
Originally Posted by Rp.KryptoNite View Post
For some reason his Plugin never worked for me ,
@credits were added
im not stealing any plugins dude its my THING
minimoney1 is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 12-24-2012 , 16:40   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #9

Quote:
Originally Posted by shavit View Post
I would use decl instead of new in OnGameFrame.
Also the string wouldn't be populated if the entity isn't valid.

Gotta love decl
ReFlexPoison is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-24-2012 , 16:52   Re: Team Fortress | is there way to detect each frame how many entity is on map
Reply With Quote #10

Decl is fine if you know how to work with it.
PHP Code:
decl String:str[999];

// Safe now
str[0] = '\0'
Yours sincerley
Impact
__________________

Last edited by Impact123; 12-24-2012 at 16:53.
Impact123 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:25.


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