PDA

View Full Version : Hudmessage With const


Xalus
06-11-2010, 12:22
Hello, I need some help for my new mod 'Western: Wild West'


// 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:


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


How to make that? :)


public Rangs(id)
{
if(get_pcvar_num(Western_status))
{
set_hudmessage(255, 0, 0, 0.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
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:

// 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 i = 0; i < sizeof(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(255, 0, 0, 0.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
hmm, thanks