• 🏆 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] Added item is removed from shop after purchase. :(

Status
Not open for further replies.
Level 13
Joined
Jul 26, 2008
Messages
1,009
After using JASS to add an item to a shops stock, no matter what numbers I put in the stockMax or currentStock field, when a unit buys the item the item is gone from stock. So how do I set this up properly? Thanks. I mean, I can do a basic system that counts how many times the item was bought and readds it til it reaches 0, but I wanted to make sure there wasn't a simpler way first.

Below is the map used and this is the trigger that adds the item. Oddly, units do not have this problem when adding them the same way.

JASS:
function Trig_GainsEclipsingDream_Actions takes nothing returns boolean
    if GetBuyingUnit() == gg_unit_nC84_0658 and GetItemTypeId(GetSoldItem()) == 'moon' then
        call AddItemToStock(gg_unit_nC84_0658, 'moon', 1, 4)
    endif
 return false
endfunction

//===========================================================================
function InitTrig_GainsEclipsingDream takes nothing returns nothing
    set gg_trg_GainsEclipsingDream = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_GainsEclipsingDream, EVENT_PLAYER_UNIT_PAWN_ITEM )
    call TriggerAddCondition( gg_trg_GainsEclipsingDream, function Trig_GainsEclipsingDream_Actions )
endfunction
 

Attachments

  • TRASH.w3x
    12 KB · Views: 44

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,526
Sorry for the double post, but I wanted to make sure the OP saw this, it's important.

First off you're handling actions within a condition, which means no new thread is created. If you put a TSA into it, it will crash the function.

Second of all, you didn't declare your condition function as a boolexpr, which means you have to Put Condition(function a) instead of just function a.

Here's your trigger converted to "perfect" vJass.

JASS:
scope eclipsingDream initializer i
    private function c takes nothing returns boolean
        local unit u=GetBuyingUnit()
        local integer i=GetItemTypeId(GetSoldItem())
        if u==gg_unit_nC84_0658 and i=='moon' then
            call AddItemToStock(gg_unit_nC84_0658,'moon',1,4)
        endif
        set u=null
        set i=null
        return false
    endfunction
    
    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PAWN_ITEM)
        call TriggerAddCondition(t,Condition(function c))
    endfunction
endscope
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Fortunately vJASS/NewGen (one of those) inputs the Conditions/Filter parts automatically.

I did have some trouble with TriggerSleepAction crashing my Conditions once a time ago and realized it was because it is only for Actions. From there, I learned to better use ExecuteFunc and the difference between it and calling a function.

What did you have in mind for the TSA btw? I could always switch some stuff around to do it, I'm certainly not limited. But atm the setup I have now isn't too bad. It was a lot easier than I expected.
 

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,526
The TSA was supposed to cause a break that would allow you to do what you were looking for.

Does it work now? If so then I misunderstood something.

The problem I thought was being caused by you referencing units like GetBuyingUnit() in a way that caused a bug.

But like I said, if it's working now, then ignore my last post.
 
Status
Not open for further replies.
Top