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

(help) HudSyncObject error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
newb1e
Junior Member
Join Date: Feb 2016
Old 02-03-2016 , 18:36   (help) HudSyncObject error
Reply With Quote #1

what is wrong with this code?
the hud message is not displayed!


PHP Code:
public Info()
{
    for(new 
id 1id <= MaxPlayersid++)
    {
        
//if(!is_user_bot(id) && is_user_connected(id))
        //{
            
if(PlayerLevel[id] <= 18)
            {
                
needXP[id] = LEVELS[PlayerLevel[id]] - PlayerXP[id];
                
set_hudmessage(1001001000.010.1301.01.0__, -1)
                static 
buffer[192], len;
                
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
                
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L %d",LANG_PLAYER,"PL_XP",PlayerXP[id]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"NEXT_LVL");
                
len += format(buffer[len], charsmax(buffer) - len" %d ",needXP[id]);
                
len += format(buffer[len], charsmax(buffer) - len"%L",LANG_PLAYER,"FRAGS");
                
ShowSyncHudMsg(idg_MsgHud"%s"buffer);
            } else {
                
set_hudmessage(1001001000.010.1301.01.0__, -1)
                static 
buffer[192], len;
                
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
                
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
                
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"PL_MAX");
                
ShowSyncHudMsg(idg_MsgHud"%s"buffer);
            }
        
//}
    
}
    return 
PLUGIN_CONTINUE


Last edited by newb1e; 02-09-2016 at 19:58.
newb1e is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-03-2016 , 19:39   Re: HudSyncObject not work
Reply With Quote #2

For starters, why do you have this commented out? You need it. Your plugin is probably throwing errors without this check. There's more stuff that can be fixed/improved.

You should instead use get_players() instead of looping through all slots and doing these checks.
PHP Code:
        //if(!is_user_bot(id) && is_user_connected(id))
        //{ 
__________________

Last edited by Bugsy; 02-03-2016 at 19:43.
Bugsy is offline
newb1e
Junior Member
Join Date: Feb 2016
Old 02-03-2016 , 21:23   Re: HudSyncObject not work
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
For starters, why do you have this commented out? You need it. Your plugin is probably throwing errors without this check. There's more stuff that can be fixed/improved.

You should instead use get_players() instead of looping through all slots and doing these checks.
PHP Code:
        //if(!is_user_bot(id) && is_user_connected(id))
        //{ 
i commented that line to disable the bot check. i'm testing the plugin with bots.
it's just a simple xp plugin, but i want to add a sync hud (always showing/updating player stats)
and i did copy this from army ranks plug, but seems that something is wrong.
I'm not good at all in scripting, but a litle help would be nice.
newb1e is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2016 , 20:33   Re: HudSyncObject not work
Reply With Quote #4

Give this a try:
  • I removed code that was duplicated between both player level cases--some of the lines are now shared between both; compare yours to mine to see what I mean.
  • It now uses get_players() instead of looping through all slots. This will get all connected players who are not bots and are not HLTV. You can set flags to get only alive/dead and specific teams if you want.
  • You were also defining a static variable inside your loop which should never be done. All variables should be declared outside of loops. You were defining buffer twice within the same function. This should be declared only one time.
PHP Code:
public Info()
{
    new 
iPlayers32 ] , iNum len id;
    static 
buffer192 ];
    
    
get_playersiPlayers iNum "ch" );
    
    for( new 
iNum i++ )
    {
        
id iPlayers];
        
        
set_hudmessage(1001001000.010.1301.01.0__, -1)
        
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
        
        if ( 
PlayerLevelid ] <= 18 )
        {
            
needXPid ] = LEVELSPlayerLevelid ] ] - PlayerXPid ];
            
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L %d",LANG_PLAYER,"PL_XP",PlayerXP[id]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"NEXT_LVL");
            
len += format(buffer[len], charsmax(buffer) - len" %d ",needXP[id]);
            
len += format(buffer[len], charsmax(buffer) - len"%L",LANG_PLAYER,"FRAGS");
        } 
        else 
        {
            
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"PL_MAX");
        }
        
        
ShowSyncHudMsgid g_MsgHud buffer );
    }
    
    return 
PLUGIN_CONTINUE

__________________

Last edited by Bugsy; 02-04-2016 at 20:36.
Bugsy is offline
newb1e
Junior Member
Join Date: Feb 2016
Old 02-05-2016 , 20:52   Re: HudSyncObject not work
Reply With Quote #5

Nice! i think this is working much better!
btw, are this a good way to hide my rank when i'm dead?
PHP Code:
public Info()
{
    new 
iPlayers32 ] , iNum len id;
    static 
buffer192 ];
    
    
get_playersiPlayers iNum "ch" );
    
    for( new 
iNum i++ )
    {
        
id iPlayers];
        
        
set_hudmessage(1001001000.010.1301.01.0__, -1)
        
len format(buffercharsmax(buffer), "%L",LANG_PLAYER,"RANK");
         
// this
    
if(is_user_alive(id))
    {
    
        if ( 
PlayerLevelid ] <= 18 )
        {
            
needXPid ] = LEVELSPlayerLevelid ] ] - PlayerXPid ];
            
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L %d",LANG_PLAYER,"PL_XP",PlayerXP[id]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"NEXT_LVL");
            
len += format(buffer[len], charsmax(buffer) - len" %d ",needXP[id]);
            
