Hello, I am creating a HUD for DarkRP and after putting the ammo counters, I realized that every time you start up the server, it says that on line 121, GetActiveWeapon is a nil value. However, when I save it, the errors go away. Here is the bit of code that is causing the issue.
[code] if client:GetActiveWeapon():Clip1() >= 0 then
draw.RoundedBox(3, ScrW() - 165, ScrH() - 115,150,100,Color(40,40,40, 230))
draw.RoundedBox(3, ScrW() - 163, ScrH() - 113,150 - 4,100 - 4,Color(100, 100, 150, 115))
draw.SimpleText(client:GetActiveWeapon():Clip1(),"Font2",ScrW() - 130, ScrH() - 65,Color(255,255,255), 1, 1)
draw.SimpleText(client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()), "Font2",ScrW() - 50, ScrH() - 65,Color(255,255,255), 1, 1)
draw.SimpleText(client:GetActiveWeapon():GetPrintName(), "Font",ScrW() - 90, ScrH() - 128,Color(255,255,255), 1, 1) --This is the line that is causing the errors, line 121
draw.RoundedBox(0, ScrW() - 90, ScrH() - 105,1,80,Color(245,245,245,57))
[/code]
I am also having problems with the DModelPanel and InitPostEntity, and these problems are kind of similar. You see, just like my other problem, on server startup there is no DModelPanel until I save the lua file. Here is the bit of code I am having issues with.
[code]
function GM:InitPostEntity()
iconmodel = vgui.Create("DModelPanel")
iconmodel:SetModel( LocalPlayer():GetModel())
function iconmodel:LayoutEntity( Entity ) return end
iconmodel:SetPos(20, ScrH() - 160)
iconmodel:SetAnimated(false)
iconmodel:SetSize(70,70)
iconmodel:SetCamPos( Vector( 14, -4, 65))
iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )
timer.Create("RefreshAvatar", 1, 0, function()
if LocalPlayer():GetModel() ~= iconmodel.Entity:GetModel() then
iconmodel:Remove()
iconmodel = vgui.Create("DModelPanel")
iconmodel:SetModel( LocalPlayer():GetModel())
function iconmodel:LayoutEntity( Entity ) return end
iconmodel:SetPos(20, ScrH() - 160)
iconmodel:SetAnimated(false)
iconmodel:SetSize(70,70)
iconmodel:SetCamPos( Vector( 14, -4, 65))
iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )
end
end)
end
hook.Add("InitPostEntity", "DrawPlayerModel", GM:InitPostEntity())
[/code]
Thanks for your help :)
Just put an if statement checking if the player has a weapon, and if not then don't run the code
[code]
local Weapon = ply:GetActiveWeapon
if IsValid(Weapon) then
--Your code here
end
[/code]
Or just put this above everything that has to do with the ammo counter
[code]if (ply:GetActiveWeapon() == NULL or ply:GetActiveWeapon() == "Camera") then return end [/code]
[QUOTE=Thane;50720208]Just put an if statement checking if the player has a weapon, and if not then don't run the code
[code]
local Weapon = ply:GetActiveWeapon
if IsValid(Weapon) then
--Your code here
end
[/code]
Or just put this above everything that has to do with the ammo counter
[code]if (ply:GetActiveWeapon() == NULL or ply:GetActiveWeapon() == "Camera") then return end [/code][/QUOTE]
Your first method returns with
[code]
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:118: function arguments expected near 'if'
1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:0
[/code]
Which I don't know how to fix, and your second message glitches the game in which although I have a ) on line 130 to end ( on line 94, it will just continue telling me that, and not draw the HUD.
[editline]16th July 2016[/editline]
[QUOTE=deal with it;50723588]Your first method returns with
[code]
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:118: function arguments expected near 'if'
1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:0
[/code]
Which I don't know how to fix, and your second message glitches the game in which although I have a ) on line 130 to end ( on line 94, it will just continue telling me that, and not draw the HUD.[/QUOTE]
Also, that doesn't even have anything to do with the ammo counter, as it is connected to the hook that draws the HUD
[QUOTE=deal with it;50720160]Hello, I am creating a HUD for DarkRP and after putting the ammo counters, I realized that every time you start up the server, it says that on line 121, GetActiveWeapon is a nil value. However, when I save it, the errors go away. Here is the bit of code that is causing the issue.
[code] if client:GetActiveWeapon():Clip1() >= 0 then
draw.RoundedBox(3, ScrW() - 165, ScrH() - 115,150,100,Color(40,40,40, 230))
draw.RoundedBox(3, ScrW() - 163, ScrH() - 113,150 - 4,100 - 4,Color(100, 100, 150, 115))
draw.SimpleText(client:GetActiveWeapon():Clip1(),"Font2",ScrW() - 130, ScrH() - 65,Color(255,255,255), 1, 1)
draw.SimpleText(client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()), "Font2",ScrW() - 50, ScrH() - 65,Color(255,255,255), 1, 1)
draw.SimpleText(client:GetActiveWeapon():GetPrintName(), "Font",ScrW() - 90, ScrH() - 128,Color(255,255,255), 1, 1) --This is the line that is causing the errors, line 121
draw.RoundedBox(0, ScrW() - 90, ScrH() - 105,1,80,Color(245,245,245,57))
[/code]
I am also having problems with the DModelPanel and InitPostEntity, and these problems are kind of similar. You see, just like my other problem, on server startup there is no DModelPanel until I save the lua file. Here is the bit of code I am having issues with.
[code]
function GM:InitPostEntity()
iconmodel = vgui.Create("DModelPanel")
iconmodel:SetModel( LocalPlayer():GetModel())
function iconmodel:LayoutEntity( Entity ) return end
iconmodel:SetPos(20, ScrH() - 160)
iconmodel:SetAnimated(false)
iconmodel:SetSize(70,70)
iconmodel:SetCamPos( Vector( 14, -4, 65))
iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )
timer.Create("RefreshAvatar", 1, 0, function()
if LocalPlayer():GetModel() ~= iconmodel.Entity:GetModel() then
iconmodel:Remove()
iconmodel = vgui.Create("DModelPanel")
iconmodel:SetModel( LocalPlayer():GetModel())
function iconmodel:LayoutEntity( Entity ) return end
iconmodel:SetPos(20, ScrH() - 160)
iconmodel:SetAnimated(false)
iconmodel:SetSize(70,70)
iconmodel:SetCamPos( Vector( 14, -4, 65))
iconmodel:SetLookAt( Vector( 0, 0, 66.5 ) )
end
end)
end
hook.Add("InitPostEntity", "DrawPlayerModel", GM:InitPostEntity())
[/code]
Thanks for your help :)[/QUOTE]
Nevermind, there's no more problems with the DModelPanel (for some reason redoing it fixed it)
Sorry, you need to Log In to post a reply to this thread.