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)
m (clean up, added deadend tag)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Dead end|date=January 2024}}
{{Note | This page is automatically generated.  Any changes may be overwritten}}
{{Note | This page is automatically generated.  Any changes may be overwritten}}
[[Category:Dota2Function]]
[[Category:CDOTA_BaseNPC]]


== Function Description ==
== Function Description ==


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


''Give an item to another unit.''
''Give an item to another unit.''


;Example
;Example
Line 19: Line 16:
-- dagger (in slot 0).
-- dagger (in slot 0).


local player = PlayerResource:GetPlayer(0)
local hero0 = PlayerResource:GetPlayer(0):GetAssignedHero()
local hero = player:GetAssignedHero()
if hero0:GetItemInSlot(0) == nil then
local item = hero:GetItemInSlot(0)
if item == nil then
   local blink = CreateItem("item_blink", nil, nil)
   local blink = CreateItem("item_blink", nil, nil)
   blink:SetPurchaseTime(0)
   blink:SetPurchaseTime(0)
   hero:AddItem(blink)
   hero0:AddItem(blink)
end
end
local callback = function (courier)
local callback = function (courier)
   hero:MoveToNPCToGiveItem(courier, hero:GetItemInSlot(0))
   hero0:MoveToNPCToGiveItem(courier, hero0:GetItemInSlot(0))
end
end
CreateUnitByNameAsync("npc_dota_courier", Vector(0, 0, 0), true, nil,
CreateUnitByNameAsync("npc_dota_courier", Vector(0, 0, 0), true, nil,
Line 48: Line 43:
| The item that should be given to the NPC
| The item that should be given to the NPC
|}
|}
[[Category:Dota2Function]]
[[Category:CDOTA_BaseNPC]]

Latest revision as of 09:16, 21 January 2024

Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024
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 hero0 = PlayerResource:GetPlayer(0):GetAssignedHero()
if hero0:GetItemInSlot(0) == nil then
  local blink = CreateItem("item_blink", nil, nil)
  blink:SetPurchaseTime(0)
  hero0:AddItem(blink)
end
local callback = function (courier)
  hero0:MoveToNPCToGiveItem(courier, hero0: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