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

does anyone know

Status
Not open for further replies.
Level 3
Joined
May 12, 2012
Messages
59
im trying to fix a trigger to prevent cheating from going on by being two species, i have it set up to purchase the species from a store that sets it up and that all works out just fine, but to prevent cheating its set up to remove the purchased unit and add the cost to the players gold amount, that also works fine. the issue i have is adding the purchased unit back to the market place based off its current inventory for that unit.

i found this,
  • Neutral Building - Add Footman to (Triggering unit) with 0 in stock and a max stock of 1
but no way to add the unit based off the inventory. so my question is:

How do you find the current value of the stock so i can use the arithmetic functions so it doesnt get all screwy. Ive tried looking to set it as an integer but to no avail as well as adding the units via trigger at the start of the game based off an integer value also to no avail, any thoughts?

im wanting to use this same fix to allow computer players for a decent but not great game but i cant get it to work
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
if you're really into counting the stocks then you might want to do this. but i don't know a better way of doing this. here is the triggers, i'm taking Goblin Sapper as an example

the current stock settings for Goblin Sapper is

Stats - Stock Maximum = 3 (Maximum Stocks of Goblin Sapper)
Stats - Stock Replenish Interval = 5 (the times needed to replenish 1 stock of Goblin Sapper)
Stats - Stock Start Delay = 0 (the times needed to fill the stock maximum of Goblin Sapper)

and i'm using a Unit Indexer by Bribe

Melee Initialization

UnitIndexer

Counting Stocks

Stock Replenish

