[CODE]include("shared.lua")
function DrawInformation()
local tr = LocalPlayer():GetEyeTrace();
if not ( tr.Entity:GetClass() == "money_printer_upgrade" ) then return end;
local w = 84
if IsValid( tr.Entity ) and tr.Entity:GetPos():Distance( LocalPlayer():GetPos() ) < 100 then
draw.RoundedBox( 4, ScrW() / 2 - ( w / 2 ), ScrH() / 2 - 40, w, 20, Color( 255, 255, 255, 100 ) );
draw.SimpleText( "Printer Upgrade", "DermaDefault", ScrW() / 2, ScrH() / 2 - 30, color_black, 1, 1 );
end;
end;
function ENT:Draw()
self.Entity:DrawModel()
DrawInformation()
end
hook.Add( "HUDPaint", "KUpgradeNotif", DrawInformation );[/CODE]
So, I'm having problems with this script in my DarkRP server. Could anyone tell me what's wrong with it? Here's the error message.
[CODE]
[ERROR] addons/darkrpmodification/lua/entities/k_printer_upgrade/cl_init.lua:5: Tried to use a NULL entity!
1. GetClass - [C]:-1
2. fn - addons/darkrpmodification/lua/entities/k_printer_upgrade/cl_init.lua:5
3. unknown - addons/ulib/lua/ulib/shared/hook.lua:105[/CODE]
Basically above loops over and over whenever I noclip out of the world.
Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/IsValid]Global.IsValid[/url] and check if tr.Entity is valid
How would I know that it is valid, I'm new to Lua... So, would I just put that in the script and look on console to see if it printed what it returned?
[editline]24th July 2015[/editline]
Would this work?
[CODE]print( IsValid( tr.Entity ) )[/CODE]
[code]if IsValid( tr.Entity ) then
-- code
end[/code]
[QUOTE=code_gs;48286802][code]if IsValid( tr.Entity ) then
-- code
end[/code][/QUOTE]
I should've known that lmao. thanks. checking now.
[editline]24th July 2015[/editline]
It's coming as an error.
[CODE]
[ERROR] addons/darkrpmodification/lua/entities/k_printer_upgrade/cl_init.lua:14: attempt to index global 'tr' (a nil value)
1. unknown - addons/darkrpmodification/lua/entities/k_printer_upgrade/cl_init.lua:14
[/CODE]
You have to put it after the "local tr..."
It would look something like this
include("shared.lua")
[CODE]function DrawInformation()
local tr = LocalPlayer():GetEyeTrace();
if IsValid( tr.Entity ) then
if not ( tr.Entity:GetClass() == "money_printer_upgrade" ) then return end;
end
local w = 84
if IsValid( tr.Entity ) and tr.Entity:GetPos():Distance( LocalPlayer():GetPos() ) < 100 then
draw.RoundedBox( 4, ScrW() / 2 - ( w / 2 ), ScrH() / 2 - 40, w, 20, Color( 255, 255, 255, 100 ) );
draw.SimpleText( "Printer Upgrade", "DermaDefault", ScrW() / 2, ScrH() / 2 - 30, color_black, 1, 1 );
end;
end;
function ENT:Draw()
self.Entity:DrawModel()
DrawInformation()
end
hook.Add( "HUDPaint", "KUpgradeNotif", DrawInformation );][/CODE]
[QUOTE=B10H4Z4RD;48287084]You have to put it after the "local tr..."
It would look something like this
include("shared.lua")
[CODE]function DrawInformation()
local tr = LocalPlayer():GetEyeTrace();
if IsValid( tr.Entity ) then
if not ( tr.Entity:GetClass() == "money_printer_upgrade" ) then return end;
end
local w = 84
if IsValid( tr.Entity ) and tr.Entity:GetPos():Distance( LocalPlayer():GetPos() ) < 100 then
draw.RoundedBox( 4, ScrW() / 2 - ( w / 2 ), ScrH() / 2 - 40, w, 20, Color( 255, 255, 255, 100 ) );
draw.SimpleText( "Printer Upgrade", "DermaDefault", ScrW() / 2, ScrH() / 2 - 30, color_black, 1, 1 );
end;
end;
function ENT:Draw()
self.Entity:DrawModel()
DrawInformation()
end
hook.Add( "HUDPaint", "KUpgradeNotif", DrawInformation );][/CODE][/QUOTE]
This worked, mate! Thanks soooo much! :)
Sorry, you need to Log In to post a reply to this thread.