Dota 2 Workshop Tools/Scripting/API/Global.CreateUnitByName: Difference between revisions
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
No edit summary |
|||
Line 65: | Line 65: | ||
-- Set the new owner as the controlling player | -- Set the new owner as the controlling player | ||
unit:SetControllableByPlayer(keys.caster:GetOwner():GetPlayerID(), true ) | unit:SetControllableByPlayer(keys.caster:GetOwner():GetPlayerID(), true ) | ||
-- Note: Only heroes will return the correct value for keys.caster:GetPlayerOwnerID() | |||
-- Useing keys.caster:GetOwner():GetPlayerID() will allow created units to create more units | |||
-- For example having builder make a building and that building create units | |||
end | end |
Revision as of 09:13, 17 August 2014

Function Description
handle CreateUnitByName(string a, Vector b, bool c, handle d, handle e, int f)
Creates a DOTA unit by its dota_npc_units.txt name ( szUnitName, vLocation, bFindClearSpace, hNPCOwner, hUnitOwner, iTeamNumber )
Parameters
Type | Name | Description | Example |
---|---|---|---|
string | a | The name of the unit as referenced in the KV | "npc_dota_creature_troll_healer" |
Vector | b | The Vector at which the unit will be created | keys.caster:GetAbsOrigin() |
bool | c | Whether or not to find free space for the unit | true/false |
handle | d | NPC Owner, Unknown Function | nil |
handle | e | Unit Owner, Unknown Function | nil |
int | f | The Team ID in which to place the unit | keys.caster:GetTeam() |
Returns
handle - The handle to the unit that was created
Example
The currently best known way to make a unit under the control of a player is something like
function CreateUnit(keys) -- Create the unit around the caster and find free space for it to prevent getting suck local unit = CreateUnitByName("npc_dota_unit", keys.caster:GetAbsOrigin(), true, nil, nil, keys.caster:GetTeam()) -- Set the owner of the new unit to the owner of the old unit unit.vOwner = keys.caster:GetOwner() -- Set the new owner as the controlling player unit:SetControllableByPlayer(keys.caster:GetOwner():GetPlayerID(), true ) -- Note: Only heroes will return the correct value for keys.caster:GetPlayerOwnerID() -- Useing keys.caster:GetOwner():GetPlayerID() will allow created units to create more units -- For example having builder make a building and that building create units end