how exactly can i get an entity to relate to a weapon?
i need to know this so i can set the secondary to create a 30 sec timer to destroy the ent that you spawn with primary fire.
Such as this:
[lua]
//--its a bit hacky, but it should get the point acrost.--
function SWEP.SecondaryFire()
GetEntity(S) ("RP_Bomb")
if entity. isValid then
(play bomb code input animation)
Timer.Create("boomtimer",3,0)---[takes three seconds before it calls function below]---
function StartBoom()
GetEntity("rp_bomb")
if entity.IsValid then
ent.Activate()
end
elseif entity.IsNotValid then
HUD.PrintCenter ("No bombs Deployed")
end
end
[/lua]
Your code is pretty awful. It barely passes as pseudo code. However, based on what you said, I think you're looking for something like this:
[lua]function SWEP:SecondaryFire()
local ent = self.Owner:GetEyeTrace().Entity;
if not ValidEntity( ent ) then self.Owner:ChatPrint("That is not a valid entity!"); return; end
timer.Simple( 30, function()
if ( ValidEntity( ent ) ) then
ent:Remove();
end
-- replace ent:Remove() with your explosion code. just do whatever the hell you want with the entity object
end);
end[/lua]
very very close..
what i want it to do is apply the Explosion code to all current entities, owned BY YOU, and is the entity by the name of "rp_bomb"
this taught me some though. thanks
[editline]02:54AM[/editline]
[lua]
function SWEP:SecondaryFire()
local ent = ents.GetByName("rp_bomb")
if ent.IsValid then
self.Owner:ChatPrint("Bomb(s) Armed!")
timer.Simple( 30, function()
--(explode code here)
end)
elseif not ent.IsValid then
self.Owner:ChatPrint("No Bombs Deployed.")
return false
end
end
[/lua]
Basically this is what i want to happen
If the entity(s) by the name of "rp_bomb" exist and are yours, then make THEM ALL explode.
you can use DTVar : [lua]function ENT:SetupDataTables()
self:DTVar("Entity", 0, "owner")
end[/lua]
in shared of your entity then when you spawn it do[lua]ent.dt.owner = self.owner[/lua]
to check if the player is the owner just do [lua]if self.owner == ent.dt.owner then --[[...]] end[/lua]
Are you sure the owner needs to be networked? It's only the server that needs to remember the owner so it knows which bombs to explode.
Sorry, you need to Log In to post a reply to this thread.