Entity.SetNetworkedEntity

From GMod Wiki

(Redirected from Entity.SetNWEntity)
Jump to: navigation, search
Function
Syntax Entity:SetNetworkedEntity( Var index, Entity value )
Description:
Sets a networked Entity in this entity with the given index to the given value.
Returns: nil
In Object: Entity
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Entity.SetNetworkedEntity]Entity.SetNetworkedEntity [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionSetting the NWEntity of a door that you are looking at.
Used onNewerServer.png
Code
function OwnDoor(ply, cmd, args)
	local trace = ply:GetEyeTrace() -- define a name for where the player is aiming
	if ( trace.Entity:IsValid() and trace.Entity:GetClass() == "prop_door_rotating" ) then -- check weather the entity that you are looking at is valid, and check its class name
	if !ValidEntity( trace.Entity:GetNetworkedEntity( "owner" ) ) then -- check if the entitys NWEntity has been Set already... 
	trace.Entity:SetNWString( "owner", ply ) -- Set the NWEntity to ply
	if( ply:GetNWInt("money") >= 50 ) then -- Check weather or not the player can afford to pay for this door. 
	ply:SetNWInt("money", ply:GetNWInt( "money" ) - 50 ) -- Deduct the money from the player if he/she can afford it... 
			end
		end
	end
end
concommand.Add("ownthisdoor", OwnDoor )
 
-- From "Combine-City RolePlaying Script" 
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox