AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Error on cs_get_user_team (https://forums.alliedmods.net/showthread.php?t=183252)

iBrazilian 04-19-2012 16:35

Error on cs_get_user_team
 
A little help please, I've marked line 78 with // LINE 78 ... Can't really think of anything up to this point..
PHP Code:

L 04/19/2012 15:00:41: [CSTRIKEInvalid player 10
L 04
/19/2012 15:00:41: [AMXXDisplaying debug trace (plugin "objectives.amxx")
L 04/19/2012 15:00:41: [AMXXRun time error 10native error (native "cs_get_user_team")
L 04/19/2012 15:00:41: [AMXX]    [0objectives.sma::bomb_explode (line 78

PHP Code:

public bomb_explode(planter,defuser)
    {
    if ( !
pluginactive || playercount minplayers ) return;
    
    new 
explode_bonus get_pcvar_num(PCVarDefusalMap);
    new 
iPlayers[32], iPlayeriNumplantteam _:cs_get_user_team(planter);
    
    
get_players(iPlayersiNum"ah");
    for( new 
iiNumi++ )
        {
        
iPlayer iPlayers[i];
        if ( 
_:cs_get_user_team(iPlayer) == plantteam // LINE 78
            
{
            
Poke_Give_XP(planter, -1explode_bonus)
            
set_hudmessage(127255420.600.1506.05.0)
            
show_hudmessage(planter"You recieved %d xp for exploding the bomb!"explode_bonus)            
        }
    }



kramesa 04-19-2012 16:38

Re: Error on cs_get_user_team
 
You need check is_user_connected.

Bugsy 04-19-2012 16:38

Re: Error on cs_get_user_team
 
Usage looks correct, probably a bug with get_players(). Try not using flags and manually check for alive\hltv and see if it still occurs.

Quote:

Originally Posted by kramesa (Post 1692536)
You need check is_user_connected.

get_players() will only return connected players (when functioning properly)

iBrazilian 04-19-2012 17:14

Re: Error on cs_get_user_team
 
I've never used get_players before, gotta do some homework then:/ Thank you.

Bugsy 04-19-2012 19:22

Re: Error on cs_get_user_team
 
Just noticed something, which cs_get_user_team() is the error occurring on?

If it's the below then what is probably happening is the planter disconnects before the bomb explodes:
PHP Code:

plantteam _:cs_get_user_team(planter); 

So, add is_user_connected( planter ) condition before checking team OR record the planting team when the bomb is first planted.

kramesa 04-19-2012 19:52

Re: Error on cs_get_user_team
 
Try this

Code:
if ( is_user_connected(id) && _:cs_get_user_team(iPlayer) == plantteam )

rak 04-19-2012 19:57

Re: Error on cs_get_user_team
 
PHP Code:

public bomb_explode(planter,defuser)
{
    if ( !
pluginactive || playercount minplayers ) return;
    
    new 
explode_bonus get_pcvar_num(PCVarDefusalMap);
    new 
iPlayers[32], iPlayeriNumplantteam _:cs_get_user_team(planter);
    
    
get_players(iPlayersiNum);
    for( new 
iiNumi++ )
    {
        
iPlayer iPlayers[i];
        if (
is_user_alive(iPlayer) && _:cs_get_user_team(iPlayer) == plantteam)
        {
            
Poke_Give_XP(planter, -1explode_bonus)
            
set_hudmessage(127255420.600.1506.05.0)
            
show_hudmessage(planter"You recieved %d xp for exploding the bomb!"explode_bonus)            
        }
    }


thanks kramesa; my mistake xD

kramesa 04-19-2012 20:01

Re: Error on cs_get_user_team
 
Quote:

Originally Posted by rak (Post 1692629)
PHP Code:

public bomb_explode(planter,defuser)
{
    if ( !
pluginactive || playercount minplayers ) return;
    
    new 
explode_bonus get_pcvar_num(PCVarDefusalMap);
    new 
iPlayers[32], iPlayeriNumplantteam _:cs_get_user_team(planter);
    
    
get_players(iPlayersiNum);
    for( new 
iiNumi++ )
    {
        
iPlayer iPlayers[i];
        if ( 
_:cs_get_user_team(iPlayer) == plantteam && is_user_alive(iPlayer))
        {
            
Poke_Give_XP(planter, -1explode_bonus)
            
set_hudmessage(127255420.600.1506.05.0)
            
show_hudmessage(planter"You recieved %d xp for exploding the bomb!"explode_bonus)            
        }
    }



You need check is_user_connected() before cs_get_user_team().

Bugsy 04-19-2012 23:21

Re: Error on cs_get_user_team
 
Did either of you read my post? I doubt the error is happening on that native call, I think it's the one checking planter ream. And iBrazilian, use the CsTeams tag instead of detagging the function return.

With your code, the XP will only be awarded if the planter remains connected to the server when the bomb explodes (which is dumb), use this:
PHP Code:

new CsTeams:g_PlantTeam;

public 
bomb_plantedplanter 
{
    
g_PlantTeam cs_get_user_teamplanter );
}

public 
bomb_explodeplanter defuser )
{
    if ( !
pluginactive || playercount minplayers 
        return;
    
    new 
explode_bonus get_pcvar_num(PCVarDefusalMap);
    new 
iPlayers[32], iPlayeriNum;
    
    
get_players(iPlayersiNum "a" );

    for( new 
iNum i++ )
    {
        
iPlayer iPlayers];
        
        if ( 
cs_get_user_teamiPlayer ) == g_PlantTeam )
        {
            
Poke_Give_XP(planter, -1explode_bonus)
            
set_hudmessage(127255420.600.1506.05.0)
            
show_hudmessage(planter"You recieved %d xp for exploding the bomb!"explode_bonus)            
        }
    }



ConnorMcLeod 04-20-2012 00:48

Re: Error on cs_get_user_team
 
Can CTs plant the bomb ??

Bugsy, you have fotgotten flag "a".
Also, i think that in Poke_Give_XP(planter, -1, explode_bonus), planter should be replaced with iPlayer :)


All times are GMT -4. The time now is 07:44.

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