• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Convert Ability Name to Item

Status
Not open for further replies.
Level 2
Joined
Aug 6, 2008
Messages
6
I am trying to create an item at a given location based on what the name of a target of an ability was.

Here I am:
JASS:
function Trig_Pack_Up_Target_Actions takes nothing returns nothing
     local MyItem = GetObjectName(GetSpellTargetUnit())
     call RemoveUnit (GetSpellTargetUnit())
     call CreateItem (MyItem, GetUnitX(GetSpellTargetUnit()), GetUnitY(GetSpellTargetUnit()))
endfunction
For example if I target the unit "Chicken" I want it to turn into the item "Chicken"

Help plz!!
 
Level 4
Joined
Jul 24, 2008
Messages
108
your local variable is not anything right now, you forgot to tell it what it should be. Try this

JASS:
function Trig_Pack_Up_Target_Actions takes nothing returns nothing
     local item MyItem = GetObjectName(GetSpellTargetUnit())   
     call CreateItem (MyItem, GetUnitX(GetSpellTargetUnit()), GetUnitY(GetSpellTargetUnit()))
     call RemoveUnit (GetSpellTargetUnit())
endfunction

Not sure if it makes a difference but you removed the unit, then your using it in the future code, so i just switched when it happens
 
Last edited:
Level 2
Joined
Aug 6, 2008
Messages
6
alright, makes sense, but I still have no idea how to convert the name of the item (effectively "GetObjectName(GetSpellTargetUnit())" to its id.
 
Level 4
Joined
Jul 24, 2008
Messages
108
Oops, sorry for my sloppy code :p didnt realize it wasnt formed correctly until i posted it. So, you want to take the name of the of the target of your spell, and create an item based on the target? Try something like this

JASS:
function Trig_Pack_Up_Target_Actions takes nothing returns nothing
    local unit u = GetSpellTargetUnit()
    local integer target = GetUnitTypeId(GetSpellTargetUnit())
// IF/THEN/ELSE, make one for every different target
    if target == 'xxxx' then
    call CreateItem ('xxxx', GetUnitX(u), GetUnitY(u))
    endif
    call RemoveUnit (u)
    set u = null
endfunction

bascially gets the target of spell, and its id. If its id is something, it will do this. i cant think of anyway of making it shorter, so a bunch of ifthen statements will work
 
Level 2
Joined
Aug 6, 2008
Messages
6
So this is simply impossible... Is there a workaround of any form? Could I perhaps draw upon a link from the item that created the unit?

I am a JASS beginner, sorry for my lack of understanding.
 
Level 4
Joined
Jul 24, 2008
Messages
108
I disagree on what soga says. Items have a 4 digit id just like units do. I is entirly possible to use a bunch of if/then/else statements (one per target) saying if the units id is this, create this item.
 
Level 7
Joined
Jul 20, 2008
Messages
377
I meant Hundirse's solution wouldn't work, not that this was impossible. It is possible, you just need a bunch of if-then-else's or as Troll-Brain says, use the cache.

Though I'd go with the if-then-else's.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
We are talking about the game cache.
You can store integers with string references.

JASS:
native  StoreInteger    takes gamecache cache, string missionKey, string key, integer value returns nothing

So you need to store all the itemId at the initialisation.

missionkey == "ItemId" // or whatever
key == nameOfYourItem, or let's say nameOfYourUnit

And in your trigger use this function :

JASS:
native  GetStoredInteger        takes gamecache cache, string missionKey, string key returns integer
It will return 0 if there is no integer stored.

missionkey == "IemId"
key == GetUnitName(GetSpellTargetUnit())

Don't forget to create the cache and init it.
 
Status
Not open for further replies.
Top