HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Force A Unit To Use An Item

07-19-2007, 04:37 AM#1
Beardo
This trigger [ideally] forces a unit to use an item when an ability is casted.
It fires fine and all the debug message appear, but whatever I do the hero will NOT use the item

I tried using the native call UnitUseItem(u, i) but it doesnt do ANYTHING.

Here's the code:

Collapse JASS:
function HotKeyExecChild takes nothing returns nothing
local timer t = GetExpiredTimer()
local string d = GetAttachmentTable(t)
local hotkeydata hkd = GetTableInt(d, "hkd")

debug call BJDebugMsg("ImRunning")

call UnitUseItem(hkd.u, hkd.i)

call hkd.destroy()
call ClearTable(d)
call DestroyTimer(t)
set t = null
endfunction



function HotKeyExec takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer slot
local hotkeydata hkd = hotkeydata.create()
local timer t = CreateTimer()
local string d = GetAttachmentTable(t) 


debug call BJDebugMsg("HotKeyHIT")

//===========================================
//                  SLOT 1
//===========================================
        if GetSpellAbilityId() == 'A05R' then
            set hkd.i = UnitItemInSlot(u, 0)
            set hkd.u = u
            call SetTableInt(d, "hkd", hkd)
            call TimerStart(t, 3, false, function HotKeyExecChild) //I added a timer for testing purposes to make sure using the ability wasnt preventing using the item
        endif            

set t = null
set d = null
set u = null
endfunction

//function BlahBlahBlah_InitTrig takes nothing returns nothing
//...

And just to clarify, I dont want the hero to actually CAST the item ability, I just want to emulate left-clicking the ability.

P.S. I should mention the item im using is not a consumable or a potion or anything like that. It's a non-droppable, pawnable item that has a unit ability on it
07-19-2007, 06:47 AM#2
blu_da_noob
You can't emulate 'left clicking' an item. If you have an ability which requires a target you have to issue an order with a target and it will use the item. Unless the force key function works on the numpad but I doubt it.
07-19-2007, 10:34 AM#3
Beardo
Doesnt work


New Code:
Hidden information:

Collapse JASS:
function HotKeyExecChild takes nothing returns nothing
local timer t = GetExpiredTimer()
local string d = GetAttachmentTable(t)
local hotkeydata hkd = GetTableInt(d, "hkd")

debug call BJDebugMsg("ImRunning")


call IssueTargetOrderById(hkd.u, 852007, hkd.target)

call hkd.destroy()
call ClearTable(d)
call DestroyTimer(t)
set t = null
endfunction




No idea why..
07-19-2007, 01:47 PM#4
blu_da_noob
Are you sure:
  • The hotkeydata object loads correctly and that hkd.u and hkd.target are both set correctly.
  • The casting has any mana required to cast
  • The spell has its targets set so it can target the target (lol hmm)
  • The item has the correct spell
  • The item is in the slot corresponding to that order id (in this case your order id isn't even correct, it should be between 852008 and 852013, corresponding to slots 1 to 6).
07-19-2007, 05:16 PM#5
Beardo
Yeah that was a typo, ive been testing 852008

I'm starting to feel like those otrders are nonexistant
It doesn't matter what item I put in slot one, it simply won't use it

I was reading a thread posted by a dude who was trying to do the exact same thi ng and had the exact same results (actually, you were the only one helping him out too). Has anyone actually gotten a unit to use items via order IDs?


EDIT: Okay, I got it to work, but NOT via that native

For anyone who's interested (or anyone who spends 6 hours like I did pullinig their hair out trying to figure this shit out) I used 'UnitUseItemTarget()'. I've never even HEARD of that function before now
But it seems like IssueTargetOrderById seems to be compltely useless for USING items. I found, however, that it works great for prohibiting/controlling item movement (IE for extended invetory systems with dragging)

thanks for your help though blu