Hi, I'm trying to make a STool for a custom entity. However this error keeps popping up once the custom entity has been spawned:
[ERROR] gamemodes/sandbox/gamemode/player_extension.lua:79: attempt to index local 'ent' (a nil value)
1. AddCount - gamemodes/sandbox/gamemode/player_extension.lua:79
2. MakeCapturePoint - addons/capture_point/lua/weapons/gmod_tool/stools/dk_capturepoint.lua:25
3. LeftClick - addons/capture_point/lua/weapons/gmod_tool/stools/dk_capturepoint.lua:46
4. unknown - gamemodes/sandbox/entities/weapons/gmod_tool/shared.lua:227
Here is the erroneous snippet of the STool code:
cleanup.Register( "ent_capturepoints" )
if ( SERVER ) then
CreateConVar( "sbox_maxent_capturepoints", 20 )
function MakeCapturePoint(ply, model, pos, ang)
if ( IsValid( ply ) && !ply:CheckLimit( "ent_capturepoints" ) ) then return false end
local ent_capturepoint = ents.Create( "ent_capturepoint" )
if ( !IsValid( ent_capturepoint ) ) then return false end
ent_capturepoint:SetModel( model )
ent_capturepoint:SetPos( pos )
ent_capturepoint:SetAngles( ang )
ent_capturepoint:Spawn()
if ( IsValid( ply ) ) then
ply:AddCount( "ent_capturepoints", ent_capturepoint )
ply:AddCleanup( "ent_capturepoints", ent_capturepoint )
end
return ent_capturepoint
end
end
function TOOL:LeftClick( trace )
if ( trace.HitSky || !trace.HitPos ) then return false end
if ( IsValid( trace.Entity ) && ( trace.Entity:GetClass() == "ent_capturepoint" || trace.Entity:IsPlayer() ) ) then return false end
if ( CLIENT ) then return true end
local ply = self:GetOwner()
local ang = trace.HitNormal:Angle()
ang.pitch = ang.pitch - 90
local mdl = self:GetClientInfo( "model" )
MakeCapturePoint(ply, mdl, trace.HitPos, ang)
end
Please send help!
Seems like ent_capturepoint is removed after Spawn() is called. Are you sure it's not deleting itself in an initialize hook or something?
It turns out that somehow a "SBoxlimit_ent_capturepoint" had been created. Just clarifying it's value solved the problem. Thanks for the help!
Sorry, you need to Log In to post a reply to this thread.