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

Defining arrays with the maximum number of entities?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 08-08-2010 , 13:01   Defining arrays with the maximum number of entities?
Reply With Quote #1

Hey guys, i need to create or define a new array as we use to do with MAXPLAYERS+1 on global variables, but i couldn't find any static variable in the sourcemod API so i used GetMaxEntities() (Knowing it wasn't going to work) and i failed. The i 'supposed' that the maximum number o entities could be 1000 so i putted that and it worked. But thats really dirsty to check entities in a loop.

Is there anyway to declare something with the maximum entities in the game in the array? Like:

Code:
new bool:mybool[MAXPLAYERS+1]
But using the maximum number of entites. Is it possible?

Code:
new bool:mybool[GetMaxEntities()+1] (X) doesnt work

new bool:mybool[1000] (X) Works, but is dirty.
Any ideas? Thanks in advance!

Btw, i'm doing this on left 4 dead 2, so i f anyone know the actual maximum entities (average), let me know.
honorcode23 is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 08-08-2010 , 13:27   Re: Defining arrays with the maximum number of entities?
Reply With Quote #2

2048 i think is the max, you could put a check in OnPluginStart() to see if GetMaxEntities ever returns higher then 2048
PHP Code:
#define MAXENTITIES 2048
new bool:mybool[MAXENTITIES+1];
public 
OnPluginStart() {
     if (
MAXENTITIES GetMaxEntities())
         
SetFailState("Need to recompile with larger MAXENTITIES, current %d, suggested %d"MAXENTITIESGetMaxEntities());

dirka_dirka is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 08-08-2010 , 14:39   Re: Defining arrays with the maximum number of entities?
Reply With Quote #3

Thanks for the help, i think that could be done.
honorcode23 is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 09-06-2010 , 17:39   Re: Defining arrays with the maximum number of entities?
Reply With Quote #4

I'm having some errors with this. I've defined the max entities and appliead it on a few arrays. For Example:

Code:
new bool:g_bValidEntity[MAXENTITIES+1];
It is spawning an Array Out Of Bounds error when i set the bool to a new created entity.

Code:
[SM] Plugin encountered error 15: Array index is out of bounds
Is there anyway to fix this issue?
honorcode23 is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 09-06-2010 , 17:55   Re: Defining arrays with the maximum number of entities?
Reply With Quote #5

Shouldn't have deleted that fast...

If you're still getting out of bounds, and the script dirka gave you never returned that message, you're probably storing it wrong... somehow.

Please post the parts of your code dealing with storing it?
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 09-06-2010 , 18:02   Re: Defining arrays with the maximum number of entities?
Reply With Quote #6

why do u need an array that big? what are you storing? that is the question
__________________
War3:Source Developer
"Your CPU is just a bunch of Muxes"
DarkEnergy is offline
honorcode23
BANNED
Join Date: Mar 2010
Location: Chile
Old 09-06-2010 , 18:04   Re: Defining arrays with the maximum number of entities?
Reply With Quote #7

PHP Code:
#define MAXENTITIES 2048

new bool:g_bCanBeRemoved[MAXENTITIES+1] = false;

public 
Action:OnWeaponEquip(clientweapon)
{
    
g_bCanBeRemoved[weapon] = false;
}


public 
Action:OnWeaponDrop(clientweapon)
{
    if(
GetConVarBool(g_cvarWeaponManagerEnable))
    {
        
g_bCanBeRemoved[weapon] = true;
        
CreateTimer(GetConVarFloat(g_cvarWeaponManagerTimeout), WeaponExistenceTimeoutweapon);
    }
}

public 
Action:WeaponExistenceTimeout(Handle:timerany:weapon)
{
    
g_hWeaponTimeout[weapon] = INVALID_HANDLE;
    if(
weapon && IsValidEntity(weapon) && IsValidEdict(weapon) && g_bGameRunning && g_bCanBeRemoved[weapon] && deathmatch)
    {
        
decl String:class[64];
        
GetEdictClassname(weapon, class, sizeof(class));
        if(
StrEqual(class, "weapon_rifle")
        || 
StrEqual(class, "weapon_rifle_desert")
        || 
StrEqual(class, "weapon_rifle_ak47")
        || 
StrEqual(class, "weapon_sniper_military")
        || 
StrEqual(class, "weapon_shotgun_spas")
        || 
StrEqual(class, "weapon_shotgun_chrome")
        || 
StrEqual(class, "weapon_smg")
        || 
StrEqual(class, "weapon_pumpshotgun")
        || 
StrEqual(class, "weapon_first_aid_kit")
        || 
StrEqual(class, "weapon_chainsaw")
        || 
StrEqual(class, "weapon_adrenaline")
        || 
StrEqual(class, "weapon_autoshotgun")
        || 
StrEqual(class, "weapon_sniper_scout")
        || 
StrEqual(class, "weapon_molotov")
        || 
StrEqual(class, "weapon_upgradepack_incendiary")
        || 
StrEqual(class, "weapon_upgradepack_explosive")
        || 
StrEqual(class, "weapon_pain_pills")
        || 
StrEqual(class, "weapon_pipe_bomb")
        || 
StrEqual(class, "weapon_vomitjar")
        || 
StrEqual(class, "weapon_smg_silenced")
        || 
StrEqual(class, "weapon_smg_mp5")
        || 
StrEqual(class, "weapon_sniper_awp")
        || 
StrEqual(class, "weapon_sniper_scout")
        || 
StrEqual(class, "weapon_rifle_sg552")
        || 
StrEqual(class, "weapon_gnome")
        || 
StrEqual(class, "weapon_pistol_magnum")
        || 
StrEqual(class, "weapon_hunting_rifle")
        || 
StrEqual(class, "weapon_pistol"))
        {
            
AcceptEntityInput(weapon"Kill");
            
#if DEBUG
            
PrintToServer("[WEAPON MANAGER] Weapon %s( ID: %i) timed out and got removed", class, weapon);
            
PrintToServer("[ENTITY MANAGER] The current entity count is: %i/%i"GetValidEntityCount(), GetMaxEntities());
            
#endif
            
return;
        }
    }
    
#if DEBUG
    
WriteFileLine(logfile,"[WEAPON MANAGER] A weapon was on deleting queue, but it was either invalid or in usage");
    
PrintToServer("[WEAPON MANAGER] A weapon was on deleting queue, but it was either invalid or in usage");
    
#endif

public OnEntityCreated(entity, const String:class[])
{
    
g_bCanBeRemoved[entity] = false;
    
#if DMDEBUG
    
new iCurrentEntities GetValidEntityCount();
    new 
iMaxEntities GetMaxEntities();
    
LogMessage("Current entity count %i/%i"iCurrentEntitiesiMaxEntities);
    
#endif
    
if(StrEqual(class, "upgrade_ammo_explosive") || StrEqual(class, "upgrade_ammo_incendiary"))
    {
        if(
IsValidEntity(entity) && IsValidEdict(entity))
        {
            
SetEntData(entityg_UpgradePackCanUseCountO501,true);
        }
    }
}

I use the SDKHOOK extension and i get the error every time i switch it between true or false. Any ideas?
honorcode23 is offline
dirka_dirka
Veteran Member
Join Date: Nov 2009
Old 09-06-2010 , 22:08   Re: Defining arrays with the maximum number of entities?
Reply With Quote #8

are you using that check in onpluginstart?

if so and it doesnt print.. what does:
Quote:
LogMessage("Current entity count %i/%i", iCurrentEntities, iMaxEntities);
give you?

and have you TRIED a print/log msg for when you toggle the cvars to see what entity number it is trying to adjust? maybe your sending in a bogus number
dirka_dirka is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 09-07-2010 , 07:41   Re: Defining arrays with the maximum number of entities?
Reply With Quote #9

I suggest using adt_array.
FaTony is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 09-08-2010 , 05:40   Re: Defining arrays with the maximum number of entities?
Reply With Quote #10

Try using EntRefToEntIndex first, it could be an entity reference.
__________________
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
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 10:21.


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