Hello everyone! I've been working on a HUD, but every time I switch to Civil protection I get this error:
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/customhud/cl_hud.lua:177: attempt to perform arithmetic on upvalue 'RelativeX' (a nil value)
1. GunLicense - addons/darkrpmodification-master/lua/darkrp_modules/customhud/cl_hud.lua:177
2. fn - addons/darkrpmodification-master/lua/darkrp_modules/customhud/cl_hud.lua:401
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:179
Any help?
Thanks
Post the code.
[QUOTE=CGHippo;48378091]Post the code.[/QUOTE]
[CODE]
end
/*---------------------------------------------------------------------------
HUD ConVars
---------------------------------------------------------------------------*/
local ConVars = {}
local HUDWidth
local HUDHeight
local Color = Color
local cvars = cvars
local DarkRP = DarkRP
local CurTime = CurTime
local draw = draw
local GetConVar = GetConVar
local IsValid = IsValid
local Lerp = Lerp
local localplayer
local math = math
local pairs = pairs
local ScrW, ScrH = ScrW, ScrH
local SortedPairs = SortedPairs
local string = string
local surface = surface
local table = table
local timer = timer
local tostring = tostring
CreateClientConVar("weaponhud", 0, true, false)
local colors = {}
colors.black = Color(0, 0, 0, 255)
colors.blue = Color(0, 0, 255, 255)
colors.brightred = Color(200, 30, 30, 255)
colors.darkred = Color(0, 0, 70, 100)
colors.darkblack = Color(0, 0, 0, 200)
colors.gray1 = Color(0, 0, 0, 155)
colors.gray2 = Color(51, 58, 51,100)
colors.red = Color(255, 0, 0, 255)
colors.white = Color(255, 255, 255, 255)
colors.white1 = Color(255, 255, 255, 200)
local function ReloadConVars()
ConVars = {
background = {0,0,0,100},
Healthbackground = {0,0,0,200},
Healthforeground = {140,0,0,180},
HealthText = {255,255,255,200},
Job1 = {0,0,150,200},
Job2 = {0,0,0,255},
salary1 = {0,150,0,200},
salary2 = {0,0,0,255}
}
for name, Colour in pairs(ConVars) do
ConVars[name] = {}
for num, rgb in SortedPairs(Colour) do
local CVar = GetConVar(name..num) or CreateClientConVar(name..num, rgb, true, false)
table.insert(ConVars[name], CVar:GetInt())
if not cvars.GetConVarCallbacks(name..num, false) then
cvars.AddChangeCallback(name..num, function() timer.Simple(0,ReloadConVars) end)
end
end
ConVars[name] = Color(unpack(ConVars[name]))
end
HUDWidth = (GetConVar("HudW") or CreateClientConVar("HudW", 240, true, false)):GetInt()
HUDHeight = (GetConVar("HudH") or CreateClientConVar("HudH", 115, true, false)):GetInt()
if not cvars.GetConVarCallbacks("HudW", false) and not cvars.GetConVarCallbacks("HudH", false) then
cvars.AddChangeCallback("HudW", function() timer.Simple(0,ReloadConVars) end)
cvars.AddChangeCallback("HudH", function() timer.Simple(0,ReloadConVars) end)
end
end
ReloadConVars()
local Scrw, Scrh, RelativeX, RelativeY
/*---------------------------------------------------------------------------
HUD Seperate Elements
---------------------------------------------------------------------------*/
local Page = Material("icon16/page_white_text.png")
local function GunLicense()
if localplayer:getDarkRPVar("HasGunlicense") then
surface.SetMaterial(Page)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawTexturedRect(RelativeX + HUDWidth, ScrH() - 34, 32, 32)
end
end
local function Agenda()
local ply = LocalPlayer()
local agenda = ply:getAgendaTable()
if not agenda then return end
draw.RoundedBox(10, 10, 10, 460, 110, colors.gray1)
draw.RoundedBox(10, 12, 12, 456, 106, colors.gray2)
draw.RoundedBox(10, 12, 12, 456, 20, colors.darkred)
draw.DrawNonParsedText(agenda.Title, "DarkRPHUD1", 30, 12, colors.red, 0)
local text = ply:getDarkRPVar("agenda") or ""
text = text:gsub("//", "\n"):gsub("\\n", "\n")
text = DarkRP.textWrap(text, "DarkRPHUD1", 440)
draw.DrawNonParsedText(text, "DarkRPHUD1", 30, 35, colors.white, 0)
end
local VoiceChatTexture = surface.GetTextureID("voice/icntlk_pl")
local function DrawVoiceChat()
if localplayer.DRPIsTalking then
local chbxX, chboxY = chat.GetChatBoxPos()
local Rotating = math.sin(CurTime()*3)
local backwards = 0
if Rotating < 0 then
Rotating = 1-(1+Rotating)
backwards = 180
end
surface.SetTexture(VoiceChatTexture)
surface.SetDrawColor(ConVars.Healthforeground)
surface.DrawTexturedRectRotated(ScrW() - 100, chboxY, Rotating*96, 96, backwards)
end
end
CreateConVar("DarkRP_LockDown", 0, {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE})
local function LockDown()
local chbxX, chboxY = chat.GetChatBoxPos()
if util.tobool(GetConVarNumber("DarkRP_LockDown")) then
local cin = (math.sin(CurTime()) + 1) / 2
local chatBoxSize = math.floor(ScrH() / 4)
draw.DrawNonParsedText(DarkRP.getPhrase("lockdown_started"), "ScoreboardSubtitle", chbxX, chboxY + chatBoxSize, Color(cin * 255, 0, 255 - (cin * 255), 255), TEXT_ALIGN_LEFT)
end
end
local Arrested = function() end
usermessage.Hook("GotArrested", function(msg)
local StartArrested = CurTime()
local ArrestedUntil = msg:ReadFloat()
Arrested = function()
if CurTime() - StartArrested <= ArrestedUntil and localplayer:getDarkRPVar("Arrested") then
draw.DrawNonParsedText(DarkRP.getPhrase("youre_arrested", math.ceil(ArrestedUntil - (CurTime() - StartArrested))), "DarkRPHUD1", ScrW()/2, ScrH() - ScrH()/12, colors.white, 1)
elseif not localplayer:getDarkRPVar("Arrested") then
Arrested = function() end
end
end
end)
local AdminTell = function() end
usermessage.Hook("AdminTell", function(msg)
timer.Destroy("DarkRP_AdminTell")
local Message = msg:ReadString()
AdminTell = function()
draw.RoundedBox(4, 10, 10, ScrW() - 20, 100, colors.darkblack)
draw.DrawNonParsedText(DarkRP.getPhrase("listen_up"), "GModToolName", ScrW() / 2 + 10, 10, colors.white, 1)
draw.DrawNonParsedText(Message, "ChatFont", ScrW() / 2 + 10, 80, colors.brightred, 1)
end
timer.Create("DarkRP_AdminTell", 10, 1, function()
AdminTell = function() end
end)
end)
/*---------------------------------------------------------------------------
Entity HUDPaint things
---------------------------------------------------------------------------*/
local function DrawPlayerInfo(ply)
local pos = ply:EyePos()
pos.z = pos.z + 10 -- The position we want is a bit above the position of the eyes
pos = pos:ToScreen()
pos.y = pos.y - 50 -- Move the text up a few pixels to compensate for the height of the text
if GAMEMODE.Config.showname and not ply:getDarkRPVar("wanted") then
draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x + 1, pos.y + 1, colors.black, 1)
draw.DrawNonParsedText(ply:Nick(), "DarkRPHUD2", pos.x, pos.y, team.GetColor(ply:Team()), 1)
end
if GAMEMODE.Config.showhealth and not ply:getDarkRPVar("wanted") then
draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x + 1, pos.y + 21, colors.black, 1)
draw.DrawNonParsedText(DarkRP.getPhrase("health", ply:Health()), "DarkRPHUD2", pos.x, pos.y + 20, colors.white1, 1)
end
if GAMEMODE.Config.showjob then
local teamname = team.GetName(ply:Team())
draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x + 1, pos.y + 41, colors.black, 1)
draw.DrawNonParsedText(ply:getDarkRPVar("job") or teamname, "DarkRPHUD2", pos.x, pos.y + 40, colors.white1, 1)
end
if ply:getDarkRPVar("HasGunlicense") then
s
Seems like RelativeX isn't defined. Or I don't know what I'm talking about.
I don't mess with huds much but as far as research goes it seems you need to define RelativeX as 0.
The problem is RelativeX not being defined, as stated above
Bumping what both norriskirby and chimp said.
[QUOTE=Chimpanzee;48378259]I don't mess with huds much but as far as research goes it seems you need to define RelativeX as 0.[/QUOTE]
Can u please explain how?
local RelativeX = 500
Change 500 to whatever you'd like it to be.
Defining variables is like algebra. You just need to make something you want = something else. Its fun!
and local means its only accessible in that certain file / code block.
[QUOTE=CGHippo;48378309]local RelativeX = 500
Change 500 to whatever you'd like it to be.
Defining variables is like algebra. You just need to make something you want = something else. Its fun!
and local means its only accessible in that certain file / code block.[/QUOTE]
Thanks a lot! Worked like a charm :)
No problem, if you need anymore help don't be scared to ask
Sorry, you need to Log In to post a reply to this thread.