Can you help me with one script?
I want that when you are going to create the new props (Trash_X)
The script need to clean the previous props created by the entity before creating the new props
[CODE]AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel( "models/sligwolf/garbagetruck/sw_dumpster.mdl" )
self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
end
function ENT:Think()
-- 1st Trash
Trash_1 = ents.Create("prop_physics")
Trash_1:SetPos(self:GetPos() + Vector(0,25,0))
Trash_1:SetModel("models/Gibs/HGIBS.mdl")
Trash_1:Spawn()
-- 2st Trash
Trash_2 = ents.Create("prop_physics")
Trash_2:SetPos(self:GetPos() + Vector(0,25,0))
Trash_2:SetModel("models/Gibs/HGIBS_rib.mdl")
Trash_2:Spawn()
-- 3st Trash
Trash_3 = ents.Create("prop_physics")
Trash_3:SetPos(self:GetPos() + Vector(0,25,0))
Trash_3:SetModel("models/Gibs/HGIBS_scapula.mdl")
Trash_3:Spawn()
-- 4st Trash
Trash_4 = ents.Create("prop_physics")
Trash_4:SetPos(self:GetPos() + Vector(0,25,0))
Trash_4:SetModel("models/Gibs/HGIBS_spine.mdl")
Trash_4:Spawn()
self:NextThink( CurTime() + 60 )
return true
end[/CODE]
I'm no wizard, so please <anyone> correct me if this is wrong or stupid:
The way I understood your request, you need only one trash entity to be "there" at one time.
I'd do this: (UNTESTED!)
[lua]
function ENT:Initialize()
-- All your other init stuff remains.
self.trashModels = {
"models/Gibs/HGIBS.mdl",
"models/Gibs/HGIBS_rib.mdl",
"models/Gibs/HGIBS_scapula.mdl",
"models/Gibs/HGIBS_spine.mdl",
}
end
function ENT:Think()
if self.trash then self.trash:Remove() end
self.trash = ents.create( "prop_physics" )
self.trash:SetPos( self:GetPos() + Vector( 0, 25, 0 ) )
self.trash:SetModel( table.random( self.trashModels ) )
self.trash:Spawn()
self:NextThink( CurTime() + 60 )
return true
end
[/lua]
This should spawn a random trash entity every 60 seconds, and, when spawning a new one; delete the old one.
No he spawn some props every one minute. he just want to remove the previous ones before the new ones spawn
[QUOTE=WalkingToast;51452286]No he spawn some props every one minute. he just want to remove the previous ones before the new ones spawn[/QUOTE]
Exactly
[QUOTE=DeclanS;51452296]Exactly[/QUOTE]
Just change what he did above to incorporate multiple entities. The underlying concept is already there.
[QUOTE=Fillipuster;51452267]
[lua]
function ENT:Think()
self:NextThink( CurTime() + 60 )
return true
end
[/lua]
[/QUOTE]
Wow, I had no idea you could set NextThink. Is using ENT:Think for things still bad practice if you're using NextThink() instead of having it run every frame?
Sorry, you need to Log In to post a reply to this thread.