Hello, i attempted and searched about this and can't get this to work. Why wont it drop to the floor???
[code]
concommand.Add("SpawnRandom", function(ply, cmd, args)
local ent = ents.Create("ent_rockore")
ent:SetPos(Vector(math.random(520, -5021), math.random(-843, 1942), 500))
ent:SetAngles(Angle(0,0,0))
ent:Spawn()
ent:Activate()
ent:DropToFloor()
end)
[/code]
I am afraid you gotta use a trace down + SetPos. AFAIK DropToFloor works for NPCs only.
Okay, i though that aswell. How said. But how exactly am i going to do that?
ent:DropToFloor(true)
[QUOTE=Robotboy655;43537885]I am afraid you gotta use a trace down + SetPos. AFAIK DropToFloor works for NPCs only.[/QUOTE]
If that is true than the example on the wiki is wrong, this is what was on the wiki:
Example :
[CODE]
for _, Ent in pairs( ents.FindByClass( "prop_physics" ) ) do
Ent:DropToFloor();
end[/CODE]
Output: Move all props on the server down until they collide with something.
I'll test it and let ya all know. The wird thing is that if you do ent:DropToFloor() without true, on a npc, it will work. :P
[editline]15th January 2014[/editline]
None of these are working?? :((
[code]
concommand.Add("SpawnRandom", function(ply, cmd, args)
-- if MaxRockores < 6 then
--MaxRockores = MaxRockores + 1
local ent = ents.Create("ent_rockore")
ent:SetPos(Vector(math.random(520, -5021), math.random(-843, 1942), 500))
ent:SetAngles(Angle(0,0,0))
ent:Spawn()
ent:Activate()
ent:DropToFloor(true)
-- end
end)
concommand.Add("Spawntrace", function(ply, cmd, args)
local tr = ply:GetEyeTrace().Entity
tr:DropToFloor(true)
ply:ChatPrint("Done")
end)
[/code]
[editline]15th January 2014[/editline]
Ohhhhh god!!! This is all my fault! Just found out that it doesn't matter if you do true or blank... The entity has to be alittle close to the ground, before this can work. It has to be around a player hight if i want it to drop down... Sorry everyone.
[editline]15th January 2014[/editline]
So i have to figure out how to do so it drops to the floor. The issue is that i got a pump in the map, so i skal the ents above it and then drop it. Anyone know how to work around this?
I ran into the same problem a few days ago with the same objective as you. I am by no means a 'great' coder so I'm sure the code below could be cleaned up, but essentially...
[lua]function Entity:DropToFloorAlt()
if !self or !IsValid(self) then return false end
local startpos = self:GetPos()
local down = self:GetPos()-Vector(0,0,8000)
local trace = util.TraceLine({start = startpos, endpos = down, filter = self })
if trace.HitWorld then
self:SetPos(Vector(startpos.x,startpos.y,trace.HitPos.z+5))
end
end[/lua]
[QUOTE=TheBigS;43544755]I ran into the same problem a few days ago with the same objective as you. I am by no means a 'great' coder so I'm sure the code below could be cleaned up, but essentially...
[lua]function Entity:DropToFloorAlt()
if !self or !IsValid(self) then return false end
local startpos = self:GetPos()
local down = self:GetPos()-Vector(0,0,8000)
local trace = util.TraceLine({start = startpos, endpos = down, filter = self })
if trace.HitWorld then
self:SetPos(Vector(startpos.x,startpos.y,trace.HitPos.z+5))
end
end[/lua][/QUOTE]
That code doesn't at all take account for the size nor orientation of the object.
Ehh? Soo it wont work?
[editline]16th January 2014[/editline]
[QUOTE=TheBigS;43544755]I ran into the same problem a few days ago with the same objective as you. I am by no means a 'great' coder so I'm sure the code below could be cleaned up, but essentially...
[lua]function Entity:DropToFloorAlt()
if !self or !IsValid(self) then return false end
local startpos = self:GetPos()
local down = self:GetPos()-Vector(0,0,8000)
local trace = util.TraceLine({start = startpos, endpos = down, filter = self })
if trace.HitWorld then
self:SetPos(Vector(startpos.x,startpos.y,trace.HitPos.z+5))
end
end[/lua][/QUOTE]
Well i had to add the MetaTable, but it works fine! Thanks!!!!!
This works:
[code]
local meta = FindMetaTable("Entity")
function meta:DropToFloorAlt()
if !self or !IsValid(self) then return false end
local startpos = self:GetPos()
local down = self:GetPos()-Vector(0,0,8000)
local trace = util.TraceLine({start = startpos, endpos = down, filter = self })
if trace.HitWorld then
self:SetPos(Vector(startpos.x,startpos.y,trace.HitPos.z+5))
end
end
[/code]
Sorry, you need to Log In to post a reply to this thread.