Well,
I wanted to convert the Pokeballs SWEP from Sandbox to TTT, but i get some errors in the entity:
[CODE][ERROR] addons/ttt_pokeballs/lua/entities/pb_capture/init.lua:61: Tried to use a NULL entity!
1. SetPos - [C]:-1
2. unknown - addons/ttt_pokeballs/lua/entities/pb_capture/init.lua:61
[/CODE]
The entity is following:
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
util.AddNetworkString("SendSelf")
function ENT:PhysicsCollide(data, phys)
self:EmitSound(self.BounceSnd)
local impulse = -data.Speed * data.HitNormal * .4 + (data.OurOldVelocity * -.6)
phys:ApplyForceCenter(impulse)
end
function ENT:Initialize()
self:SetModel("models/weapons/w_pokeball_thrown.mdl")
self:PhysicsInit(SOLID_CUSTOM)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:DrawShadow(false)
self.timer = CurTime() + 20
end
function ENT:Think()
if self.Entity:GetNWBool("HasHitPlayer", true) then
self:DoEffects(self.ent)
end
end
function ENT:DoEffects(ent)
if type(self.ent) ~= "string" then
self.Alpha = self.Alpha - 800*FrameTime()
ent:SetRenderMode(RENDERMODE_TRANSALPHA)
ent:SetColor(Color(255, 0, 0, self.Alpha))
ent:SetModelScale(ent:GetModelScale()*0.5, 1)
end
end
function ENT:Settype(type)
self.type = type
end
function ENT:SetEnt(ent)
if IsValid(ent) and ent:IsPlayer() then
self.ent = ent
end
end
function ENT:StartTouch(ent)
if self:GetNWBool("HasHitPlayer") then
return false
end
if not self:GetNWBool("HasHitPlayer") and ent:GetClass() ~= "Player_barnacle" and ent:IsPlayer() and IsValid(ent) then
self:SetNWBool("HasHitPlayer", true)
self:EmitSound(self.CaptureSnd)
if SERVER then
local pball = "pokeball_base"
local ent1 = ents.Create(pball)
ent1.spawn = ent:GetClass()
ent1.model = ent:GetModel()
ent1:SetPos(self:GetPos())
ent1:Spawn()
self:Remove()
end
elseif not self.Entity:GetNWBool("HasHitPlayer") then
if SERVER then
local pball2 = "pokeball_capture"
local ent2 = ents.Create(pball2)
--set spawn
ent2:SetPos(self:GetPos())
ent2:Spawn()
self:Remove()
end
end
if ent:IsPlayer() and IsValid(ent) and ent:GetClass() ~= "Player_barnacle" then
self.ent = ent
self:DoEffects(ent)
self:DoColorstuff(ent)
end
end
function ENT:DoColorstuff(ent) --Hacky way of doing this, but it looks cool so what the hell
if IsValid(ent) and ent:IsPlayer() then
ent:SetSolid(SOLID_NONE)
timer.Simple(3.0, function()
ent:Remove()
end)
end
end[/CODE]
It's just the following line which makes problems:
[CODE]ent1:SetPos(self:GetPos())[/CODE]
Hopefully someone can help me.
Check if the entity you created is valid after creating it
Sorry, you need to Log In to post a reply to this thread.