AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Index out of bounds in de_dust2 (https://forums.alliedmods.net/showthread.php?t=154166)

kotinha 04-03-2011 16:34

Index out of bounds in de_dust2
 
Hi, I'm creating a plugin (based in this tutorial How To: Make a perfect NPC) and it works fine except in de_dust2 that gives me this error:
Code:

L 04/03/2011 - 20:49:45: [AMXX] Displaying debug trace (plugin "domination.amxx")
L 04/03/2011 - 20:49:45: [AMXX] Run time error 4: index out of bounds
L 04/03/2011 - 20:49:45: [AMXX]    [0] domination.sma::dbase_think (line 71)

What the hell?!
It didn't give me any errors in the other maps that I tryed (de_nuke and aim_aztec_s)

Exolent[jNr] 04-03-2011 16:35

Re: Index out of bounds in de_dust2
 
Show your plugin.

kotinha 04-03-2011 18:07

Re: Index out of bounds in de_dust2
 
1 Attachment(s)
Here it is...

fysiks 04-03-2011 19:16

Re: Index out of bounds in de_dust2
 
What are the values of "id" in dbase_think(id)? If you don't know then find out.

I don't really know anything abotu NPCs but from an inconsistency I can see that it is more than likely bool:Dominator[33] being declared too small. The other two arrays on that line are bigger.

kotinha 04-03-2011 19:28

Re: Index out of bounds in de_dust2
 
The value of "id" is the index of the base that is thinking (or at least I think so).
And the bool:Dominator[33] is for players while the other arrays are for the bases (max bases 99...)

Exolent[jNr] 04-03-2011 20:04

Re: Index out of bounds in de_dust2
 
Don't use arrays to hold values for entities.
You should instead use place holders like EV_INT_iuser1 to EV_INT_iuser4

Mini_Midget 04-03-2011 20:40

Re: Index out of bounds in de_dust2
 
Are there more than 1 of your ents in de_dust2?
If so then you'll need to make a ent count to keep track of the ent's indices/indexes.

As Exolent mentioned above. Best to use place holders to keep track.

If I remember correctly... You can set and check an ent to a specific team with pev_team.

Anyway, just fixed a few minor things.

PHP Code:


new gMaxPlayers

public plugin_init()
{
    
//....
    
gMaxPlayers get_maxplayers();
}

//Note that I'm using iEnt as the index name for the entity and not id. Just makes things easier
public dbase_think(iEnt)
{
    if(!
is_valid_ent(iEnt))
        return;
        
    
//Should use get_maxplayers() instead and have it as a global variable
    
for(new id id <= gMaxPlayers id++)
    {
        
//I'm sure you would want to check for only alive players to 'dominate' your ent
        
if(is_user_alive(id))
        {
            
//entity_range returns a float. (You can use get_entity_distance which is exactly the same except it returns an int instead)
            
if(entity_range(iEntid)  < 200.0)
            {
                
//..... 


fysiks 04-03-2011 21:01

Re: Index out of bounds in de_dust2
 
Quote:

Originally Posted by kotinha (Post 1444083)
And the bool:Dominator[33] is for players while the other arrays are for the bases (max bases 99...)

Your code does not use it that way. You use all three arrays indexed with the same "id".


All times are GMT -4. The time now is 14:37.

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