Dota 2 Workshop Tools/Scripting/API/CDOTA BaseNPC.MoveToNPCToGiveItem: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Dota_Lebot push: Updated Page)
Line 6: Line 6:




''' void MoveToNPCToGiveItem(handle ''a'', handle ''b'') '''
''' void MoveToNPCToGiveItem(handle ''npc'', handle ''item'') '''


''Give an item to another unit.''
''Give an item to another unit.''
Line 12: Line 12:




;Example
<source lang="lua">
-- We create a courier and then order player 0's hero to
-- give the item it has in slot 0 to the courier. If the
-- hero does not have an item in slot 0, we give it a blink
-- dagger (in slot 0).
local player = PlayerResource:GetPlayer(0)
local hero = player:GetAssignedHero()
local item = hero:GetItemInSlot(0)
if item == nil then
  local blink = CreateItem("item_blink", nil, nil)
  blink:SetPurchaseTime(0)
  hero:AddItem(blink)
end
local callback = function (courier)
  hero:MoveToNPCToGiveItem(courier, hero:GetItemInSlot(0))
end
CreateUnitByNameAsync("npc_dota_courier", Vector(0, 0, 0), true, nil,
                      nil, DOTA_TEAM_GOODGUYS, callback)
</source>
== Parameters ==
== Parameters ==
{| class="standard-table" style="width: 50%;"
{| class="standard-table" style="width: 50%;"
Line 19: Line 41:
|-
|-
| handle
| handle
| a
| npc
| Target
| The NPC that should get the item
|-
|-
| handle
| handle
| b
| item
| Caster
| The item that should be given to the NPC
|}
|}

Revision as of 07:06, 18 September 2014

Note.pngNote: This page is automatically generated. Any changes may be overwritten

Function Description

void MoveToNPCToGiveItem(handle npc, handle item)

Give an item to another unit.


Example
-- We create a courier and then order player 0's hero to
-- give the item it has in slot 0 to the courier. If the
-- hero does not have an item in slot 0, we give it a blink
-- dagger (in slot 0).

local player = PlayerResource:GetPlayer(0)
local hero = player:GetAssignedHero()
local item = hero:GetItemInSlot(0)
if item == nil then
  local blink = CreateItem("item_blink", nil, nil)
  blink:SetPurchaseTime(0)
  hero:AddItem(blink)
end
local callback = function (courier)
  hero:MoveToNPCToGiveItem(courier, hero:GetItemInSlot(0))
end
CreateUnitByNameAsync("npc_dota_courier", Vector(0, 0, 0), true, nil,
                      nil, DOTA_TEAM_GOODGUYS, callback)

Parameters

Type Name Description
handle npc The NPC that should get the item
handle item The item that should be given to the NPC