Hello !
I need help for config my darkRP HUD, it's the TCB HUD 2 [I]free[/I] :
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 :
[CODE] local VAL_Rank = LocalPlayer():GetUserGroup() or "Joueur"[/CODE]
[CODE] --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)[/CODE]
But I made this for change the colors :
[CODE] 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[/CODE]
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
[QUOTE=Mrkrabz;51800959]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.[/QUOTE]
not working there is an ERROR LUA :
[code]
[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
[/code]
[QUOTE=Ezotose;51803226]not working there is an ERROR LUA :
[code]
[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
[/code][/QUOTE]
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]
[QUOTE=smithy285;51803234]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][/QUOTE]
When i change this, the rank is now written in yellow but it never change color...
It's user, superadmin admin. There are indexed but there are all yellow colored...
Ho yeah I will remove the capitals matter thank's.
Lets try now...
[editline]10th February 2017[/editline]
It Working ! Thank's all !
Sorry, you need to Log In to post a reply to this thread.