AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Invalid player (https://forums.alliedmods.net/showthread.php?t=121611)

drekes 03-17-2010 16:32

Invalid player
 
Hi,

I have a problem with a plugin, it always gives errors about invalid players.
I check max players and is_user_connected(id) and is_user_alive(id) but still i get errors.

Could someone take a look at this and learn me how to fix these errors.
(I'm not really experienced at using stocks, maybe i use it the wrong way)

The error
Code:

L 03/17/2010 - 16:20:11: Start of error session.
L 03/17/2010 - 16:20:11: Info (map "jail_sanctuary") (file "addons/amxmodx/logs/error_20100317.log")
L 03/17/2010 - 16:20:11: [CSTRIKE] Invalid player 2
L 03/17/2010 - 16:20:12: [AMXX] Displaying debug trace (plugin "jailbreak_main.amxx")
L 03/17/2010 - 16:20:12: [AMXX] Run time error 10: native error (native "cs_get_user_team")
L 03/17/2010 - 16:20:12: [AMXX]    [0] handgunmenu.inl::gun_spawn (line 12)
L 03/17/2010 - 16:20:12: [AMXX]    [1] jailbreak_main.sma::PlayerSpawn (line 100)
L 03/17/2010 - 16:25:48: [CSTRIKE] Player out of range (0)
L 03/17/2010 - 16:25:48: [AMXX] Displaying debug trace (plugin "jailbreak_main.amxx")
L 03/17/2010 - 16:25:48: [AMXX] Run time error 10: native error (native "cs_get_user_team")
L 03/17/2010 - 16:25:48: [AMXX]    [0] jail_addons.inl::rebeldeath (line 54)

And there is a lot more where that came from.

The plugin:
handgunmenu part
PHP Code:

public gun_spawn(id)
{
    new 
players[32], pnum
    get_players
(playerspnum"a");
    for( new 
ii<pnumi++ )
    {
        
check_user(id)
        if(
cs_get_user_team(id) == CS_TEAM_CT)
        {
            
handgun_menu(id)
        }
        
got_gun[id] = false
    
}
    return 
PLUGIN_HANDLED


PlayerSpawn(id) part:
PHP Code:

public PlayerSpawn(id)

    for( new 
1<= g_iMaxPlayers i++ )
    {
        
check_user(id)
        if(
is_user_alive(id))
        {
            
set_user_rendering(idkRenderFxGlowShell000kRenderNormal20)
            
strip_weapons(id)
        }
    }
    
    if(
gravityday)
    {
        
check_user(id)
        if(
is_user_alive(id)
        ||(
cs_get_user_team(id) == CS_TEAM_T))
        {
            
set_user_gravity(id1.0)
        }
    }
    
check_lr(id)
    
gun_spawn(id)
    
is_user_wanted[id] = false
    
return PLUGIN_HANDLED


jail_addons part:
PHP Code:

public rebeldeath()
{
    new 
attacker read_data(1)
    new 
victim read_data(2)
    new 
headshot read_data(3)
    
    new 
AttackerName[32]
    new 
VictimName[32]

    
check_user(attacker)
    
check_user(victim)
    
    if( 
cs_get_user_team(attacker) == CS_TEAM_CT && cs_get_user_team(victim) == CS_TEAM_T)
    {
        if(
is_user_wanted[victim])
        {
            
get_user_name(attackerAttackerName31)
            
get_user_name(victimVictimName,31)
    
            
client_print(0print_chat"Guard %s killed wanted prisoner %s!"AttackerNameVictimName)
        }
        
        else if(!
is_user_wanted[victim])
        {
            
get_user_name(attackerAttackerName31)
            
get_user_name(victimVictimName,31)
    
            
client_print(0print_chat"Guard %s killed unwanted prisoner %s!"AttackerNameVictimName)
        }
    }
    
    if( 
cs_get_user_team(attacker) == CS_TEAM_T && cs_get_user_team(victim) == CS_TEAM_CT)
    {
        
playerpoints[attacker] += get_pcvar_num(cvar_killpoints)
        
        if(
headshot)
            
playerpoints[attacker] += get_pcvar_num(cvar_headshotpoints);
        
    }
    
//SaveData(attacker)


And the stock: check_user(id):
PHP Code:

stock check_user(index)
{
    if(!
is_user_connected(index)
    ||(
is_user_bot(index)))
    {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE


I hope you guys can show me how it works, so i can fix my plugin.
Thanks in advance

wrecked_ 03-17-2010 16:36

Re: Invalid player
 
Quote:

Originally Posted by drekes (Post 1120723)
stuff

In the .inl you're checking the team of the original passed index, rather than the player in the for loop.

drekes 03-17-2010 16:41

Re: Invalid player
 
I don't understand what you mean, could you make an example of my mistake and a solution, so i can see my mistake?

wrecked_ 03-17-2010 17:00

Re: Invalid player
 
Quote:

Originally Posted by drekes (Post 1120734)
I don't understand what you mean, could you make an example of my mistake and a solution, so i can see my mistake?

PHP Code:

new players[32], pnum
    get_players
(playerspnum"a");
    for( new 
ii<pnumi++ )
    {
        
check_user(id)
        if(
cs_get_user_team(id) == CS_TEAM_CT)
        {
            
handgun_menu(id)
        }
        
got_gun[id] = false
    


:arrow:
Code:
new players[32], pnum, tempid     get_players(players, pnum, "a");     for( new i; i<pnum; i++ )     {         tempid = players[i]         check_user(tempid)         if(cs_get_user_team(tempid) == CS_TEAM_CT)         {             handgun_menu(tempid)         }         got_gun[tempid] = false     }

drekes 03-17-2010 17:01

Re: Invalid player
 
ow, i think i get it.

so i need to keep the id of the player, and then check his team and such.

And instead of tempid, can i use id?

wrecked_ 03-17-2010 17:02

Re: Invalid player
 
Quote:

Originally Posted by drekes (Post 1120761)
ow, i think i get it.

so i need to keep the id of the player, and then check his team and such.

The way you were doing it, it was checking the team of one player x amount of times.

This one checks each player individually.

drekes 03-17-2010 17:04

Re: Invalid player
 
can i use id instead of tempid, or does this bug the plugin?

wrecked_ 03-17-2010 17:10

Re: Invalid player
 
Quote:

Originally Posted by drekes (Post 1120765)
can i use id instead of tempid, or does this bug the plugin?

You'd need to rename the index passed in the function.

drekes 03-17-2010 17:12

Re: Invalid player
 
ok, thanks wrecked_, for all the times you helped me out.

drekes 03-17-2010 17:15

Re: Invalid player
 
and do i rename the index of another function to?
like so
PHP Code:

public handgun_menu(tempid)
{
    
check_user(tempid)
    {
    
        new 
handgunmenu menu_create("\yChoose your handgun:""sub_handgun_menu")

        
menu_additem(handgunmenu"\wUsp""1"0);
        
menu_additem(handgunmenu"\wGlock""2"0);
        
menu_additem(handgunmenu"\wDual Elites""3"0);
        
menu_additem(handgunmenu"\wDeagle""4"0)
        
        
menu_setprop(handgunmenuMPROP_EXITMEXIT_ALL);
        
menu_display(idhandgunmenu0);
    }
    return 
PLUGIN_HANDLED


or like this, without renaming that
PHP Code:

public handgun_menu(id)
{
    
check_user(id)
    {
    
        new 
handgunmenu menu_create("\yChoose your handgun:""sub_handgun_menu")

        
menu_additem(handgunmenu"\wUsp""1"0);
        
menu_additem(handgunmenu"\wGlock""2"0);
        
menu_additem(handgunmenu"\wDual Elites""3"0);
        
menu_additem(handgunmenu"\wDeagle""4"0)
        
        
menu_setprop(handgunmenuMPROP_EXITMEXIT_ALL);
        
menu_display(idhandgunmenu0);
    }
    return 
PLUGIN_HANDLED


and how do i use it in a death event?
like this
PHP Code:

public PlayerDeath()
{
    new 
attacker read_data(1)
    new 
victim read_data(2)

    if( 
cs_get_user_team(attacker) == CS_TEAM_T && cs_get_user_team(victim) == CS_TEAM_CT)
    {
        
lr_started false
    
}
    if(
spray_on)
    {
        
server_cmd("decalfrequency 20")
        
spray_on false
    
}




All times are GMT -4. The time now is 08:48.

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