AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" ) (https://forums.alliedmods.net/showthread.php?t=134364)

GXLZPGX 08-03-2010 19:21

Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
Alright what could possibly be the problem? I wouldn't like to show any code, so if you could possibly just list some possibilities it would be greatly appreciated.

ConnorMcLeod 08-03-2010 19:24

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
id < 1, id > get_maxplayers, player not connected.
Dunno what happend with HLTVs.

Anyway, put your plugin in debug mode to get detailed errors.


The following checks are made when you use that native :
Code:

#define CHECK_PLAYER(x) \
        if (x < 1 || x > gpGlobals->maxClients) { \
                MF_LogError(amx, AMX_ERR_NATIVE, "Player out of range (%d)", x); \
                return 0; \
        } else { \
                if (!MF_IsPlayerIngame(x) || FNullEnt(MF_GetPlayerEdict(x))) { \
                        MF_LogError(amx, AMX_ERR_NATIVE, "Invalid player %d", x); \
                        return 0; \
                } \
        }


GXLZPGX 08-03-2010 19:27

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
L 08/04/2010 - 07:28:08: [AMXX] [0] vcjb.sma::cmdCheck (line 72)

The block of code that line 72 is located:

PHP Code:

public cmdCheck(id)
{
    if( !
is_user_alive(id) )
        return 
PLUGIN_HANDLED;
    
    if( 
cs_get_user_team(id) != CS_TEAM_T )
        return 
PLUGIN_HANDLED;
    
    if( 
gLastRequest == true )
        return 
PLUGIN_HANDLED;
    
    new 
iPlayers[32] = 0;
    new 
iNum;
    new 
id;
    
get_playersiPlayersiNum"a" )
    
    for( new 
0gMaxClientsi++ )
    {
        
id iPlayers[i]
        
        if( !
is_user_alive(id) )
            continue;
        
        switch( 
cs_get_user_team(id) )
        {
            case 
CS_TEAM_T:
            {
                
Prisoners++
            }
            case 
CS_TEAM_CT:
            {
                
Guards++
            }
        }
    }
    
    if( 
cs_get_user_team(id) == CS_TEAM_CT )
    {
        
client_print_coloridBlue"^4[Jailbreak] ^1You aren't a prisoner^4." )
    }
    
    if( 
Prisoners )
    {
        
client_print_coloridBlue"^4[Jailbreak] ^1There are too many terrorists alive^4!" )
    } else {
        
cmdLastRequestid )
    }
    
    return 
PLUGIN_HANDLED;



wrecked_ 08-03-2010 19:40

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
Code:
for( new i = 0; i < iNum; i++ )

EDIT: You should really code more optimistically than pessimistically. What I mean by that is that you return after every if() to avoid faulty conditions, but you should just execute the following code when you check the inverted situation for the current if() condition.

That's kind of hard to explain, so here's an example:
Code:
if( is_user_alive( id ) )     return; // code
:arrow:
Code:
if( !is_user_alive( id ) ) {     // code }

GXLZPGX 08-03-2010 19:48

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
Quote:

Originally Posted by wrecked_ (Post 1260934)
Code:
for( new i = 0; i < iNum; i++ )

EDIT: You should really code more optimistically than pessimistically. What I mean by that is that you return after every if() to avoid faulty conditions, but you should just execute the following code when you check the inverted situation for the current if() condition.

That's kind of hard to explain, so here's an example:
Code:
if( is_user_alive( id ) )     return; // code
:arrow:
Code:
if( !is_user_alive( id ) ) {     // code }

Thats how I used to code if statements. I have no idea why I changed.

wrecked_ 08-03-2010 19:54

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
Quote:

Originally Posted by GXLZPGX (Post 1260944)
Thats how I used to code if statements. I have no idea why I changed.

I also recommend using the && (and) operator in your if() statements. You have 3 if()'s checking a different thing but returning the same value if each one is executed.

Kreation 08-03-2010 20:33

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
You also check if( !is_user_alive( id ) ) twice, once at the top and then again in the loop.

wrecked_ 08-03-2010 21:16

Re: Run time error 10 (plugin "vcjb.amxx") (native "cs_get_user_team" )
 
Quote:

Originally Posted by Kreation (Post 1261020)
You also check if( !is_user_alive( id ) ) twice, once at the top and then again in the loop.

He had 2 variables named id. We fixed that via PM.


All times are GMT -4. The time now is 00:06.

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