• 🏆 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!

assistance with random shop items

Status
Not open for further replies.

311

311

Level 4
Joined
May 12, 2019
Messages
73
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.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
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.
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
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
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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.
 

Attachments

  • Item Lists v.1.w3x
    29.6 KB · Views: 45
Last edited:
Level 38
Joined
Feb 27, 2007
Messages
4,951
JASS:
//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)
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
@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:
Level 38
Joined
Feb 27, 2007
Messages
4,951
For whatever reason it doesn't work properly and won't always add the new item. The only way I could ever add a new Item to a Shop was to Remove ALL items from the Shop and then Add them all back at once including the New Item.
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
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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:

311

311

Level 4
Joined
May 12, 2019
Messages
73
upload_2019-8-13_20-6-8.png
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
@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:
Level 38
Joined
Feb 27, 2007
Messages
4,951
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:
Pyrogasm said:
//put this in your custom script section
//or a blank JASS trigger
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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!
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
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
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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).
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
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)
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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
 

Attachments

  • Unit Lists v.1.w3x
    28.6 KB · Views: 31
Last edited:

311

311

Level 4
Joined
May 12, 2019
Messages
73
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 :).
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
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.
 

Attachments

  • Unit List Lua v.1.w3x
    28 KB · Views: 32
Last edited:

311

311

Level 4
Joined
May 12, 2019
Messages
73
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"
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
  • UL Setup CONFIGURE THIS
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- CONFIGURE THESE VARIABLES: --------
      • -------- ////////////////////////////////////////// --------
      • -------- Set the total number of Units (abilities) --------
      • Set UL_TotalUnits = 4
      • -------- - --------
      • -------- List the Units (abilities) that you want available --------
      • Set UL_Unit[1] = Summon Footman (Test Ability)
      • Set UL_Unit[2] = Summon Grunt (Test Ability)
      • Set UL_Unit[3] = Summon Ghoul (Test Ability)
      • Set UL_Unit[4] = Summon Archer (Test Ability)
      • -------- - --------
      • -------- Set each Player's Shop --------
      • Set UL_PlayerShop[1] = Shop (UL Lists) 0003 <gen>
      • -------- - --------
      • -------- Set which Players use this System (You probably won't have to change this) --------
      • Set UL_ActivePlayers = (All players controlled by a User player)
      • -------- ////////////////////////////////////////// --------
      • -------- - --------
      • -------- - --------
      • -------- You're all finished! The System will do the rest. --------
      • Trigger - Run UL System <gen> (ignoring conditions)
You can run the trigger above whenever. It doesn't need to be at the start of the game like how I do it.

So you could create a trigger like this instead of using the trigger above:
  • UL Example
    • Events
      • Player - Player 1 (Red) types a chat message containing -archer as An exact match
    • Conditions
    • Actions
      • Set UL_TotalUnits = (UL_TotalUnits + 1)
      • Set UL_Unit[UL_TotalUnits] = Summon Archer (Test Ability)
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UL_TotalUnits Equal to 4
        • Then - Actions
          • -------- Set each Player's Shop --------
          • Set UL_PlayerShop[1] = Shop (UL Lists) 0003 <gen>
          • -------- - --------
          • -------- Set which Players use this System (You probably won't have to change this) --------
          • Set UL_ActivePlayers = (All players controlled by a User player)
          • -------- - --------
          • -------- You're all finished! The System will do the rest. --------
          • Trigger - Run UL System <gen> (ignoring conditions)
        • Else - Actions
      • Trigger - Turn off (This trigger)
Here I use a chat message to add the unit's to the Shop. You can use any kind of Event to do this. Another ability, dialog buttons, items, whatever you think would look best.

I uploaded a new version with this example incorporated. Type "-archer", "-grunt", "-footman", or "-ghoul" in-game to add that unit to the Shop. Once you've added all 4 the System will run and add the Unit's to your Shop at random. Since it's only 4 units you won't notice the randomization but once you go above 12 it will work!
 

Attachments

  • Unit Lists v.2.w3x
    30.5 KB · Views: 23
Last edited:

311

311

Level 4
Joined
May 12, 2019
Messages
73
you are my hero, thanks so much
Haven't tried it, but I am sure it will work :)
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
for the UL_totalunits do I need to make that a array for multiplayer?
I haven't tested multiplayer yet, and I am not the best at triggers but I would think since it is not an array, currently it wouldn't work in multiplayer right? or least all players would contribute to adding the units to teh shop with how it is currently correct?
If this is all that needs to be changed I can do that on my own, I just wanted to make sure.
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
Well, in that example I made I was under the impression that only one player (the host for example) would choose the "list" of units at the start of the game and those would be the Units available to everyone for the rest of the game.

I would have to edit the system a bit to allow each player to have their one "list" of units. But you're right, TotalUnits would need to be an Array. It's a bit more complicated than that though... I'll work on something in a bit.

So to clarify. You DO want every player to be able to choose their own "list" of units?
 
Last edited:

311

311

Level 4
Joined
May 12, 2019
Messages
73
correct each player has their own list of units they would pick in the start of game and each player has their own shop to to then summon those units from the shop
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
Uploaded a new version. I think you'll be happy with this one, I added what I assumed you'd want in a map like this.

1) Each player can have their own unique list of Units.
2) Created a Drafting Timer that will expires after some time. Players that didn't finish their "drafts" (selecting units) will have their drafts automatically finished for them when this timer expires.
3) Added some custom Events so you can easily create your own triggers without having to mess with the system itself (These Events are real variables that I fire during certain stages of the System like when a Player Drafts a Unit or when a Player Finishes Drafting)
4) Added Pages to the Shop so you can browse through just about as many units as you want.