Global Interval

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set SapperStock = 3
  • Unit Indexer
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call ExecuteFunc("InitializeUnitIndexer")
      • Custom script: endfunction
      • -------- --------
      • -------- This is the most important function - it provides an index for units as they enter the map --------
      • -------- --------
      • Custom script: function IndexUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • -------- --------
      • -------- You can use the boolean UnitIndexerEnabled to protect some of your undesirable units from being indexed --------
      • -------- - Example: --------
      • -------- -- Set UnitIndexerEnabled = False --------
      • -------- -- Unit - Create 1 Dummy for (Triggering player) at TempLoc facing 0.00 degrees --------
      • -------- -- Set UnitIndexerEnabled = True --------
      • -------- --------
      • -------- You can also customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UnitIndexerEnabled Equal to True
        • Then - Actions
          • -------- --------
          • -------- Generate a unique integer index for this unit --------
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • UDexRecycle Equal to 0
            • Then - Actions
              • Set UDex = (UDexGen + 1)
              • Set UDexGen = UDex
            • Else - Actions
              • Set UDex = UDexRecycle
              • Set UDexRecycle = UDexNext[UDex]
          • -------- --------
          • -------- Link index to unit, unit to index --------
          • -------- --------
          • Set UDexUnits[UDex] = (Matching unit)
          • Unit - Set the custom value of UDexUnits[UDex] to UDex
          • -------- --------
          • -------- Use a doubly-linked list to store all active indexes --------
          • -------- --------
          • Set UDexPrev[UDexNext[0]] = UDex
          • Set UDexNext[UDex] = UDexNext[0]
          • Set UDexNext[0] = UDex
          • -------- --------
          • -------- Fire index event for UDex --------
          • -------- --------
          • Set UnitIndexEvent = 0.00
          • Set UnitIndexEvent = 1.00
          • Set UnitIndexEvent = 0.00
          • Custom script: set udg_UDex = pdex
        • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function is called each time a unit enters the map --------
      • -------- --------
      • Custom script: function IndexNewUnit takes nothing returns boolean
      • Custom script: local integer pdex = udg_UDex
      • Custom script: local integer ndex
      • -------- --------
      • -------- Recycle indices of units no longer in-play every (15) units created --------
      • -------- --------
      • Set UDexWasted = (UDexWasted + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • UDexWasted Equal to 15
        • Then - Actions
          • Set UDexWasted = 0
          • Set UDex = UDexNext[0]
          • Custom script: loop
          • Custom script: exitwhen udg_UDex == 0
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of UDexUnits[UDex]) Equal to 0
            • Then - Actions
              • -------- --------
              • -------- Remove index from linked list --------
              • -------- --------
              • Custom script: set ndex = udg_UDexNext[udg_UDex]
              • Custom script: set udg_UDexNext[udg_UDexPrev[udg_UDex]] = ndex
              • Custom script: set udg_UDexPrev[ndex] = udg_UDexPrev[udg_UDex]
              • Set UDexPrev[UDex] = 0
              • -------- --------
              • -------- Fire deindex event for UDex --------
              • -------- --------
              • Set UnitIndexEvent = 2.00
              • Set UnitIndexEvent = 0.00
              • -------- --------
              • -------- Recycle the index for later use --------
              • -------- --------
              • Set UDexUnits[UDex] = No unit
              • Set UDexNext[UDex] = UDexRecycle
              • Set UDexRecycle = UDex
              • Custom script: set udg_UDex = ndex
            • Else - Actions
              • Set UDex = UDexNext[UDex]
          • Custom script: endloop
          • Custom script: set udg_UDex = pdex
        • Else - Actions
      • -------- --------
      • -------- Handle the entering unit (Matching unit) --------
      • -------- --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Custom value of (Matching unit)) Equal to 0
        • Then - Actions
          • Custom script: call IndexUnit()
        • Else - Actions
      • Custom script: return false
      • Custom script: endfunction
      • -------- --------
      • -------- The next function initializes the core of the system --------
      • -------- --------
      • Custom script: function InitializeUnitIndexer takes nothing returns nothing
      • Custom script: local integer i = 0
      • Custom script: local region re = CreateRegion()
      • Custom script: local rect r = GetWorldBounds()
      • Set UnitIndexerEnabled = True
      • Custom script: call RegionAddRect(re, r)
      • Custom script: call TriggerRegisterEnterRegion(CreateTrigger(), re, Filter(function IndexNewUnit))
      • Custom script: call RemoveRect(r)
      • Custom script: set re = null
      • Custom script: set r = null
      • Custom script: loop
      • Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), Filter(function IndexUnit))
      • Custom script: set i = i + 1
      • Custom script: exitwhen i == 16
      • Custom script: endloop
      • -------- --------
      • -------- This is the "Unit Indexer Initialized" event, use it instead of "Map Initialization" for best results --------
      • -------- --------
      • Set UnitIndexEvent = 3.00
      • Set UnitIndexEvent = 0.00
  • Counting Stocks
    • Events
      • Unit - A unit Sells a unit
    • Conditions
      • (Unit-type of (Sold unit)) Equal to Goblin Sapper
    • Actions
      • Set cv = (Custom value of (Sold unit))
      • Set SapperStock = (SapperStock - 1)
      • Set TriggerCount = (TriggerCount + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TriggerCount Greater than 1
        • Then - Actions
          • Set SapperInterval[cv] = (GlobalSapperInterval + 5.00)
        • Else - Actions
          • Set SapperInterval[cv] = 5.00
      • Set GlobalSapperInterval = (GlobalSapperInterval + 5.00)
      • Unit Group - Add (Sold unit) to SapperGroup
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Stock Replenish <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Stock Replenish <gen>
        • Else - Actions
  • Stock Replenish
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SapperGroup and do (Actions)
        • Loop - Actions
          • Set cv = (Custom value of (Picked unit))
          • Set SapperInterval[cv] = (SapperInterval[cv] - 0.04)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • SapperInterval[cv] Less than or equal to 0.00
            • Then - Actions
              • Set SapperStock = (SapperStock + 1)
              • Set TriggerCount = (TriggerCount - 1)
              • Unit Group - Remove (Picked unit) from SapperGroup
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TriggerCount Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
            • Else - Actions
  • Global Interval
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • GlobalSapperInterval Greater than 0.00
        • Then - Actions
          • Set GlobalSapperInterval = (GlobalSapperInterval - 0.04)
        • Else - Actions
and here is a test map. now you can add an arithmetic stuff by using the current stock of Goblin Sapper (the variable is SapperStock) :D.
 

Attachments

  • Counting Stocks.w3x
    21.8 KB · Views: 48
Last edited:
Level 3
Joined
May 12, 2012
Messages
59
thanks

i appriciate it but after digging around on another website i found out what i was doing wrong and fixed the issue, i needed to have the store not sell anything and add the units via trigger, now i need to fix my AI and ittl be a single player and then finish everything else :vw_unimpressed:

it adds up to success eventually with each accomplished step
 
Level 12
Joined
Sep 11, 2011
Messages
1,176
i appriciate it but after digging around on another website i found out what i was doing wrong and fixed the issue, i needed to have the store not sell anything and add the units via trigger, now i need to fix my AI and ittl be a single player and then finish everything else :vw_unimpressed:

it adds up to success eventually with each accomplished step

i'm glad you found the solution.

happy mapping :D
 
Status
Not open for further replies.
Top