AlliedModders

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

davidto1995 03-02-2021 08:39

Player out of range
 
Code:

new const SHOWHUD_ID = 200;

public client_connect(id)
{
        get_user_name(id, gPlayerName[id], charsmax(gPlayerName[]));
        set_task(0.5, "ShowHUD", id+SHOWHUD_ID, _, _, "b");
}

public ShowHUD(taskid) //call after client connect
{

        new id = taskid - SHOWHUD_ID;

        if(cs_get_user_team(id) != CS_TEAM_UNASSIGNED)
        {

                if(!is_user_alive(id))
                        id = pev(id, pev_iuser2);


                if(cs_get_user_team(id) == CS_TEAM_CT)
                {
                        if(equal(gPlayerType[id], "Leader"))
                                set_hudmessage(255, 255, 255, 0.7, 0.7, 0, 0.1, 1.0, 0.1, 0.1, 1);
                        if(equal(gPlayerType[id], "Supporter"))
                                set_hudmessage(0, 204, 255, 0.7, 0.7, 0, 0.1, 1.0, 0.1, 0.1, 1);
                        else
                                set_hudmessage(0, 255, 0, 0.7, 0.7, 0, 0.1, 1.0, 0.1, 0.1, 1);
                }
                if(cs_get_user_team(id) == CS_TEAM_T)
                {
                        if(equal(gPlayerType[id], "G-Virus Monster"))
                                set_hudmessage(153, 0, 204, 0.7, 0.7, 0, 0.1, 1.0, 0.1, 0.1, 1);
                        else
                                set_hudmessage(255, 0, 0, 0.7, 0.7, 0, 0.1, 1.0, 0.1, 0.1, 1);
                }

                ShowSyncHudMsg(id, gMsgSyncObj, "帳號: %s | 生命: %i | 血清量: %i | 等級: %i^n經驗值: %i/%i | 金幣: %i | 種族: %s | ID: %i", gPlayerName[id], get_user_health(id), get_user_armor(id), gPlayerLevel[id], gPlayerExp[id], gPlayerNextLevel[id], gPlayerPoints[id], gPlayerType[id], id);
        }
}

Keep having errors as below:
L 03/02/2021 - 21:38:22: [AMXX] [0] zm.sma::ShowHUD (line 1127)
L 03/02/2021 - 21:38:23: [CSTRIKE] Invalid player 12
L 03/02/2021 - 21:38:23: [AMXX] Displaying debug trace (plugin "zm.amxx")
L 03/02/2021 - 21:38:23: [AMXX] Run time error 10: native error (native "cs_get_user_team")

I have this error once I connect to the server. Which part has gone wrong? Thank you!

OciXCrom 03-02-2021 08:50

Re: Player out of range
 
Check if the user is connected before getting his team.
You shouldn't be using "client_connect" because the user isn't connected yet. Use "client_putinserver".

davidto1995 03-02-2021 09:18

Re: Player out of range
 
Quote:

Originally Posted by OciXCrom (Post 2738927)
Check if the user is connected before getting his team.
You shouldn't be using "client_connect" because the user isn't connected yet. Use "client_putinserver".

Thank you so much. The problem is solved.


All times are GMT -4. The time now is 11:52.

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