Hello, I have this code:
[code]
hook.Add( "KeyPress", "RemoveEntity", function( ply, key )
if ( ply:GetActiveWeapon():GetClass() == "weapon_sh_tool" ) then
if(key == KEY_1 or key == KEY_2 or key == KEY_3 or key == KEY_4)then --DOESN'T RUN!
ents.FindByName("GhostEntity"):Remove()
end
end
end )
[/code]
and the second if statement doesnt run, any ideas? this is being ran clientside.
[QUOTE=Mattymoo14211;48615234]Hello, I have this code:
[code]
hook.Add( "KeyPress", "RemoveEntity", function( ply, key )
if ( ply:GetActiveWeapon():GetClass() == "weapon_sh_tool" ) then
if(key == KEY_1 or key == KEY_2 or key == KEY_3 or key == KEY_4)then --DOESN'T RUN!
ents.FindByName("GhostEntity"):Remove()
end
end
end )
[/code]
and the second if statement doesnt run, any ideas? this is being ran clientside.[/QUOTE]
ents.FindByName return a table. You are trying to remove table not an entity.
[QUOTE=SteppuFIN;48615262]ents.FindByName return a table. You are trying to remove table not an entity.[/QUOTE]
What do you suggest I use instead?
Loop through the table and remove each entry.
[QUOTE=Mattymoo14211;48615268]What do you suggest I use instead?[/QUOTE]
[CODE]
for k, v in pairs( ents.FindByName("GhostEntity") ) do
v:Remove()
end
[/CODE]
Should remove all GhostEntity's on map.
[QUOTE=SteppuFIN;48615298][CODE]
for k, v in pairs( ents.FindByName("GhostEntity") ) do
v:Remove()
end
[/CODE]
Should remove all GhostEntity's on map.[/QUOTE]
I have done that, still doesnt work, with no errors.
The issue: [url]https://steamcommunity.com/sharedfiles/filedetails/?id=512143425[/url]
[code]
hook.Add( "KeyPress", "RemoveEntity", function( ply, key )
if ( ply:GetActiveWeapon():GetClass() == "weapon_sh_tool" ) then
if(key == KEY_1 or key == KEY_2 or key == KEY_3 or key == KEY_4)then
for k, ent in pairs( ents.FindByName("GhostEntity"))do
ent:Remove()
end
end
end
end )
[/code]
im sure its GhostEntity, as in the gamemode files, this is used to remove the entity.
[code]
self.GhostEntity:Remove()
[/code]
what happens is, I hold the tool gun as usual, then press 1 or 2 or 3 or 4, it will switch to the weapon corresponding with the key, and it will just switch and the floating entity will stay there.
But is the entity actually CALLED ghostentity? Run this after self.GhostEntity is called in whatever file it's in: print( self.GhostEntity:GetClass() )
[editline]4th September 2015[/editline]
Oh, you want to remove it when the toolgun is gone? Just use the toolgun holster function.
[QUOTE=code_gs;48615402]But is the entity actually CALLED ghostentity? Run this after self.GhostEntity is called in whatever file it's in: print( self.GhostEntity:GetClass() )
[editline]4th September 2015[/editline]
Oh, you want to remove it when the toolgun is gone? Just use the toolgun holster function.[/QUOTE]
yes, basically, if im not using the tool gun, I want it gone
[editline]4th September 2015[/editline]
[QUOTE=code_gs;48615402]But is the entity actually CALLED ghostentity? Run this after self.GhostEntity is called in whatever file it's in: print( self.GhostEntity:GetClass() )
[editline]4th September 2015[/editline]
Oh, you want to remove it when the toolgun is gone? Just use the toolgun holster function.[/QUOTE]
The toolgun holster function is already in the files:
[code]
function TOOL:Holster()
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
end
function TOOL:OnRemove()
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
end
function TOOL:OwnerChanged()
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
end
[/code]
[editline]4th September 2015[/editline]
this is what is returned from the print
class C_BaseFlex
Sorry, you need to Log In to post a reply to this thread.