AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] Hud Msg Problem (https://forums.alliedmods.net/showthread.php?t=141023)

Stylaa 10-18-2010 16:58

[Solved] Hud Msg Problem
 
im running this funcktion to show the players healt on my server

and what did i wrong?

it displays

tylaa HP: 10000
ter HP: 10000

Must be
Stylaa HP: 10000
Peter HP: 10000

i realy dont know what i did Wrong

PHP Code:

public zombie_hud()
{
    
set_task(1.0"zombie_hud"// set a task to Zombie Hud

            
new szText[2560]
            
szText ""
            
for(new 0g_max_clientsi++)
            {
                if(
g_connected[i] == true && cs_get_user_team(i) == CS_TEAM_CT )
                {
                    new 
PlayerName[33]
                    new 
PlayerHealt[33]
                    
                    
get_user_name(iPlayerName64)
                    
PlayerHealt[i] = get_user_health(i)
                    
                    
formatex(szTextcharsmax(szText), "%s %s HP: %d ^n"szText,PlayerName[i], PlayerHealt[i])
                }
            }
            
set_hudmessage(255000.700.02)
            
ShowSyncHudMsg(0g_MsgSyncZombie,"%s"szText)

    



Exolent[jNr] 10-18-2010 17:23

Re: Hud Msg Problem
 
formatex() -> format() because you are using szText as a formatting variable.
Read about that here: http://www.amxmodx.org/funcwiki.php?...atex&go=search

Also, you don't need an array for health.

Finally, don't index PlayerName in the format statement. Just put the variable name.

Stylaa 10-18-2010 17:30

Re: Hud Msg Problem
 
Thanks it works great now

Hunter-Digital 10-18-2010 21:36

Re: [Solved] Hud Msg Problem
 
And don't create the variables inside the loop (that'll make a variable for each literation), place them before the loop!

Also, I see that you create playername using 33 cells and you're using get_user_name() with 64... make up your mind, but better use charsmax() like so:
Code:

new name[32]

get_user_name(id, name, charsmax(name))



All times are GMT -4. The time now is 10:26.

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