Hello, I am making a HUD element and I want it to display (for CP’s only) who is currently wanted.
I have this code, which makes the HUD element: (clientside of course)
[LUA]
local defaultwantedplayers = {
“No players wanted.”
}
local wantedplayers = {
}
function CheckWantedPlayers()
if wantedplayers == nil then
wantedplayers = table.Copy( defaultwantedplayers )
end
end
function DrawCopHUD()
if LocalPlayer():isCP() then
local X = ScrW()/2-750
local Y = 0
local W = 500
local H = 290
surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( X, Y, W, 35+(#defaultwantedplayers*20) )
draw.RoundedBox( 4, X, Y, W, 30, Color( 0, 0, 100, 200 ) )
draw.DrawText("WANTED PLAYERS", "TargetID", X+W/2, Y+7, Color( 255, 0, 0, 200 ), TEXT_ALIGN_CENTER )
local y = 35
for i, wplayer in pairs( wantedplayers ) do
draw.DrawText( i .. ": " .. wplayer, "TargetID", X+5, y, Color( 255, 255, 255, 200 ) )
y = y + 20
end
end
end
hook.Add(“HUDPaint”, “DrawCopHUD”, DrawCopHUD)
function AddWantedPlayer( um )
table.insert( wantedplayers, um:ReadString() )
end
usermessage.Hook(“AddWantedPlayer”, AddWantedPlayer )
[/LUA]
And this is my serverside that checks if a player is wanted:
[LUA]
local defaultwantedplayers = {
“No players wanted.”
}
local wantedplayers = {
}
function CheckWantedPlayers()
if wantedplayers == nil then
wantedplayers = table.Copy( defaultwantedplayers )
end
end
function DrawCopHUD()
if LocalPlayer():isCP() then
local X = ScrW()/2-750
local Y = 0
local W = 500
local H = 290
surface.SetDrawColor( 0, 0, 0, 200 )
surface.DrawRect( X, Y, W, 35+(#defaultwantedplayers*20) )
draw.RoundedBox( 4, X, Y, W, 30, Color( 0, 0, 100, 200 ) )
draw.DrawText("WANTED PLAYERS", "TargetID", X+W/2, Y+7, Color( 255, 0, 0, 200 ), TEXT_ALIGN_CENTER )
local y = 35
for i, wplayer in pairs( wantedplayers ) do
draw.DrawText( i .. ": " .. wplayer, "TargetID", X+5, y, Color( 255, 255, 255, 200 ) )
y = y + 20
end
end
end
hook.Add(“HUDPaint”, “DrawCopHUD”, DrawCopHUD)
function AddWantedPlayer( um )
table.insert( wantedplayers, um:ReadString() )
end
usermessage.Hook(“AddWantedPlayer”, AddWantedPlayer )
[/LUA]
There are no console errors outputted, I must just be using something wrong?
Any help appreciated, thanks.