Raised This Month: $12 Target: $400
 3% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZEDD_Intensity
Senior Member
Join Date: Jun 2016
Old 07-02-2018 , 18:41   native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
Reply With Quote #1

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
__________________

Last edited by ZEDD_Intensity; 07-03-2018 at 15:12. Reason: better SEO, lol
ZEDD_Intensity is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-02-2018 , 18:51   Re: native "cs_get_user_team" - The complicated way
Reply With Quote #2

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.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
ZEDD_Intensity
Senior Member
Join Date: Jun 2016
Old 07-02-2018 , 20:05   Re: native "cs_get_user_team" - The complicated way
Reply With Quote #3

Quote:
Originally Posted by OciXCrom View Post
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
__________________

Last edited by ZEDD_Intensity; 07-02-2018 at 20:05.
ZEDD_Intensity is offline
CrAzY MaN
Senior Member
Join Date: Mar 2017
Location: India
Old 07-03-2018 , 00:12   Re: native "cs_get_user_team" - The complicated way
Reply With Quote #4

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.
__________________
CrAzY MaN is offline
ZEDD_Intensity
Senior Member
Join Date: Jun 2016
Old 07-03-2018 , 01:58   Re: native "cs_get_user_team" - The complicated way
Reply With Quote #5

Quote:
Originally Posted by CrAzY MaN View Post
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 is offline
ZEDD_Intensity
Senior Member
Join Date: Jun 2016
Old 07-03-2018 , 14:58   Re: native "cs_get_user_team" - The complicated way
Reply With Quote #6

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
__________________

Last edited by ZEDD_Intensity; 07-03-2018 at 15:21. Reason: Dumb stuff by me, edited out.
ZEDD_Intensity is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 07-03-2018 , 15:30   Re: native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
Reply With Quote #7

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"
__________________









Last edited by CrazY.; 07-03-2018 at 15:32.
CrazY. is offline
ZEDD_Intensity
Senior Member
Join Date: Jun 2016
Old 07-03-2018 , 16:38   Re: native "cs_get_user_team" & native "cs_get_weapon_silen" - The complicated way
Reply With Quote #8

Quote:
Originally Posted by CrazY. View Post
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
__________________
ZEDD_Intensity is offline
Old 07-09-2018, 12:06
ZEDD_Intensity
This message has been deleted by ZEDD_Intensity.
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:51.


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