• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] can anyone tell me y this doesnt work ?

Status
Not open for further replies.
Level 29
Joined
Oct 24, 2012
Messages
6,543
hello im trying to get an items lumber cost and put it into an array it works w this code
JASS:
function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
    call AddItemToStock( gg_unit_n01L_0127, itemIDS[33],1,1)
    call IssueNeutralImmediateOrderById( Player(0), gg_unit_n01L_0127, itemIDS[33])
    call RemoveItemFromStock( gg_unit_n01L_0127, itemIDS[33])
    call BJDebugMsg( "builds item")
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_003 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Untitled_Trigger_003, Player(0), "-builditem", false)
    call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction

//works as expected just place in a loop
but when i call it in a trigger it doesnt work for player 11 ?
JASS:
private function settingLumberCosts takes nothing returns nothing
    local integer Loop = 33
    local unit u = gg_unit_n01L_0127
    local integer maxLumber = 1000000 // 1 mil
    local integer itemLumber
    local unit Hero = gg_unit_Nalc_0128
    call SetUnitOwner( Hero, Player(11), true)
    loop
        exitwhen Loop > 39
        call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, maxLumber)
        call AddItemToStock( u, itemIDS[Loop], 1, 1)
        call IssueNeutralImmediateOrderById( Player(11), u, itemIDS[Loop])
        call RemoveItemFromStock( u, itemIDS[Loop])
        set itemLumber = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
        set lumberCost[Loop] = maxLumber - itemLumber
        call RemoveItem( UnitItemInSlot( Hero, 0))
        call DisplayTextToForce( GetPlayersAll(), I2S(Loop) + " " + I2S(lumberCost[Loop]))
        set Loop = Loop + 1
    endloop
    call ShowUnit( u, false )
    call ShowUnit( Hero, false )
    set u = null
    set Hero = null
endfunction
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Make sure your shop has the ability Sell Items (Asid) but not Select Hero (Aneu) or similar. Else your buying unit will need to be selected first. However, you do not need a purchaser. This purchasing method will place the item next to the shop.

The stock modying natives are fairly bugged. This might not work for a large amount of item types because RemoveItemFromStock will leak slots now and then. I do not know the details at the moment. Of course you can recreate the shop.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
JASS:
IssueNeutralTargetOrder(<ownerOfBuyer>, <shop>, "neutralinteract", <buyer>)

But this might not work as the ability is disabled while no unit is selected. As I have said, you do not need your hero at all. Get rid of the shop's Select ability, so it can sell items without a customer.
 
Status
Not open for further replies.
Top