I was working on my darkrp earlier and i noticed when a player dissconnects there things (money printer, ammo crates, etc) dont go away.
The only thing that does go away is the gunlabs.
I was wandering if anyone knows how to correct this i have been working on it all day and i cant figure it out :/
I have tried with rp_removeclassitems 0 and 1.
If the owner is set correctly on all entities, you could just cycle through all entities and remove the ones where owner is the player who just disconnected. You can use the[URL="http://wiki.garrysmod.com/?title=Gamemode.PlayerDisconnected"] PlayerDisconnected [/URL]hook for this.
Ok. Ill lookinto that. Also how can i change the weight of an entity? like i know you can do things like SetColor() and such what would weight be?
I tried that but it seemed just to make id have less physics or something not weigh less. Ill try that again but is there anything else that may work?
[editline]11:38AM[/editline]
O ya also is there a way to find who spawned the entity? Because when they spawn they spawn as "World Prop" or something like that.
When they spawn it use SetOwner on the entity and set the owner as the player.. then to see who spawned it use entity:GetOwner()
Basic Example:
[lua]
local function RemoveDisconected( Player )
for _,Ent in pairs( ents.GetAll() ) do
if ( Ent:GetOwner() == Player ) then
Ent:Remove()
end
end
end
hook.Add("PlayerDisconnected","RemovePlayerStuff",RemoveDisconected)
[/lua]
As Averice said this will require using SetOwner() every time somthing is spawned that you want to be removed when that player goes. Using spawn hooks.
[lua]
PlayerSpawnedVehicle( Player, vehicle )
PlayerSpawnedSENT( userid, prop )
PlayerSpawnedRagdoll( Player, model, ragdoll )
PlayerSpawnedEffect( Player, model, effect, )
PlayerSpawnedProp( Player, model, ent )
PlayerSpawnedNPC( Player, npc )
[/lua]
On second thought doesn't Gmod SetOwner automatically now in sandbox for AddCount()?
Ok thanks ill try to get something like this working. But the thing i want to know is why would the gunlab go away but nothing else? These are the things that puzzle me :/
[editline]06:14PM[/editline]
Thanks for all your help this is now fixed :D
But does anyone have anything as far as the weight situation?
The thing is im trying to make it so you can grav gun the entity but its to heavy :/