AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hudmessage With const (https://forums.alliedmods.net/showthread.php?t=129308)

Xalus 06-11-2010 12:22

Hudmessage With const
 
Hello, I need some help for my new mod 'Western: Wild West'

PHP Code:

// Rangs
new const RANG[][64] = {
    
"Bandit",
    
"Cowgirl",
    
"Cowboy",
    
"Shireff"
};
// Kills needed
new const KILLS[TOTALKILLS] = {
    
1,
    
5,
    
10,
    
15


And I need in a Hudmessage like:

Code:

Rangs
    - Bandit (%s kills)
    - Cowboy (%s kills)
    - ..

How to make that? :)

PHP Code:

public Rangs(id)
{
    if(
get_pcvar_num(Western_status))
    {
        
set_hudmessage(255000.01, -1.0)
        
show_hudmessage(id"%s^n   Levels:^n      Rang: %s (Kills: %d)^n      Rang: %s (Kills: %d)^n      Rang: %s (Kills: %d)^n      Rang: %s (Kills: %d)^n"RANG[0], KILLS[0], RANG[1], KILLS[1], RANG[2], KILLS[2], RANG[3], KILLS[3])
    }
    return 
PLUGIN_CONTINUE;


But is theire a better & shorter way?

fysiks 06-11-2010 17:18

Re: Hudmessage With const
 
If you want the display part to be more dynamic (aka depend on the consts) then you should use a loop to make the HUD string.

I would do something like this:

PHP Code:

// Rangs
new const RANG[][64] = {
    
"Bandit",
    
"Cowgirl",
    
"Cowboy",
    
"Shireff"
};
// Kills needed
new const KILLS[sizeof(RANG)] = {
    
1,
    
5,
    
10,
    
15
}
new 
HUDstring[64]

public 
plugin_cfg()
{
    new 
len 0
    len 
formatex(HUDstring[len], charsmax(HUDstring) - len"Levels:")
    for(new 
0sizeof(RANG); i++)
    {
        
len += formatex(HUDstring[len], charsmax(HUDstring) - len"^nRang: %s (Kills: %d)"RANG[i], KILLS[i])
    }
}

public 
Rangs(id)
{
    if(
get_pcvar_num(Western_status))
    {
        
set_hudmessage(255000.01, -1.0)
        
show_hudmessage(id,HUDstring)
    }
    return 
PLUGIN_CONTINUE;


You had an extra (unused) %s at the begining of your HUD message so I don't know what you wanted there. Let me know because my example might need modified.

Xalus 06-11-2010 18:46

Re: Hudmessage With const
 
hmm, thanks


All times are GMT -4. The time now is 14:45.

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