1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  4. The Secrets of Warcraft 3 have revealed interesting works. The RESULTS for Abelhawk's Mini-Mapping Contest #15 have come out!
    Dismiss Notice
  5. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  6. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  7. Night Rider gained several songs for his journey. The poll for the 12th Music Contest has started. Check it out!
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  9. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

assistance with random shop items

Discussion in 'World Editor Help Zone' started by 311, Aug 12, 2019 at 11:11 PM.

  1. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    How would I make a trigger so there is random items in the shop (but never the same items 2x)

    so for example the shop will show 12 items (out of a possible of 50 items)
    if I buy an item now there is 11 items showing
    One item should be added of any item that isn't currently in shop

    I know I need to add the items to a variable array, which I have done that for all 50 items, but I am not sure how to get it to add them to shop with making sure the item isn't already there, because then nothing happens :(

    For example add item (random item # between 1 and 50)
    well if the item isn't already in the shop great it works fine, but if it tries to add a item that is in the shop then nothing will happen and I will just have an empty spot :(

    I want my shop to have 12 items at all times, as soon as you buy an item a random item gets added of my 50, but the 12 items in the shop have to be different.
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,663
    Resources:
    1
    Spells:
    1
    Resources:
    1
    You could use the (criminally underused) itempool type for this: Itempools Guide
    1. Have 1 itempool: UnusedPool.
    2. Add all items to UnusedPool with equal weighting.
    3. Randomize an item from Unused pool, remove that type from UnusedPool, and add it to the shop's sell list.
    4. Repeat step 3 for a total of 12 items.
    5. When an item is bought from the shop, add that item-type to the UnusedPool then repeat step 3.
     
  3. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    I dont understand the guide, or even the map that came with it :(
    I only know GUI, so unsure what I would modify in the trigger that they have
     
  4. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    Alright, here's something I whipped up. It's not efficient and it's not a good way of doing this, but it's really GUI friendly. At least I hope it is.

    There's Instructions in the Trigger Editor. Make sure that your Shop uses the "Sell Items" ability. Also, make sure you copy & paste the Units/Triggers and have "Automatically create unknown variables" checked on under "File -> Preferences -> General" in the World Editor.

    Edit: I could create something 100x more efficient in Lua if you want. You'd have to enable Lua under Scenario -> Map Options though, which can be a pain in the ass to do if you use any JASS triggers or Custom Scripts (You have to disable the Custom Scripts before making the switch to Lua but you can re-enable them afterwards. JASS on the other hand I think you can't use at all). However, if your map is 100% GUI then it would be easy to enable Lua.
     

    Attached Files:

    Last edited: Aug 13, 2019 at 6:44 AM
  5. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,663
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Code (vJASS):
    //put this in your custom script section
    //or a blank JASS trigger
    globals
      itempool UnusedPool = CreateItemPool()
    endglobals

    • Events
      • Time - Elapsed game time is 0.50 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 50 do (Actions)
        • Loop - Actions
          • Set SellItem = ItemTypeArray[(Integer A)]
          • Custom script: call ItemPoolAddItemType(UnusedPool, udg_SellItem, 1.)
      • For each (Integer A) from 1 to 12 do (Actions)
        • Loop - Actions
          • Trigger - Run ADD_ITEM_TRIGGER (ignoring conditions)

    • -------- ADD_ITEM_TRIGGER --------
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_ItemVariable = PlaceRandomItem(UnusedPool, 0., 0.)
      • Set SellItem = Item-type of ItemVariable
      • Item - Remove ItemVariable
      • Custom script: call ItemPoolRemoveItemType(UnusedPool, udg_SellItem)
      • Neutral Building - Add SellItem to YOUR_SHOP with 1 in stock and a max stock of 1

    • Events
      • Unit - A unit sells an item
    • Conditions
      • ((Triggering Unit) equal to YOUR_SHOP)
    • Actions
      • Set SellItem = (Item type of (Sold item))
      • Custom script: call ItemPoolAddItemType(UnusedPool, udg_SellItem, 1.)
      • Trigger - Run ADD_ITEM_TRIGGER (ignoring conditions)
     
  6. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    @Pyrogasm Did you test that? Because I always get problems with:
    • Neutral Building - Add SellItem to YOUR_SHOP with 1 in stock and a max stock of 1

    For whatever reason it doesn't work properly. I had to keep track of all of the items in the shop and remove all of them/then add them back including the new item.

    Something like this:
    • Shop Trig
      • Events
      • Conditions
      • Actions
        • Neutral Building - Limit (Triggering unit) to 0 item slots
        • Neutral Building - Limit (Triggering unit) to 11 item slots
        • For each (Integer A) from 1 to 11, do (Actions)
          • Loop - Actions
            • Neutral Building - Add Item[(Integer A)] to (Triggering unit) with 1 in stock and a max stock of 1
     
    Last edited: Aug 14, 2019 at 4:40 AM
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,663
    Resources:
    1
    Spells:
    1
    Resources:
    1
    The unit has to have the "sell items" ability and have no items listed as sold in the OE. Info in this thread and many others: Add/remove items in a specific shop
     
  8. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    I remember messing with this for a while. The shop has Sell Items and all of the other requirements are met. It's not like it doesn't work entirely, it just stops working after a few times.

    Edit: Okay, I recreated the bug. The first 2-3 times that I purchase an item, the item is immediately replaced by itself (restocks basically). However, after that some of the other items begin to disappear 1 by 1 as I purchase more and more items. It's almost as if there is conflicting button positions and when you add a New item for whatever reason it pushes another item out. The new item you add is NEVER removed.

    • Shop Setup
      • Events
        • Time - Elapsed game time is 0.00 seconds
      • Conditions
      • Actions
        • Neutral Building - Add Clarity Potion to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Healing Salve to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Ivory Tower to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Mechanical Critter to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Moonstone to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Potion of Healing to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Potion of Invisibility to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Potion of Lesser Invulnerability to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Potion of Mana to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Rod of Necromancy to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1
        • Neutral Building - Add Sacrificial Skull to Goblin Merchant (IL Lists) 0003 <gen> with 1 in stock and a max stock of 1


    • Shop Purchase
      • Events
        • Unit - A unit Sells an item (from shop)
      • Conditions
      • Actions
        • Neutral Building - Add (Item-type of (Sold Item)) to (Selling unit) with 1 in stock and a max stock of 1
     
    Last edited: Aug 14, 2019 at 4:44 AM
  9. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
  10. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    @311
    I think you have to replace all instances of "UnusedPool" with "udg_UnusedPool" in the triggers. But don't change it in the custom script thingy. Try it out, I'm not too certain. You may have also messed up with the custom script, where did you place it?
     
    Last edited: Aug 14, 2019 at 4:52 AM
  11. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,663
    Resources:
    1
    Spells:
    1
    Resources:
    1
    The udg_ prefix is added to all GUI variables and stands for "user defined global". The itempool type doesn't exist in GUI so you can only make it with a JASS globals block and thus its name will not have any prefix unless you give it one. As I said:
     
  12. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    I did unless I did it wrong

    upload_2019-8-14_4-13-52.png
     
  13. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    That's the "Custom Script Code Comment". As in where you can put your own comment for notes like "This is how this works and blah blah blah". Below it is the "Custom Script:" Gotta read carefully!
     
  14. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    lol I knew that :p
    I am still getting errors however :(


    however I don't believe this will produce the result I wanted like I originally thought
    What I am really trying to do is have 12 different icons to choose between that each is a different summon and I get to choose where to place them.

    I want it a random 12 of a total of 36(originally had 50) but # shouldnt matter anyway
    but basically I want to be able to always see 12 different summons at a time out of 36, and when clickking I can place where they go
     
  15. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    Use Abilities instead of Items. Base the abilities off of the Channel ability. Set each abilities Target Type to Point and make sure each ability has a different Base Order ID. Then apply the logic used in the system Pyrogasm suggested or take a look at my map.

    How I would do it:
    Add Abilities to the Marketplace instead of Items. Then instead of "When a Shop Sells an Item" you do "When a unit starts the effect of an ability" to detect which ability was purchased (cast). Then remove that ability from the Marketplace and add a new one. The only issue would be that the Gold cost/Lumber cost of the ability (if it has a cost) would have to be triggered so it won't show up in the tooltip. Not that big of a deal though, you can always type it yourself like "Purchase Fireball - 100 Gold".

    Want me to make this for you? I can easily edit the map I made to work this way OR I can create you an entirely new system in Lua (but like I said before you'll have to enable Lua which means you can't use JASS and it's a slight pain to setup).
     
  16. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    sure if you could that would be great.
    Rather not LUA, as some spells are in JASS I think, my map will be fairly simple but sometimes they got some cool stuff on here :)
    but basically a multiplayer map where each player can see 12 different units at a time out of a possible of 36, when you choose one, you cast a summon spell at the location.
    now that unit you summon goes away of the 12 spots and that 1 spot is replaced with a different random summon of the 36(none of which can be in the shop already)
     
  17. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    Here it is.

    I tested it in singleplayer and it seems to work. I created 4 abilities (4 units) but you can add as many as you want. It won't really look like it's working until there's more than 12 units (abilities).

    Remember, each Ability has to have a different Base Order ID or they will conflict with one another.

    Edit: reuploaded map
     

    Attached Files:

    Last edited: Aug 15, 2019 at 3:05 AM
  18. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    It worked, at least so far it seems to when I added up to 14 just to test, haven't tried multiplayer yet, but thanks so much :).
     
  19. Uncle

    Uncle

    Joined:
    Aug 10, 2018
    Messages:
    287
    Resources:
    0
    Resources:
    0
    Here's a Lua version I made if you ever feel like making the switch. I imagine eventually you'll be able to use all of the languages together without the hassle.

    Also it's GUI friendly and very simple to use.
     

    Attached Files:

    Last edited: Aug 16, 2019 at 10:49 PM
  20. 311

    311

    Joined:
    May 12, 2019
    Messages:
    16
    Resources:
    0
    Resources:
    0
    Would it be easy to change slightly change it to where you get to choose the possible units to be available at random?
    so for example the shop instead starts empty, and I choose lets say 20 units (this # isn't 100% decided yet) choose the 20 out of the 36 I 1st mentioned, though this 36# has climbed to over 45 now
    now the shop will add 12random spells "unit summons" of those 20 I chose.

    the beginning of the map is where I would choose the 20 units, doesn't exactly matter how, this part I know how to trigger, and can just do the wisp in front like in the RPGs in the past, or even just have a different shop with blank abilities that add it to the "unit summon shop"