len += format(buffer[len], charsmax(buffer) - len"%L",LANG_PLAYER,"FRAGS");
        } 
        else 
        {
            
len += format(buffer[len], charsmax(buffer) - len" %L",LANG_PLAYER,RANKS[PlayerLevel[id]]);
            
len += format(buffer[len], charsmax(buffer) - len"^n%L",LANG_PLAYER,"PL_MAX");
        }
        
        
ShowSyncHudMsgid g_MsgHud buffer );
    }
        
// here if user dead hide his rank
        
return PLUGIN_HANDLED
   
}

    return 
PLUGIN_CONTINUE

i just added if(is_user_alive(id)) and an return handled.
and would be nice if you help me creating a fuction that will show the rank of the player you spectact. that means if you die, your rank already will hide but will show another player rank when you spectate him. thanks by the way!!
newb1e is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-06-2016 , 10:51   Re: (help) HudSyncObject not work
Reply With Quote #6

This will show the players own data while alive, or spectated player info when dead. You will need to add PLAYERNAME to your language file. You also need to include fakemeta if you do not use it already.

See comments:
PHP Code:
public Info()
{
    new 
iPlayers32 ] , iNum len id iPlayerToShow szName33 ];
    static 
buffer192 ];
    
    
//Get all players who are connected and are not bots or HLTV
    
get_playersiPlayers iNum "ch" );
    
    
//Loop through these players
    
for( new iNum i++ )
    {
        
id iPlayers];
        
        
//If self is alive then use self player id. If not alive, use spectated player id (pev_iuser2)
        
iPlayerToShow is_user_aliveid ) ? id pevid pev_iuser2 );
        
        
//If iPlayerToShow is self OR iPlayerToShow is not self and iPlayerToShow is alive
        
if ( ( id == iPlayerToShow ) || is_user_aliveiPlayerToShow ) )
        {
            
//iPlayerToShow is not self, so get players name to we know who is being spectated. 
            //If iPlayerToShow is self then name is not retrieved.
            
if ( iPlayerToShow != id )
            {
                
get_user_nameiPlayerToShow szName charsmaxszName ) );
                
len formatexbuffer charsmaxbuffer ) , "%L %s^n" LANG_PLAYER "PLAYERNAME" szName );
            }
            
            
len += formatexbufferlen ], charsmaxbuffer ), "%L" LANG_PLAYER ,"RANK" );
            
            if ( 
PlayerLeveliPlayerToShow ] <= 18 )
            {
                
needXPid ] = LEVELSPlayerLeveliPlayerToShow ] ] - PlayerXPiPlayerToShow ];
                
len += formatexbufferlen ] , charsmaxbuffer ) - len " %L" LANG_PLAYER RANKSPlayerLeveliPlayerToShow ] ] );
                
len += formatexbufferlen ] , charsmaxbuffer ) - len "^n%L %d" LANG_PLAYER "PL_XP" PlayerXPiPlayerToShow ] );
                
len += formatexbufferlen ] , charsmaxbuffer ) - len "^n%L %d" LANG_PLAYER "NEXT_LVL" needXPiPlayerToShow ] );
                
len += formatexbufferlen ] , charsmaxbuffer ) - len "^n%L" LANG_PLAYER "FRAGS" );
            } 
            else 
            {
                
len += formatexbufferlen ] , charsmaxbuffer ) - len " %L" LANG_PLAYER RANKSPlayerLeveliPlayerToShow ] ] );
                
len += formatexbufferlen ] , charsmaxbuffer ) - len "^n%L" LANG_PLAYER "PL_MAX" );
            }
            
            
set_hudmessage255 255 255 0.01 0.13 0.0 1.0 __, -);
            
ShowSyncHudMsgid g_MsgHud buffer );
        }
    }

__________________

Last edited by Bugsy; 02-06-2016 at 20:58.
Bugsy is offline
newb1e
Junior Member
Join Date: Feb 2016
Old 02-06-2016 , 20:51   Re: (help) HudSyncObject not work
Reply With Quote #7

Error: Undefined symbol "PlayerFrags" on line 171

Should i add new PlayerFrags[32] before plugin_init ?
newb1e is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-06-2016 , 20:55   Re: (help) HudSyncObject not work
Reply With Quote #8

I don't remember why I added it, I think because you had FRAGS but no value for it. I updated my code to remove it
__________________

Last edited by Bugsy; 02-06-2016 at 21:11.
Bugsy is offline
Old 02-07-2016, 06:47
newb1e
This message has been deleted by newb1e.
newb1e
Junior Member
Join Date: Feb 2016
Old 02-09-2016 , 18:52   Re: (help) HudSyncObject error
Reply With Quote #9

Is this beceause i'm testing with bots?
newb1e is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-09-2016 , 19:22   Re: (help) HudSyncObject error
Reply With Quote #10

Yes, all variables are initialized at 0 when first created unless you change the value. So when players first join and no value is assigned, it will be 0. So if PlayerLevel[ id ] = 0 then LEVELS[ PlayerLevel[ id ] ] will be 0 since the first cell in the LEVELS array is 0.

I don't think testing with bots should matter unless you are specifically excluding bots somewhere using !is_user_bot() or excluding them with get_players(). If you are saving data to vault or something with their steam id, then it will only create 1 record for all bots, using podbots atleast.

I don't know enough about your plugin to know what is wrong. Plus it's difficult to help with and/or fix a plugin without seeing all of the code.

This will be good debugging practice for you. When something doesn't work how you expect, put some client_prints or server_prints in to output values. If they are not what you want, you know there is an issue at that location of code.
__________________

Last edited by Bugsy; 02-09-2016 at 19:27.
Bugsy is offline
Reply



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 21:46.


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