Hi, I'm trying to make a STool for a custom entity. The custom entity is currently very simple as I'm trying to get the STool to work first. The custom entity does get spawned in using the STool, however this error keeps popping up once it's spawned :
[ERROR] addons/capture_point/lua/weapons/gmod_tool/stools/cp.lua:12: attempt to call global 'MakeCP' (a nil value)
1. LeftClick - addons/capture_point/lua/weapons/gmod_tool/stools/cp.lua:12
2. unknown - gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua:227
Here is the STool code so far:
TOOL.Category = "Construction"
TOOL.Name = "#tool.cp.name"
function TOOL:LeftClick( trace )
if ( trace.Entity && trace.Entity:IsPlayer() ) then return false end
local ply = self:GetOwner()
local Ang = trace.HitNormal:Angle()
Ang.pitch = Ang.pitch + 90
local cpoint = MakeCP(ply, Ang, trace.HitPos)
end
if ( SERVER ) then
function MakeCP(pl, ang, pos)
local cpoint = ents.Create("cpentity")
if ( !IsValid( cpoint ) ) then return end
cpoint:SetAngles(ang)
cpoint:SetPos(pos)
cpoint:Spawn()
return cpoint
end
end
if ( CLIENT ) then
language.Add( "tool.cp.name", "Capture Point" )
language.Add( "tool.cp.desc", "Creates Capture Points.")
language.Add( "tool.cp.text", "Location")
end
function TOOL.BuildCPanel( CPanel )
CPanel:AddControl( "Header", { Description = "#tool.cp.desc" } )
CPanel:AddControl( "TextBox", { Label = "#tool.cp.text", Command = "button_description", MaxLenth = "20" } )
end
It probably is a very simple error but a friend and I couldn't fix it. Send help!
TOOL:LeftClick is called in Server and Client, you are making MakeCP only available for SERVER, so wrap the MakeCP call with "if SERVER then"
It worked, thanks!
Sorry, you need to Log In to post a reply to this thread.