duplicator.RegisterEntityClass

From GMod Wiki

Jump to: navigation, search
Mess.pngThis page has been deemed a mess. It may contain unnecessary information or be poorly organized. You can discuss changes on this article's talk page.
Function
Syntax duplicator.RegisterEntityClass( String entity class, Function callback function, arguments for function, ... )
Where is this used?
Description:
register a function used for creating a duplicated entity.
Returns: nil
Part of Library: duplicator
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Duplicator.RegisterEntityClass]Duplicator.RegisterEntityClass [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionThis is from ..\gamemodes\sandbox\gamemode\commands.lua
Used onNewerShared.png
Code
 
local function GenericNPCDuplicator( Player, Model, Class, Equipment, SpawnFlags, Data )
 
        if ( !gamemode.Call( "PlayerSpawnNPC", Player, Class, Equipment ) ) then return end
 
	local Entity = InternalSpawnNPC( Player, Data.Pos, Vector(0,0,1), Class, Equipment, SpawnFlags )
 
	if ( Entity && Entity:IsValid()) then
 
		Entity:SetModel( Model )
		Entity:SetAngles( Data.Angle )
		gamemode.Call( "PlayerSpawnedNPC", Player, Entity )
		Player:AddCleanup( "npcs", Entity )
		table.Add( Entity:GetTable(), Data )
 
	end
 
	return Entity
 
end
 
duplicator.RegisterEntityClass( "npc_alyx", GenericNPCDuplicator, "Model", "Class", "Equipment", "SpawnFlags", "Data"  )
Outputnone
DescriptionThis example registers an entity named sent_dongs for the duplicator
Used onNewerShared.png
Code
function Makedongs( ply, Pos)
 
		local ball = ents.Create( "sent_dongs" )
		if (!ball:IsValid()) then return false end
 
		ball:SetPos( Pos )
		ball:Spawn()
		ball:GetTable():SetPlayer( ply )
 
		local ttable = 
		{
			pl	= ply,
		}
 
		table.Merge( ball:GetTable(), ttable )
 
 
		return ball
 
	end
 
	duplicator.RegisterEntityClass( "sent_dongs", Makedongs, "Pos")
Outputnone


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox