AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way (https://forums.alliedmods.net/showthread.php?t=308763)

ZEDD_Intensity 07-02-2018 18:41

native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
 
Greetings,

Hope everybody is having a great time here.

Had to post this after a lot of searching and fixing didn't help.

Error :
PHP Code:

L 07/01/2018 22:26:11Start of error session.
L 07/01/2018 22:26:11Info (map "css_dust2") (file "addons/amxmodx/logs/error_20180701.log")
L 07/01/2018 22:26:11: [CSTRIKEInvalid player 3
L 07
/01/2018 22:26:11: [AMXXDisplaying debug trace (plugin "x_216.amxx"version "2.16")
L 07/01/2018 22:26:11: [AMXXRun time error 10native error (native "cs_get_user_team")
L 07/01/2018 22:26:11: [AMXX]    [0x_216.sma::HandleSay (line 517

Code extracts :
PHP Code:

public HandleSay(id)
{
    new 
Message[192], None[2][32], Chat[192], Alive[16];
    
    
read_args(Message191);
    
remove_quotes(Message);

    
formatex(None[0], 31"");
    
formatex(None[1], 31" ");
    
    if(
Message[0] == '@' || Message[0] == '!' || equal (Message""))
        return 
PLUGIN_HANDLED;
    
    if(!
is_user_alive(id))
        
Alive "*DEAD* ";
    else
        
Alive "";
        
    if(!
equali(MessageNone[0]) && !equali(MessageNone[1]))
    {
        if(
Logined[id])
        {
            
formatex(Chat191"^1%s^4[%s] ^3%s^1 : %s"AliveRanks[CurrentRank[id]], Name[id], Message);
        }
        else
        {
            
formatex(Chat191"^1%s^4[Unranked] ^3%s^1 : %s"AliveName[id], Message);
        }
        
//////// Line 517 Below ////////
        
switch(cs_get_user_team(id)) // Line 517 Here
        //////// Line 517 Above ///////
        
{
            case 
CS_TEAM_TColorChat(0REDChat);
            case 
CS_TEAM_CTColorChat(0BLUEChat);
            case 
CS_TEAM_SPECTATORColorChat(0GREYChat);
        }
        
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_HANDLED;


Tried adding a check : Failed.
PHP Code:

    if(!is_user_connected(id))
    { 

Checking is_user_alive didn't make sense to me, and still for the 'sake of science', I tried it and it made the code wildly malfunction and blocked chat messages, as expected.

I'd love to get a fixed code and also learn how to fix these type of errors, especially with SayHandlers.

Lemme know if you need any additional information.
Kind Regards,
ZEDD

OciXCrom 07-02-2018 18:51

Re: native "cs_get_user_team" - The complicated way
 
Checking if the user is connected before getting his team should without any doubt prevent that error. Every time you see an "invalid player X" error, it means that the user is not connected. Add the check in the beginning of the function and stop the code from going any further if it returns false.

ZEDD_Intensity 07-02-2018 20:05

Re: native "cs_get_user_team" - The complicated way
 
Quote:

Originally Posted by OciXCrom (Post 2600646)
Checking if the user is connected before getting his team should without any doubt prevent that error. Every time you see an "invalid player X" error, it means that the user is not connected. Add the check in the beginning of the function and stop the code from going any further if it returns false.

Hi,

Thanks OciXCrom, definitely something to keep in mind for my future projects as well. Really appreciate the help, simple but significantly differential.

If errors do me any more negative, I'll update this thread.

Warm Regards,
ZEDD

CrAzY MaN 07-03-2018 00:12

Re: native "cs_get_user_team" - The complicated way
 
Code:
if(!is_user_connected(id))      return PLUGIN_HANDLED; new CsTeams:team = cs_get_user_team(id) switch(team) {      //CODE }

Maybe this will help you.

ZEDD_Intensity 07-03-2018 01:58

Re: native "cs_get_user_team" - The complicated way
 
Quote:

Originally Posted by CrAzY MaN (Post 2600674)
Code:
if(!is_user_connected(id))      return PLUGIN_HANDLED; new CsTeams:team = cs_get_user_team(id) switch(team) {      //CODE }

Maybe this will help you.

Hey,

Already fixed it myself, but this will definitely be an option if mine fails at all. Thanks mate!

Warmest Regards,
ZEDD

ZEDD_Intensity 07-03-2018 14:58

Re: native "cs_get_user_team" - The complicated way
 
Greetings,

Ran into another error, a different one :
PHP Code:

 L 07/03/2018 19:09:01Start of error session.
L 07/03/2018 19:09:01Info (map "css_mirage") (file "addons/amxmodx/logs/error_20180703.log")
L 07/03/2018 19:09:01: [CSTRIKENon-player entity 0 out of range
L 07
/03/2018 19:09:01: [AMXXDisplaying debug trace (plugin "x_216.amxx"version "2.16")
L 07/03/2018 19:09:01: [AMXXRun time error 10native error (native "cs_get_weapon_silen")
L 07/03/2018 19:09:01: [AMXX]    [0x_216.sma::SkinCheck (line 932

@
PHP Code:

public SkinCheck(id)
{
    if(!
is_user_connected(id) && !is_user_alive(id))
        return 
PLUGIN_HANDLED;
    
    new 
SilWPName[32];
    
formatex(WPNamecharsmax(WPName), DefaultModels[get_user_weapon(id)][1]);
    new 
WPN find_ent_by_owner(-1DefaultModels[get_user_weapon(id)][1], id);
    
    if(
get_user_weapon(id) == CSW_M4A1 || get_user_weapon(id) == CSW_USP)
        
Sil cs_get_weapon_silen(WPN);
        
    if(
get_user_weapon(id) == CSW_AWP)
        
cs_set_user_zoom(id00);
    
    
PlayAnimation(idAnimationIDs[get_user_weapon(id)][Sil]);

    return 
PLUGIN_HANDLED;


Thanks in advance.

Regards,
ZEDD

CrazY. 07-03-2018 15:30

Re: native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
 
is_user_alive already check if the player is connected, so you don't need to verify. Also, you need to check if weapon is a valid entity.

Code:
public SkinCheck(id) {     if(!is_user_alive(id))         return PLUGIN_HANDLED;         new Sil, WPName[32];     formatex(WPName, charsmax(WPName), DefaultModels[get_user_weapon(id)][1]);     new WPN = find_ent_by_owner(-1, DefaultModels[get_user_weapon(id)][1], id);         if (!is_valid_ent(WPN))         return PLUGIN_HANDLED;     if(get_user_weapon(id) == CSW_M4A1 || get_user_weapon(id) == CSW_USP)         Sil = cs_get_weapon_silen(WPN);             if(get_user_weapon(id) == CSW_AWP)         cs_set_user_zoom(id, 0, 0);         PlayAnimation(id, AnimationIDs[get_user_weapon(id)][Sil]);     return PLUGIN_HANDLED; }

Also, consider to use switch instead of a lot of "if"

ZEDD_Intensity 07-03-2018 16:38

Re: native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
 
Quote:

Originally Posted by CrazY. (Post 2600814)
is_user_alive already check if the player is connected, so you don't need to verify. Also, you need to check if weapon is a valid entity.
Also, consider to use switch instead of a lot of "if"

Thanks CrazY! Great pointer on that Validation check, it did feel like I was missing something than editing the existing. Everything seems so far so good, no errors.

Will keep switch() in mind as well.

Thanks again and Regards,
ZEDD


All times are GMT -4. The time now is 12:13.

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