• 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] Item Recipe Help

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
Now don't worry it's not the whole item recipe system thing that I'm troubled about, it's how to either lower the cost of the final item of the build in the item store when you have all of the ingredients... Or make the final item not able to be bought in the item store without all of the necessary items for it?

This is an unfinished JASS code of what I have for a Recipe System:

JASS:
globals
    boolean RECIPE_CONDITION              =           true  
    integer RECIPE_NEW                    =           0
    integer array ITEM_ID1
    integer array ITEM_ID2
    integer array ITEM_ID3
    integer array ITEM_ID4
    integer array ITEM_ID5
    integer array ITEM_ID6
    integer array ITEM_COUNT
    integer array OUTPUT_ITEM
    trigger RECIPE_TRIGGER                =           CreateTrigger()
endglobals

function GetItem takes unit u, integer Id returns item
    local integer i = 0
    local item it
    
    loop
        exitwhen i == 6
        if GetItemTypeId(UnitItemInSlot(u, i)) == Id then
            return UnitItemInSlot(u, i)
            set i = 5
        endif
        set i = i + 1
    endloop
    return null
endfunction

function HasItem takes unit u, integer i returns boolean
    local integer index = 0
    local integer id = -1
    local integer s1 = 0
    local integer s2 = 0
    local integer s3 = 0
    local integer s4 = 0
    local integer s5 = 0
    local integer s6 = 0
    
    loop
        exitwhen index == 6
        set id = GetItemTypeId(UnitItemInSlot(u, index))
        if id == 0 then
            set id = -1
        endif
        if id == ITEM_ID1[i] and s1 == 0 then
            set s1 = 1
            set id = -1
        endif
        if id == ITEM_ID2[i] and s2 == 0 then
            set s2 = 1
            set id = -1
        endif
        if id == ITEM_ID3[i] and s3 == 0 then
            set s3 = 1
            set id = -1
        endif
        if id == ITEM_ID4[i] and s4 == 0 then
            set s4 = 1
            set id = -1
        endif
        if id == ITEM_ID5[i] and s5 == 0 then
            set s5 = 1
            set id = -1
        endif
        if id == ITEM_ID6[i] and s6 == 0 then
            set s6 = 1
            set id = -1
        endif
        if s1 + s2 + s3 + s4 + s5 + s6 == ITEM_COUNT[i] then
            return true
        endif
        set index = index + 1
    endloop
    return false
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
One option is to detect the order id of buying an item and interrupting the purchase:
  • Untitled Trigger 086
    • Events
      • Unit - A unit Is issued an order with no target
    • Conditions
    • Actions
      • Custom script: if GetIssuedOrderId() == 1936749167 then
      • Unit - Pause (Triggering unit)
      • Unit - Order (Triggering unit) to Stop
      • Unit - Unpause (Triggering unit)
      • Custom script: endif
1936749167 is the order id of buying Scroll of Protection. The id is different for each item. You can find them out with this:
  • OrderID
    • Events
      • Unit - A unit Is issued an order with no target
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg(OrderId2String(GetIssuedOrderId()) + " ---- " + I2S(udg_i))
 
Status
Not open for further replies.
Top