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

Changing Item System for Marketplaces?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
So I am trying to make a shop that changes the items it has for sale every three minutes or so. This is proving to be more difficult then I imagined. Here is what I have so far:

  • SeriorMarkettime
    • Events
      • Time - Every 180.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Tavern (Armor1)) and do (Actions)
        • Loop - Actions
          • Set TempTavernTeam = (Owner of (Picked unit))
          • Set TempTavernUnit = (Picked unit)
          • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
          • Item - Pick every item in ItemFarm <gen> and do (Actions)
            • Loop - Actions
              • Neutral Building - Remove (Item-type of (Picked item)) from TempTavernUnit
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
          • Unit - Change ownership of TempTavernUnit to TempTavernTeam and Change color
All my own items are level 1 and I made sure that no other one is, that way I can be sure what randomizes in, all the core items are set to level 0. The problem is right now that nothing happens after three minutes. I thought that maybe because the change item trigger was for neutral buildings was the problem, so I made it take all taverns, my sell building, change them to neutral, then do the item change, and set them back to their respective owners, but that didn't make a difference. Also there is no way to set item groups or even pick from item groups if there is one, so I have an island on my map that has one of every item in it, hidden, with a region over it called ItemFarm, otherwise there is no way to simply 'Remove all items from shop', you have to specify what item you want. For some reason the items don't remove though. The items on my island aren't even hidden right now, I thought that was the problem but no dice. Can anyone guide me here?
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Before you create the rest of this, this is how it looks like when you've fixed the leaks and made it more efficient:

  • SeriorMarkettime
  • Events
    • Time - Every 180.00 seconds of game time
  • Conditions
  • Actions
    • Set Group = Pick every unit in (Units of type Tavern (Armor1))
    • Unit Group - Pick every unit in Group and do (Actions)
      • Loop - Actions
        • Set TempTavernTeam = (Owner of (Picked unit))
        • Set TempTavernUnit = (Picked unit)
        • Unit - Change ownership of (Picked unit) to Neutral Passive and Retain color
        • Item - Pick every item in ItemFarm <gen> and do (Actions)
          • Loop - Actions
            • Neutral Building - Remove (Item-type of (Picked item)) from TempTavernUnit
        • For each Integer A from 1 to 11 do (Actions)
          • Loop - Actions
            • Neutral Building - Add (Random level 1 item-type) to TempTavernUnit with 1 in stock and a max stock of 1
    • Custom script: call DestroyGroup(udg_Group)
(Group is a Unit Group variable without array).

Now we can start trying to find out why that doesn't work.

If you have based your building off a "Goblin Merchant", the building probably does not have the ability "Sell Item", which is required for those triggers.
Go to the object editor, check your buildings, if they don't have that ability, add it, otherwise I'll search for other problems.

Edit:
You can only remove items that have been added through trigges as far as I know, so do not give them any standard items, but add them all through triggers.
 
Level 6
Joined
Aug 12, 2007
Messages
201
I scrapped it and remade it, I found out you don't even need to remove the items. Adding new ones shoves items from the bottom of the list out. This is my current trigger.

  • MarketRandomize
    • Events
      • Unit - A unit Finishes casting an ability
    • Conditions
      • (Ability being cast) Equal to Cycle Items
    • Actions
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set RandomNumberGenerator = (Random integer number between 1 and 6)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumberGenerator Equal to 1
            • Then - Actions
              • Neutral Building - Add (Random level 1 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomNumberGenerator Equal to 2
                • Then - Actions
                  • Neutral Building - Add (Random level 2 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • RandomNumberGenerator Equal to 3
                    • Then - Actions
                      • Neutral Building - Add (Random level 3 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • RandomNumberGenerator Equal to 4
                        • Then - Actions
                          • Neutral Building - Add (Random level 4 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • RandomNumberGenerator Equal to 5
                            • Then - Actions
                              • Neutral Building - Add (Random level 5 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • RandomNumberGenerator Equal to 6
                                • Then - Actions
                                  • Neutral Building - Add (Random level 6 Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
                                • Else - Actions
Also I don't quite have a very firm grasp on what is a leak and what leaks and how to optimize them. I figured when I was done the whole map I would go through each trigger manually and fix them then.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You should really check some tutorials about leaks and how to improve your coding.
I would recommend this tutorial for the coding: Efficiency Tutorial
For the leaks, this is a good tutorial: Leak Tutorial #1
Or, one written by myself: Leak Tutorial#2

Yet again you didn't use the best method :s
Well, here is the fixed version:

  • MarketRandomize
  • Events
    • Unit - A unit Finishes casting an ability
  • Conditions
    • (Ability being cast) Equal to Cycle Items
  • Actions
    • For each (Integer A) from 1 to 10 do, (Actions)
      • Loop - Actions
        • Set RandomNumberGenerator = (Random integer number between 1 and 6)
        • For each (Integer B) from 1 to 6 do, (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • RandomNumberGenerator Equal to Integer B
              • Then - Actions
                • Neutral Building - Add (Random level Integer B Any Class item-type) to (Triggering unit) with 1 in stock and a max stock of 1
              • Else - Actions
 
Status
Not open for further replies.
Top