Buydoor function

Hi, so I’m new to GMOD Lua and I’m trying to create a command where I can get ownership of a door so that I can lock and unlock that particular door. I’ve got the basis of this concept working, however since I’m using “Entity:SetOwner” it’s removing all physics of that door. My question is this, is there some method of applying ownership to a door based on the entity that your looking at and still have that prop with full physics? Thanks.

Here’s my buydoor code:



function buyDoor( ply )
	local eyes = ply:GetEyeTrace()
	local ent = eyes.Entity

	if IsValid( ent ) then
		ent:SetOwner(ply)
		ply:ChatPrint( "You've purchased door: " .. ent:EntIndex() )
	end
end
concommand.Add( "buyDoor", buyDoor )


You’re gonna need a seperate swep developing as well which can lock and unlock the entity, i think theres a built in function to make doors not move but i don’t know what it is.

As for the script above couldn’t you learn from DarkRP code or something? Thats what i do

Hey, I’m not sure why I’d need a separate SWEP? For now I’m just trying to make it so that the base function is working correctly and as far as learning it from DarkRP… I tried looking inside of it but it has documents everywhere, includes over this world which is just going to take forever. If you know what file the core buydoor function is in, I’ll greatly appreciate it.

Well how are you going to lock and unlock the door in the actual addon/gamemode

special combination. like alt + e.



UnlockAllDoors = function()
	for _, Door in pairs( ents.GetAll() ) do
		if Door:GetClass() == "func_door" || Door:GetClass() == "prop_door_rotating" || Door:GetClass() == "func_door_rotating" then
			Door:Fire("unlock", "", .5)
		end
	end
end



Pretty simple, tbh.

I’m just using a crowbar for now, as I said, I just want to get the base function of the buydoor working first, the lock & unlocking function is completely fine and working.

I’ve managed to solve the problem. I’ve used “SetNW” functions on both player and entity.