AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player out of range (0) (https://forums.alliedmods.net/showthread.php?t=188306)

GhostMan 06-24-2012 19:33

Player out of range (0)
 
Quote:

L 06/23/2012 - 20:24:15: [FUN] Player out of range (0)
L 06/23/2012 - 20:24:15: [AMXX] Displaying debug trace (plugin "jb_days_lr.amxx")
L 06/23/2012 - 20:24:15: [AMXX] Run time error 10: native error (native "strip_user_weapons")
L 06/23/2012 - 20:24:15: [AMXX] [0] jb_days_lr.sma::fw_player_killed (line 368 )
PHP Code:

public fw_player_killed(victimattackershouldgib)
{
    new 
name[32]
    
get_user_name(attackername31)
            
    if(
duel_active)
    {
        if(
cs_get_user_team(victim) == CS_TEAM_CT && player_challenged[victim])
        {
            
m3_duel[attacker] = false
            deagle_duel
[attacker] = false
            ump_duel
[attacker] = false
            scout_duel
[attacker] = false
            once
[attacker] = false
            strip_user_weapons
(attacker)
            
give_item(attacker"weapon_knife")
            
set_user_rendering(attacker)
            
duel_menu(attacker)
        }
        else if(
cs_get_user_team(victim) == CS_TEAM_CT && !player_challenged[victim])
        {
            
set_task(0.4"kill_player"attacker)
            
set_hudmessage02550, -1.00.4025.08.00.00.010)
            
show_hudmessage(0"%L"LANG_PLAYER,"DUEL_DOWN"name)
                
        }
    }
    
remove_task(attacker)
    
remove_task(victim)


Line 368
PHP Code:

            strip_user_weapons(attacker


hornet 06-24-2012 19:39

Re: Player out of range (0)
 
When a player is killed by the map ( including by falling ) the attacker id is 0. So you need to run a check to ensure that the attacker is a player.

GhostMan 06-25-2012 06:54

Re: Player out of range (0)
 
And how do i do that? Just like that?

PHP Code:

public fw_player_killed(victimattackershouldgib)
{
    new 
name[32]
    
get_user_name(attackername31)
            
    if(
duel_active)
    {
        if(
cs_get_user_team(victim) == CS_TEAM_CT && player_challenged[victim])
        {
            
m3_duel[attacker] = false
            deagle_duel
[attacker] = false
            ump_duel
[attacker] = false
            scout_duel
[attacker] = false
            once
[attacker] = false

            
if(is_user_alive(attacker))
            {
                
strip_user_weapons(attacker)
                
give_item(attacker"weapon_knife")
                
set_user_rendering(attacker)
                
duel_menu(attacker)
            }

        }
        else if(
cs_get_user_team(victim) == CS_TEAM_CT && !player_challenged[victim])
        {
            
set_task(0.4"kill_player"attacker)
            
set_hudmessage02550, -1.00.4025.08.00.00.010)
            
show_hudmessage(0"%L"LANG_PLAYER,"DUEL_DOWN"name)
                
        }
    }
    
remove_task(attacker)
    
remove_task(victim)


Or is_user_alive not checks if its a player? :O

hornet 06-25-2012 08:06

Re: Player out of range (0)
 
You want to check straight away, so your not executing commands that aren't needed.

You can use this concept which is probably the best: !( 1 <= id <= g_iMaxPlayers )

In which case you add these pieces in:
Code:
new g_iMaxPlayers; public plugin_init() {     g_iMaxPlayers = get_maxplayers(); } public fw_player_killed(victim, attacker, shouldgib) {     if( !( 1 <= id <= g_iMaxPlayers ) )         return HAM_IGNORED;     //the rest of the code goes here     return HAM_IGNORED; }
Although, realistically, if your not going to have custom entities that will be inflicting damage to / killing the player, then all you need is this one check in place of the previous example ( without the global variable I added in ):
Code:
if( !attacker )     return HAM_IGNORED;

So if the attacker id is 0, the rest of your function will be ignored.

GhostMan 06-25-2012 10:21

Re: Player out of range (0)
 
PHP Code:

if( !( <= id <= g_iMaxPlayers ) ) 

you sure it has to be "id" not "attacker"?

hornet 06-25-2012 10:40

Re: Player out of range (0)
 
Sorry, your right.


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

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