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

tf_objective_resource entity index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-23-2015 , 11:21   tf_objective_resource entity index
Reply With Quote #1

So I have this code that is ran every so often in a plugin:

PHP Code:
stock void UpdateWaveNumbers(bool update)
{
    while( ( 
iEnt FindEntityByClassname(iEnt"tf_objective_resource") ) != -)
    {
        
CurrentWaveTemp GetEntProp(iEntProp_Send"m_nMannVsMachineWaveCount");
        
TotalWavesTemp GetEntProp(iEntProp_Send"m_nMannVsMachineMaxWaveCount");
        
GetEntPropString(iEntProp_Send"m_iszMvMPopfileName"PopFilePathsizeof(PopFilePath));        
        break;
    }

However, is it possible to do:

PHP Code:
public void OnMapStart()
{
    
ObjectiveEntity FindEntityByClassname(-1"tf_objective_resource");

So that I can ditch the while loop and do:

PHP Code:
stock void UpdateWaveNumbers(bool update)
{
    
CurrentWaveTemp GetEntProp(ObjectiveEntityProp_Send"m_nMannVsMachineWaveCount");
    
TotalWavesTemp GetEntProp(ObjectiveEntityProp_Send"m_nMannVsMachineMaxWaveCount");
    
GetEntPropString(ObjectiveEntityProp_Send"m_iszMvMPopfileName"PopFilePathsizeof(PopFilePath));        

In other words, from the map startup, is it possible for the tf_objective_resource entity index to change within a map? (Or possibly when the mvm mission is changed or wave is failed?)

Thanks!
Potato Uno is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 08-23-2015 , 17:24   Re: tf_objective_resource entity index
Reply With Quote #2

I doubt it'll change during map time.

However, all entities are reset on round start, so I'd move the 'FindEntityByClassname' to a round_start event just to be sure.
__________________

SoulSharD is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-23-2015 , 18:17   Re: tf_objective_resource entity index
Reply With Quote #3

A few things:
  1. As far as I'm aware, there's only going to be one tf_objective_resource entity at a time.
  2. If you're concerned with the entity changing, you can store an entity reference instead by using EntIndexToEntRef. To check if a reference is still valid, use EntRefToEntIndex and see if it returns INVALID_ENT_REFERENCE.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 08-23-2015 at 18:18.
Powerlord is offline
Mehis
Senior Member
Join Date: Mar 2013
Location: basement
Old 08-24-2015 , 04:04   Re: tf_objective_resource entity index
Reply With Quote #4

It shouldn't change. Not all entities are reset each round start. E.g, CSS ents
Mehis is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-26-2015 , 19:18   Re: tf_objective_resource entity index
Reply With Quote #5

In MvM a mapper told me that the map effectively resets if players fail a wave, and after doing some further inspection it looks like I was at the verge of falling into a premature optimization trap (messier code for a very negligible speed boost). So I decided to say "screw it" and not bother caching the entity index.

However this was useful:

Quote:
Originally Posted by Powerlord View Post
A few things:
  1. As far as I'm aware, there's only going to be one tf_objective_resource entity at a time.
At least now I can do:

PHP Code:
stock void UpdateWaveNumbers(bool update

    
int ObjectiveEntity FindEntityByClassname(-1"tf_objective_resource");
    
CurrentWaveTemp GetEntProp(ObjectiveEntityProp_Send"m_nMannVsMachineWaveCount"); 
    
TotalWavesTemp GetEntProp(ObjectiveEntityProp_Send"m_nMannVsMachineMaxWaveCount"); 
    
GetEntPropString(ObjectiveEntityProp_Send"m_iszMvMPopfileName"PopFilePathsizeof(PopFilePath));         

instead of a while loop, which now results in neater code. Thanks Ross!

Last edited by Potato Uno; 08-26-2015 at 19:19.
Potato Uno is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-27-2015 , 11:07   Re: tf_objective_resource entity index
Reply With Quote #6

And complet what said powerlord, every entities related with the logic can be found in a map only one time if it's not a makers error, or halloween minigames, or payload hud
__________________

Last edited by Benoist3012; 08-27-2015 at 11:10.
Benoist3012 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 02:35.


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