Raised This Month: $ Target: $400
 0% 

Hudmessage With const


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 06-11-2010 , 12:22   Hudmessage With const
Reply With Quote #1

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?
__________________
Retired.

Last edited by Xalus; 06-11-2010 at 12:27.
Xalus is offline
Old 06-11-2010, 12:26
Xalus
This message has been deleted by Xalus.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-11-2010 , 17:18   Re: Hudmessage With const
Reply With Quote #2

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.
__________________
fysiks is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 06-11-2010 , 18:46   Re: Hudmessage With const
Reply With Quote #3

hmm, thanks
__________________
Retired.
Xalus 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 00:40.


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