Need help to config HUD

Hello !
I need help for config my darkRP HUD, it’s the TCB HUD 2 free :
I would like to write the rank of the player in (this is working), but if he is Player the rank is written in Yellow, if he is Admin, the rank is written in blue and if he is SuperAdmin, the rank is written in red.

The basic code for writing the rank is this :


	local VAL_Rank      = LocalPlayer():GetUserGroup() or "Joueur"


	--Rank
	draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285 + 1, HUD.PosY + 18 * 1 + 2.5 * 2 + 1, Color(0, 0, 0, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
	draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285, HUD.PosY + 18 * 1 + 2.5 * 2, Color(51, 51, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)

But I made this for change the colors :


	if ply:IsSuperAdmin() then
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285 + 1, HUD.PosY + 18 * 1 + 2.5 * 2 + 1, Color(0, 0, 0, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285, HUD.PosY + 18 * 1 + 2.5 * 2, Color(51, 51, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
	else if ply:IsAdmin() then
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 320 + 1, HUD.PosY + 18 * 1 + 2.5 * 2 + 1, Color(0, 0, 0, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 320, HUD.PosY + 18 * 1 + 2.5 * 2, Color(255, 51, 51, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
	else
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285 + 1, HUD.PosY + 18 * 1 + 2.5 * 2 + 1, Color(0, 0, 0, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
		draw.DrawText(VAL_Rank, "TCB_BebasNeue_1", HUD.PosX + 285, HUD.PosY + 18 * 1 + 2.5 * 2, Color(51, 255, 255, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
	end

But it not working ! :weeb:

Can you help me please ?

Any errors? I’m guessing ply isn’t defined.

Try this:
[lua]
local rankcolors = {
[“SuperAdmin”] = Color(255,0,0),
[“Admin”] = Color(0,0,255),
[“User”] = Color(255,255,0),
}

local rankcol = rankcolor[VAL_Rank] or Color(255,255,0)
draw.DrawText(VAL_Rank, “TCB_BebasNeue_1”, HUD.PosX + 285 + 1, HUD.PosY + 18 * 1 + 2.5 * 2 + 1, Color(0, 0, 0, 255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
draw.DrawText(VAL_Rank, “TCB_BebasNeue_1”, HUD.PosX + 285, HUD.PosY + 18 * 1 + 2.5 * 2, rankcol, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER)
[/lua]

Preferably put the table of ranks outside of the HUDPrint hook, doesn’t need to be but best to.

i would make VAL_Rank lowercase to check against the table

not working there is an ERROR LUA :



[ERROR] arkrpmodification-master/lua/darkrp_modules/tcb_hud_2/cl_main.lua:248: attempt to index global 'rankcolor' (a nil value)
  1. PlayerInfo - addons/[a]darkrpmodification-master/lua/darkrp_modules/tcb_hud_2/cl_main.lua:248
   2. fn - addons/[a]darkrpmodification-master/lua/darkrp_modules/tcb_hud_2/cl_main.lua:512
    3. unknown - addons/ulib/lua/ulib/shared/hook.lua:109



It’s a spelling mistake, literally read your own error and compare it to what is being defined in your code

[sp] Change ‘rankcolor’ in local rankcol = rankcolor[VAL_Rank] or Color(255,255,0) to ‘rankcolors’ [/sp]

When i change this, the rank is now written in yellow but it never change color…

What rank is being drawn? Is it indexed in the table?

It’s user, superadmin admin. There are indexed but there are all yellow colored…

That is incorrect. “User”, “SuperAdmin”, and “Admin”, are indexed, not “user”, “superadmin”, and “admin”. Capitals matter.

Ho yeah I will remove the capitals matter thank’s.

Lets try now…

[editline]10th February 2017[/editline]

It Working ! Thank’s all !