Note: I didn't add Pages to the Summoning aspect of the Shop. With that being said, would you like Pages for the Summoning Units too? Also, I'm planning on making the Page System better. At the moment it's a bit awkward to use.
 

Attachments

  • Unit Lists v.5.w3x
    66.4 KB · Views: 27
Last edited:

311

311

Level 4
Joined
May 12, 2019
Messages
73
No, I don't need pages for the summoning aspect, as I do want some kind of cap, so the fact it only shows 12 at a time is good and works for what I was going for.
As far as the page system for adding the units, I think its really good what you did :), I mean I haven't added more units yet but with the testing so far I think its great.

Thanks so much for all your help
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
Alright, sounds good to me. And you're welcome.

Anyway, there's actually some bugs I found with the Page System so i'm trying to figure out a way to get it to work properly. It would work in singleplayer but not multiplayer
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
There is no way to add unit portraits just on screen is there?, (with being able to click it as a button though)
For the unit selection to add them to the map, that would be the best solution but I don't believe there is a way to make it selectable button correct?

That way for example it would show all units I have available as unit portraits so would see all 50 or however many I end up having at time, when you click it, it would then have the stats of that unit and an ADD button, which would then add it to the shop.

If not I can just have all 50 or whatever units on the screen, and select them to add it that way, but the portraits would be better to take up less space/look nicer
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
I think Abilities are the most useful/easy to do this since you can throw in any information you want into the Tooltip. "Select Footman - 100 Gold, This unit deals 10-14 damage" etc...

However, there's plenty of ways to do cool things with the UI. There are systems on here you could look into like this one: Ultimate GUI Hero Pick System 2.3

Plus the new UI natives add a lot of possibilities.
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
I'm looking through the map again and I can't find any issues. It must've been late when I said that because as far as I can tell it should work in multiplayer... Can you test it out?
 

311

311

Level 4
Joined
May 12, 2019
Messages
73
What part of the trigger causes regular spells not to work?
Because everything is working good, but even though the main part of the game is summoning units there are a few spells you can cast such as chain lighting from the shop, these are similar
to the unit summons in the fact that you also choose them at map start to get added to your shop and how its randomized when you cast it to leave the shop/add new summon/spell

however when I cast it, even though it may do damage in chain lightnings case, it wont jump
I did make sure there was nothing wrong with the ability itself, as I put it on a unit and it jumps fine.
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,456
There shouldn't be any issues with casting abilities as I just tested Chain Lightning and it worked fine for me. It might have something to do with the way you're adding the abilities. OR and much more likely it's because of the Ability itself and which player owns the Shop.

Which Player does your Shop belong to? Because it sounds like Chain Lightning won't bounce because it can't find any legal targets to bounce to.

All of that aside, I did find some critical bugs in v.5 after looking over it again. I attached a fixed version below.

To make importing easy I recommend doing this:
1) Create a copy of your UL Setup Configure trigger and the Event triggers (if you changed them at all) and put them in a different folder.
2) Disable those copies.
3) Delete the Unit Lists folder in your map and open the new v.8 map.
4) In v.8 copy the Unit Lists folder and then paste it into your map.
5) You can now reference your old disabled triggers and transfer the variables from them into the new UL Setup Configure/Events triggers. Just make sure to only replace the configurable variables.
6) Delete the old disabled triggers when you're done.

If the bug still persists can you post the triggers and show me how you're adding abilities to the shop. This system is designed to work specifically with units.
 

Attachments

  • Unit Lists v.8.w3x
    66.6 KB · Views: 25
Last edited:
Status
Not open for further replies.
Top