Raised This Month: $ Target: $400
 0% 

Solved variable command to change hud's color


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-09-2025 , 21:08   variable command to change hud's color
Reply With Quote #1

hi, how do I introduce a variable to change the hud's color throught a custom cvar command?

the custom cvar must modify this : set_hudmessage(0, 255, 0,

PHP Code:
#include <amxmodx>
#include <reapi>
#include <csx>

#define TASK_HUD 5134

new g_iObject

public plugin_init()
{
    
register_plugin("Hud Info""1.4""Tornado_SW/enisato")
    
g_iObject CreateHudSyncObj()
}

public 
client_putinserver(id)
{
    
set_task(1.0"taskShowHud"id TASK_HUD, .flags "b")
}

public 
client_disconnected(id)
{
    new 
iTask id TASK_HUD
    
if (task_exists(iTask))
        
remove_task(iTask)
}

public 
taskShowHud(id)
{
    
id -= TASK_HUD

    
static iStats[STATSX_MAX_STATS], iBody[MAX_BODYHITS]
    new 
iMoney get_member(idm_iAccount)
    new 
iPingiLoss
    get_user_ping
(idiPingiLoss)

    
set_hudmessage(025500.010.2000.11.00.10.1, -1)
    
ShowSyncHudMsg(idg_iObject,
        
"[ Nickname: %n ]^n[ K/D: %.0f/%i ]^n[ Rank: %i/%i ]^n[ Money: $%d ]^n[ Ping: %d ms | Loss: %d%% ]",
        
id,
        
get_entvar(idvar_frags),
        
get_member(idm_iDeaths),
        
get_user_stats(idiStatsiBody),
        
get_statsnum(),
        
iMoney,
        
iPing,
        
iLoss
    
)




note : you need the reapi libraries in order to compile
Attached Files
File Type: sma Get Plugin or Get Source (hud.sma - 48 views - 1.2 KB)

Last edited by enisato; 06-09-2025 at 23:15. Reason: [php]
enisato is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-09-2025 , 21:31   Re: variable command to change hud's color
Reply With Quote #2

Because a color is represented by three numbers, it's not as simple as a having a single cvar and getting its value. You will either need three cvars (one for each color, this is relatively simple because you can just use get_cvar_num() three times for the three color components) or you can have a string cvar that you will need to first read as a string and then parse the string to extract the values. This parsing allows you to use any type of formatting you want, you can use three comma separated decimal values or you could use six hexadecimal characters to store the three values.

Let us know if you need further help. Please post the code that you tried so that we can more easily and quickly help fix issues you may have.
__________________
fysiks is offline
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-09-2025 , 21:35   Re: variable command to change hud's color
Reply With Quote #3

hi, thank you for your feedback, I'll try that
enisato is offline
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-09-2025 , 22:48   Re: variable command to change hud's color
Reply With Quote #4

PHP Code:
#include <amxmodx>
#include <reapi>
#include <csx>

#define TASK_HUD 5134

new g_iObject
new redgreenblue;


public 
plugin_init()
{
    
register_plugin("Hud Info""1.4""Tornado_SW/enisato")
    
g_iObject CreateHudSyncObj()
    
    
red register_cvar("red_hud""0");
    
green register_cvar("green_hud""255");
    
blue register_cvar("blue_hud""0");
}

public 
client_putinserver(id)
{
    
set_task(1.0"taskShowHud"id TASK_HUD, .flags "b")
}

public 
client_disconnected(id)
{
    new 
iTask id TASK_HUD
    
if (task_exists(iTask))
        
remove_task(iTask)
}

public 
taskShowHud(id)
{
    
id -= TASK_HUD

    
static iStats[STATSX_MAX_STATS], iBody[MAX_BODYHITS]
    new 
iMoney get_member(idm_iAccount)
    new 
iPingiLoss
    get_user_ping
(idiPingiLoss)

    new 
get_cvar_num("red_hud")
    new 
get_cvar_num("green_hud")
    new 
get_cvar_num("blue_hud")
    
    
    
set_hudmessage(rgb0.010.2000.11.00.10.1, -1)
    
ShowSyncHudMsg(idg_iObject,
        
"[ Nickname: %n ]^n[ K/D: %.0f/%i ]^n[ Rank: %i/%i ]^n[ Money: $%d ]^n[ Ping: %d ms | Loss: %d%% ]",
        
id,
        
get_entvar(idvar_frags),
        
get_member(idm_iDeaths),
        
get_user_stats(idiStatsiBody),
        
get_statsnum(),
        
iMoney,
        
iPing,
        
iLoss
    
)



works so great, tysm fysiks, appreciate
enisato is offline
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-09-2025 , 23:16   Re: variable command to change hud's color
Reply With Quote #5

I have already learned to introduce natives inside the code, so I can use for eg : CRX rank system natives to display a level

but I'm so glad I could add color variables

Last edited by enisato; 06-10-2025 at 00:28.
enisato is offline
Tote
Senior Member
Join Date: Jul 2023
Old 06-09-2025 , 23:28   Re: variable command to change hud's color
Reply With Quote #6

Quote:
Originally Posted by enisato View Post
PHP Code:
#include <amxmodx>
#include <reapi>
#include <csx>

#define TASK_HUD 5134

new g_iObject
new redgreenblue;


public 
plugin_init()
{
    
register_plugin("Hud Info""1.4""Tornado_SW/enisato")
    
g_iObject CreateHudSyncObj()
    
    
red register_cvar("red_hud""0");
    
green register_cvar("green_hud""255");
    
blue register_cvar("blue_hud""0");
}

public 
client_putinserver(id)
{
    
set_task(1.0"taskShowHud"id TASK_HUD, .flags "b")
}

public 
client_disconnected(id)
{
    new 
iTask id TASK_HUD
    
if (task_exists(iTask))
        
remove_task(iTask)
}

public 
taskShowHud(id)
{
    
id -= TASK_HUD

    
static iStats[STATSX_MAX_STATS], iBody[MAX_BODYHITS]
    new 
iMoney get_member(idm_iAccount)
    new 
iPingiLoss
    get_user_ping
(idiPingiLoss)

    new 
get_cvar_num("red_hud")
    new 
get_cvar_num("green_hud")
    new 
get_cvar_num("blue_hud")
    
    
    
set_hudmessage(rgb0.010.2000.11.00.10.1, -1)
    
ShowSyncHudMsg(idg_iObject,
        
"[ Nickname: %n ]^n[ K/D: %.0f/%i ]^n[ Rank: %i/%i ]^n[ Money: $%d ]^n[ Ping: %d ms | Loss: %d%% ]",
        
id,
        
get_entvar(idvar_frags),
        
get_member(idm_iDeaths),
        
get_user_stats(idiStatsiBody),
        
get_statsnum(),
        
iMoney,
        
iPing,
        
iLoss
    
)



works so great, tysm fysiks, appreciate
if u are registering the cvar to a variable for example red = register_cvar("red_hud", "x") , u dont need to use get_cvar num. just use get_pcvar_num(variable_name). e.g: get_pcvar_num(red), get_pcvar_num(green), get_pcvar_num(blue) and use these 3 directly into the set_hudmessage func. or if u want to use get_cvar_num("red_hud") u dont need to assign the cvar to the var. just register them like this

register_cvar("red_hud", "x") and use the way u are using in the code

and some advanced way would be to make 1 cvar and put three values in it like ("255 255 255") and break them and then use them. but its kinda advanced u can search it up u might find this way being used somewhere

Last edited by Tote; 06-09-2025 at 23:30.
Tote is offline
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-10-2025 , 00:26   Re: variable command to change hud's color
Reply With Quote #7

Quote:
Originally Posted by Tote View Post
if u are registering the cvar to a variable for example red = register_cvar("red_hud", "x") , u dont need to use get_cvar num. just use get_pcvar_num(variable_name). e.g: get_pcvar_num(red), get_pcvar_num(green), get_pcvar_num(blue) and use these 3 directly into the set_hudmessage func. or if u want to use get_cvar_num("red_hud") u dont need to assign the cvar to the var. just register them like this

register_cvar("red_hud", "x") and use the way u are using in the code

and some advanced way would be to make 1 cvar and put three values in it like ("255 255 255") and break them and then use them. but its kinda advanced u can search it up u might find this way being used somewhere
PHP Code:
#include <amxmodx>
#include <reapi>
#include <csx>

#define TASK_HUD 5134

new g_iObject
new redgreenblue;


public 
plugin_init()
{
    
register_plugin("Hud Info""1.4""Tornado_SW/enisato")
    
g_iObject CreateHudSyncObj()
    
    
red register_cvar("red_hud""0");
    
green register_cvar("green_hud""255");
    
blue register_cvar("blue_hud""0");
}

public 
client_putinserver(id)
{
    
set_task(1.0"taskShowHud"id TASK_HUD, .flags "b")
}

public 
client_disconnected(id)
{
    new 
iTask id TASK_HUD
    
if (task_exists(iTask))
        
remove_task(iTask)
}

public 
taskShowHud(id)
{
    
id -= TASK_HUD

    
static iStats[STATSX_MAX_STATS], iBody[MAX_BODYHITS]
    new 
iMoney get_member(idm_iAccount)
    new 
iPingiLoss
    get_user_ping
(idiPingiLoss)

    
get_pcvar_num(red), 
    
get_pcvar_num(green), 
    
get_pcvar_num(blue);
    
    
    
set_hudmessage(redgreenblue0.010.2000.11.00.10.1, -1)
    
ShowSyncHudMsg(idg_iObject,
        
"[ Nickname: %n ]^n[ K/D: %.0f/%i ]^n[ Rank: %i/%i ]^n[ Money: $%d ]^n[ Ping: %d ms | Loss: %d%% ]",
        
id,
        
get_entvar(idvar_frags),
        
get_member(idm_iDeaths),
        
get_user_stats(idiStatsiBody),
        
get_statsnum(),
        
iMoney,
        
iPing,
        
iLoss
    
)


this, right?

Last edited by enisato; 06-10-2025 at 00:30.
enisato is offline
Tote
Senior Member
Join Date: Jul 2023
Old 06-10-2025 , 00:32   Re: variable command to change hud's color
Reply With Quote #8

Quote:
Originally Posted by enisato View Post
PHP Code:
#include <amxmodx>
#include <reapi>
#include <csx>

#define TASK_HUD 5134

new g_iObject
new redgreenblue;


public 
plugin_init()
{
    
register_plugin("Hud Info""1.4""Tornado_SW/enisato")
    
g_iObject CreateHudSyncObj()
    
    
red register_cvar("red_hud""0");
    
green register_cvar("green_hud""255");
    
blue register_cvar("blue_hud""0");
}

public 
client_putinserver(id)
{
    
set_task(1.0"taskShowHud"id TASK_HUD, .flags "b")
}

public 
client_disconnected(id)
{
    new 
iTask id TASK_HUD
    
if (task_exists(iTask))
        
remove_task(iTask)
}

public 
taskShowHud(id)
{
    
id -= TASK_HUD

    
static iStats[STATSX_MAX_STATS], iBody[MAX_BODYHITS]
    new 
iMoney get_member(idm_iAccount)
    new 
iPingiLoss
    get_user_ping
(idiPingiLoss)

    
get_pcvar_num(red), 
    
get_pcvar_num(green), 
    
get_pcvar_num(blue);
    
    
    
set_hudmessage(redgreenblue0.010.2000.11.00.10.1, -1)
    
ShowSyncHudMsg(idg_iObject,
        
"[ Nickname: %n ]^n[ K/D: %.0f/%i ]^n[ Rank: %i/%i ]^n[ Money: $%d ]^n[ Ping: %d ms | Loss: %d%% ]",
        
id,
        
get_entvar(idvar_frags),
        
get_member(idm_iDeaths),
        
get_user_stats(idiStatsiBody),
        
get_statsnum(),
        
iMoney,
        
iPing,
        
iLoss
    
)


this, right?
no
r = get_pcvar_num(red),
g = get_pcvar_num(green),
b = get_pcvar_num(blue); remove these three

and set hud mgs ->

set_hudmessage(get_pcvar_num(red), get_pcvar_num(green), get_pcvar_num(blue), 0.01, 0.20, 0, 0.1, 1.0, 0.1, 0.1, -1)
Tote is offline
enisato
Member
Join Date: Oct 2024
Location: Canada
Old 06-10-2025 , 00:34   Re: variable command to change hud's color
Reply With Quote #9

oh ok, sorry i did not follow your instructions correctly mb, thank you so much
enisato 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 19:21.


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