[QUOTE=Mattymoo14211;48621386]Then how else should I refer to the entity?[/QUOTE]
Sending the entity object
[QUOTE=tyguy;48621605]Sending the entity object[/QUOTE]
could you please give me an example (not very familiar with coding with entities)
[QUOTE=Mattymoo14211;48621757]could you please give me an example (not very familiar with coding with entities)[/QUOTE]
either get the entity by looping through all entities, or save it when you make it
[QUOTE=tyguy;48621823]either get the entity by looping through all entities, or save it when you make it[/QUOTE]
Am I not already looping through them with the for loop?
[editline]5th September 2015[/editline]
I just looped through all ents and this is what I got:
Entity [0][worldspawn]
Entity [13][soundent]
Entity [14][player_manager]
Entity [15][gmod_gamerules]
Entity [16][bodyque]
Entity [17][bodyque]
Entity [18][bodyque]
Entity [19][bodyque]
Entity [20][ai_network]
Entity [22][info_player_start]
Entity [26][func_breakable]
Entity [27][func_breakable]
Entity [28][func_breakable]
Entity [29][func_breakable]
Entity [30][func_breakable]
Entity [31][env_sun]
Entity [32][shadow_control]
Entity [0][sky_camera]
Entity [33][prop_dynamic]
Entity [34][info_player_start]
Entity [35][info_player_start]
Entity [36][info_player_start]
Entity [37][info_player_start]
Entity [38][info_player_start]
Entity [39][info_player_start]
Entity [40][info_player_start]
Entity [41][info_player_start]
Entity [21][env_skypaint]
Player [1][|M00Gaming| MATTYMOO142]
Entity [23][predicted_viewmodel]
Entity [24][predicted_viewmodel]
Entity [25][predicted_viewmodel]
Entity [42][scene_manager]
Weapon [43][weapon_sh_flash]
Weapon [44][tfa_thompson]
Weapon [45][tfa_ak47]
Weapon [46][weapon_sh_doormod]
Weapon [47][weapon_sh_tool]
(I looped through it when the GhostEntity existed)
[QUOTE=Mattymoo14211;48621853]Am I not already looping through them with the for loop?
[editline]5th September 2015[/editline]
I just looped through all ents and this is what I got:
Entity [0][worldspawn]
Entity [13][soundent]
Entity [14][player_manager]
Entity [15][gmod_gamerules]
Entity [16][bodyque]
Entity [17][bodyque]
Entity [18][bodyque]
Entity [19][bodyque]
Entity [20][ai_network]
Entity [22][info_player_start]
Entity [26][func_breakable]
Entity [27][func_breakable]
Entity [28][func_breakable]
Entity [29][func_breakable]
Entity [30][func_breakable]
Entity [31][env_sun]
Entity [32][shadow_control]
Entity [0][sky_camera]
Entity [33][prop_dynamic]
Entity [34][info_player_start]
Entity [35][info_player_start]
Entity [36][info_player_start]
Entity [37][info_player_start]
Entity [38][info_player_start]
Entity [39][info_player_start]
Entity [40][info_player_start]
Entity [41][info_player_start]
Entity [21][env_skypaint]
Player [1][|M00Gaming| MATTYMOO142]
Entity [23][predicted_viewmodel]
Entity [24][predicted_viewmodel]
Entity [25][predicted_viewmodel]
Entity [42][scene_manager]
Weapon [43][weapon_sh_flash]
Weapon [44][tfa_thompson]
Weapon [45][tfa_ak47]
Weapon [46][weapon_sh_doormod]
Weapon [47][weapon_sh_tool]
(I looped through it when the GhostEntity existed)[/QUOTE]
[code]
for k,v in pairs(ents.FindByClass("GhostEntity")) do
--do stuff to 'GhostEntity' like finding if what you're looking at is the one to remove
end
[/code]
[QUOTE=tyguy;48622036][code]
for k,v in pairs(ents.FindByClass("GhostEntity")) do
--do stuff to 'GhostEntity'
end
[/code][/QUOTE]
But if GhostEntity wasnt found when I ran that loop, then it isnt what I should be looking for, is it? Surely the name of the entity im trying to remove should have been printed in my console
[QUOTE=Mattymoo14211;48622055]But if GhostEntity wasnt found when I ran that loop, then it isnt what I should be looking for, is it? Surely the name of the entity im trying to remove should have been printed in my console[/QUOTE]
yup
[QUOTE=tyguy;48622066]yup[/QUOTE]
So, I should definitely be looking for GhostEntity?
[QUOTE=Mattymoo14211;48622079]So, I should definitely be looking for GhostEntity?[/QUOTE]
yup
edit: depends if that's the class name
[QUOTE=tyguy;48622143]yup
edit: depends if that's the class name[/QUOTE]
But I thought the class was C_BaseFlex and the name was 'GhostEntity'
edit: I suppose I should use C_BaseFlex instead then
[editline]5th September 2015[/editline]
I just ran this code:
[code]
hook.Add("PlayerButtonDown", "DONT CARE", function(ply,key)
if(key == KEY_5)then
for k, v in pairs( ents.FindByClass( "C_BaseFlex" ) )do
print( v:GetPos() )
end
end
end)
[/code]
when the player had the tool gun equipped and it didnt print anything
The stronghold gamemode works just fine default why are you trying to make so many unnecessary changes
[QUOTE=Mattymoo14211;48622165]But I thought the class was C_BaseFlex and the name was 'GhostEntity'
edit: I suppose I should use C_BaseFlex instead then
[editline]5th September 2015[/editline]
I just ran this code:
[code]
hook.Add("PlayerButtonDown", "DONT CARE", function(ply,key)
if(key == KEY_5)then
for k, v in pairs( ents.FindByClass( "C_BaseFlex" ) )do
print( v:GetPos() )
end
end
end)
[/code]
when the player had the tool gun equipped and it didnt print anything[/QUOTE]
if you go into the entities folder of the gamemode, what do you see?
[QUOTE=tyguy;48622569]if you go into the entities folder of the gamemode, what do you see?[/QUOTE]
There is effects,entities and weapons.
the files of directory entities/weapons/weapon_sh_tool:
[url]http://185.38.148.82/~moogamin/tool%20gun/weapon_sh_tool/[/url]
[url]http://prntscr.com/8d1nf0[/url]
[QUOTE=Mattymoo14211;48622658]There is effects,entities and weapons.
the files of directory entities/weapons/weapon_sh_tool:
[url]http://185.38.148.82/~moogamin/tool%20gun/weapon_sh_tool/[/url]
[url]http://prntscr.com/8d1nf0[/url][/QUOTE]
but.. whats in entities?
[QUOTE=tyguy;48622695]but.. whats in entities?[/QUOTE]
Here you go: [url]http://185.38.148.82/~moogamin/entities/[/url]
sorry, I didnt reply, was watching a film
You have got entirely the wrong idea here.
The entity you get from the tool gun is CLIENT side, not serverside.
What you tried to do there with the net messages is basically an open exploit for people to remove any entity on your server, including the players. ( Hint: That is very bad )
The reason why it stays there is because you removed the normal weapon changer and replaced it with your half-assed own.
[code]
function TOOL:Holster()
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
return true
end[/code]
This is taken from the tool gun code from one of your links.
( [url]http://185.38.148.82/~moogamin/tool%20gun/weapon_sh_tool/stools/propspawn.lua[/url] )
The problem is TOOL:Holster is not called in your weapon switcher CLIENTSIDE on the old weapon ( When switcing away from the tool gun, the old weapon is the toolgun ), when it should.
[QUOTE=Robotboy655;48623171]You have got entirely the wrong idea here.
The entity you get from the tool gun is CLIENT side, not serverside.
What you tried to do there with the net messages is basically an open exploit for people to remove any entity on your server, including the players. ( Hint: That is very bad )
The reason why it stays there is because you removed the normal weapon changer and replaced it with your half-assed own.
[code]
function TOOL:Holster()
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
return true
end[/code]
This is taken from the tool gun code from one of your links.
( [url]http://185.38.148.82/~moogamin/tool%20gun/weapon_sh_tool/stools/propspawn.lua[/url] )
The problem is TOOL:Holster is not called in your weapon switcher CLIENTSIDE on the old weapon ( When switcing away from the tool gun, the old weapon is the toolgun ), when it should.[/QUOTE]
The weapon switch script is ran clientside, so doing anything like that would not be an issue, so would I have to just put that function in my weapon switching script?
[editline]6th September 2015[/editline]
I have put this code in my weapon selection script:
[code]
function weapon_sh_tool:Holster(wep)
if IsValid( self.GhostEntity ) then
GhostEntity:Remove()
end
GhostEntity = nil
return true
end
[/code]
But it just gives me the error: Attempt to index global weapon_sh_tool (a nil value)
It also says on the wiki, use SWEP:Holster so I tried that, I got the same error, just that SWEP was a nil value, I also tried TOOL and that also gave me the same error.
weapon_sh_tool is the weapon :Holster is the function in the weapon class. SWEP:Holster is basically a function within the weapon metatable.
The error you get is for trying to insert a function into a nonexistent table.
try this:
[CODE]local weapon = FindMetaTable( "Weapon" )
local old_holster = weapon.Holster
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
local rt = old_holster( self, wep )
return rt ~= nil and rt or true
end[/CODE]
alternatively if you can get this to work this would be a better option:
[CODE]local weapon = weapons.GetStored( "weapon_sh_tool" ) --Your weapon class here
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
return true
end[/CODE]
I changed GhostEntity into self.GhostEntity because your were checking for self.GhostEntity and removing GhostEntity
[QUOTE=darkjacky;48625687]weapon_sh_tool is the weapon :Holster is the function in the weapon class. SWEP:Holster is basically a function within the weapon metatable.
The error you get is for trying to insert a function into a nonexistent table.
try this:
[CODE]local weapon = FindMetaTable( "Weapon" )
local old_holster = weapon.Holster
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
local rt = old_holster( self, wep )
return rt ~= nil and rt or true
end[/CODE]
alternatively if you can get this to work this would be a better option:
[CODE]local weapon = weapons.GetStored( "weapon_sh_tool" ) --Your weapon class here
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
return true
end[/CODE]
I changed GhostEntity into self.GhostEntity because your were checking for self.GhostEntity and removing GhostEntity[/QUOTE]
Thankyou, atleast I seem to be getting somewhere now :) I doesnt give any errors, which is a first :)
But, it just doesnt remove the entity. I also tried removing self. and it doesnt work, so I think it must be called something else. As I have said previously, I have tried printing all entities and GhostEntity doesnt appear in the table printed
[editline]6th September 2015[/editline]
I just cant find the correct name for the entity
-bump-
[QUOTE=darkjacky;48625687]weapon_sh_tool is the weapon :Holster is the function in the weapon class. SWEP:Holster is basically a function within the weapon metatable.
The error you get is for trying to insert a function into a nonexistent table.
try this:
[CODE]local weapon = FindMetaTable( "Weapon" )
local old_holster = weapon.Holster
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
local rt = old_holster( self, wep )
return rt ~= nil and rt or true
end[/CODE]
alternatively if you can get this to work this would be a better option:
[CODE]local weapon = weapons.GetStored( "weapon_sh_tool" ) --Your weapon class here
function weapon:Holster( wep )
if IsValid( self.GhostEntity ) then
self.GhostEntity:Remove()
end
self.GhostEntity = nil
return true
end[/CODE]
I changed GhostEntity into self.GhostEntity because your were checking for self.GhostEntity and removing GhostEntity[/QUOTE]
What you are doing is inherently wrong, the problem OP is having is because of the Holster function not being called by his custom weapon switcher. Overriding the weapons Holster method is a very terrible idea because you will be breaking the weapon itself, but is also pointless because the function is never actually called.
[QUOTE=Robotboy655;48627520]What you are doing is inherently wrong, the problem OP is having is because of the Holster function not being called by his custom weapon switcher. Overriding the weapons Holster method is a very terrible idea because you will be breaking the weapon itself, but is also pointless because the function is never actually called.[/QUOTE]
What is the best way to make it holster my weapon then?
Post your weapon switcher code. ( The stuff that actually switches the weapon )
[QUOTE=Robotboy655;48627572]Post your weapon switcher code. ( The stuff that actually switches the weapon )[/QUOTE]
[code]
local MultiKeyBinder = {};
MultiKeyBinder.Binds = {};
function MultiKeyBinder.Think()
local self = MultiKeyBinder;
local p = LocalPlayer();
for _,v in pairs(self.Binds) do
local pressed = true;
for _,key in pairs(v.Keys) do
if(not input.IsKeyDown(key)) then
pressed = false;
break;
end
end
if(pressed) then
if(not v.Pressed) then
if p:IsTyping() or vgui.CursorVisible() then
else
v.Pressed = true;
p:ConCommand(v.Command);
end
end
else
v.Pressed = nil;
end
end
end
hook.Add("Think","MultiKeyBinder.Think",MultiKeyBinder.Think);
function MultiKeyBinder.AddBind(cmd,...)
table.insert(MultiKeyBinder.Binds,
{
Keys = {...},
Command = cmd,
}
);
end
//BIND PRIMARYS
MultiKeyBinder.AddBind("use tfa_acr",KEY_1)
MultiKeyBinder.AddBind("use tfa_ak47",KEY_1)
MultiKeyBinder.AddBind("use tfa_ak74",KEY_1)
MultiKeyBinder.AddBind("use tfa_amd65",KEY_1)
MultiKeyBinder.AddBind("use tfa_an94",KEY_1)
MultiKeyBinder.AddBind("use tfa_auga3",KEY_1)
MultiKeyBinder.AddBind("use tfa_fal",KEY_1)
MultiKeyBinder.AddBind("use tfa_g36",KEY_1)
MultiKeyBinder.AddBind("use tfa_g3a3",KEY_1)
MultiKeyBinder.AddBind("use tfa_l85",KEY_1)
MultiKeyBinder.AddBind("use tfa_m14sp",KEY_1)
MultiKeyBinder.AddBind("use tfa_m16a4_acog",KEY_1)
MultiKeyBinder.AddBind("use tfa_m416",KEY_1)
MultiKeyBinder.AddBind("use tfa_scar",KEY_1)
MultiKeyBinder.AddBind("use tfa_tar21",KEY_1)
MultiKeyBinder.AddBind("use tfa_val",KEY_1)
MultiKeyBinder.AddBind("use tfa_mp5",KEY_1)
MultiKeyBinder.AddBind("use tfa_dragunov",KEY_1)
MultiKeyBinder.AddBind("use tfa_honeybadger",KEY_1)
MultiKeyBinder.AddBind("use tfa_intervention",KEY_1)
MultiKeyBinder.AddBind("use tfa_m98b",KEY_1)
MultiKeyBinder.AddBind("use tfa_mp5sd",KEY_1)
MultiKeyBinder.AddBind("use tfa_aw50",KEY_1)
MultiKeyBinder.AddBind("use tfa_bizonp19",KEY_1)
MultiKeyBinder.AddBind("use tfa_usc",KEY_1)
//BIND SECONDARYS
MultiKeyBinder.AddBind("use tfa_colt1911",KEY_2)
MultiKeyBinder.AddBind("use tfa_coltpython",KEY_2)
MultiKeyBinder.AddBind("use tfa_deagle",KEY_2)
MultiKeyBinder.AddBind("use tfa_glock",KEY_2)
MultiKeyBinder.AddBind("use tfa_hk45",KEY_2)
MultiKeyBinder.AddBind("use tfa_luger",KEY_2)
MultiKeyBinder.AddBind("use tfa_model3russian",KEY_2)
MultiKeyBinder.AddBind("use tfa_model627",KEY_2)
MultiKeyBinder.AddBind("use tfa_mp40",KEY_2)
MultiKeyBinder.AddBind("use tfa_sig_p229r",KEY_2)
MultiKeyBinder.AddBind("use tfa_tec9",KEY_2)
MultiKeyBinder.AddBind("use tfa_thompson",KEY_2)
MultiKeyBinder.AddBind("use tfa_usp",KEY_2)
MultiKeyBinder.AddBind("use tfa_uzi",KEY_2)
//BIND EXPLOSIVES
MultiKeyBinder.AddBind("use weapon_sh_grenade",KEY_3)
MultiKeyBinder.AddBind("use weapon_sh_c4",KEY_3)
MultiKeyBinder.AddBind("use weapon_sh_flash",KEY_3)
//BIND DOOR
MultiKeyBinder.AddBind("use weapon_sh_doormod",KEY_4)
//BIND TOOL GUN
MultiKeyBinder.AddBind("use weapon_sh_tool",KEY_5)
[/code]
-snip-
Misunderstood op
[QUOTE=SuperiorGamer;48622215]The stronghold gamemode works just fine default why are you trying to make so many unnecessary changes[/QUOTE]
Other server owners with the same attitude don't see any players on their server
Here's an example of a proper weapon switching:
[url]http://wiki.garrysmod.com/page/CUserCmd/SelectWeapon[/url]
This would replace your ConsoleCommand stuff.
[QUOTE=Robotboy655;48627962]Here's an example of a proper weapon switching:
[url]http://wiki.garrysmod.com/page/CUserCmd/SelectWeapon[/url]
This would replace your ConsoleCommand stuff.[/QUOTE]
Would this fix the issue I am having?
[editline]6th September 2015[/editline]
Would that also holster my weapons, it also says its used in the default HUD so this might fix my issue.
[QUOTE=Mattymoo14211;48627884]Other server owners with the same attitude don't see any players on their server[/QUOTE]
-Snip- No Reason to start anything
[QUOTE=SuperiorGamer;48628444]-Snip- No Reason to start anything[/QUOTE]
:) FWENDS
[editline]6th September 2015[/editline]
UPDATE: I will test the new code tomorrow as FTP clients on android are shit.
[editline]6th September 2015[/editline]
[QUOTE=SuperiorGamer;48622215]The stronghold gamemode works just fine default why are you trying to make so many unnecessary changes[/QUOTE]
What did you mean by unnecessary changes, I'm intrigued.
Sorry, you need to Log In to post a reply to this thread.