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

Random Unit Available for Training! (BUG)

Status
Not open for further replies.
Level 2
Joined
Feb 22, 2015
Messages
10
I'm currently making a Clash Royale-inspired map.

I tried to make it work like the original game; whenever you begin training a unit, it'll dissapear (unavailable for training) and a new one should show up available to train.

The problem is sometimes when I begin training a unit, it dissapears from training but the new unit doesn't become available to train.

These are the current triggers:

This one is to set the units available to train. By default, you can train Footman, Archer, Rifleman, and Mortar Team.

  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set RandomUnit[1] = Footman
    • Set RandomUnit[2] = Archer
    • Set RandomUnit[3] = Rifleman
    • Set RandomUnit[4] = Mortar Team
    • Set RandomUnit[5] = Giant
    • Set RandomUnit[6] = Bandit
    • Set RandomUnit[7] = Spearman
    • Set RandomUnit[8] = Skeleton
    • Set RandomUnit[9] = Golem
    • Set RandomUnit[10] = Wizard
    • Set RandomUnit[11] = Baby Dragon
    • Set RandomUnit[12] = Knight
    • Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
      • Loop - Actions
        • Player - Make RandomUnit[5] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[6] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[7] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[8] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[9] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[10] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[11] Unavailable for training/construction by (Picked player)
        • Player - Make RandomUnit[12] Unavailable for training/construction by (Picked player)
    • Wait 0.01 seconds
    • Trigger - Turn off (This trigger)
This one is to randomize the new unit available for training.

  • Events
    • Unit - A unit Begins training a unit
  • Conditions
  • Actions
    • Wait 0.01 seconds
    • Player - Make (Trained unit-type) Unavailable for training/construction by (Owner of (Triggering unit))
    • Player - Make RandomUnit[(Random integer number between 1 and 12)] Available for training/construction by (Owner of (Triggering unit))
And this one: (Custom Spawn) I thought it might have something to do with it. What this trigger does is teleport the last trained unit to the exact spot where you put the rally-point before training.

  • Events
    • Unit - A unit Finishes training a unit
  • Conditions
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Owner of (Triggering unit)) Equal to Player 1 (Red)
      • Then - Actions
        • Set Temp_Unit_1 = (Trained unit)
        • Set Temp_Loc_1 = (Rally-Point of (Triggering unit) as a point)
        • Unit - Move Temp_Unit_1 instantly to Temp_Loc_1
        • Custom script: call RemoveLocation(udg_Temp_Loc_1)
      • Else - Actions
        • Do nothing
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Owner of (Triggering unit)) Equal to Player 2 (Blue)
      • Then - Actions
        • Set Temp_Unit_2 = (Trained unit)
        • Set Temp_Loc_2 = (Rally-Point of (Triggering unit) as a point)
        • Unit - Move Temp_Unit_2 instantly to Temp_Loc_2
        • Custom script: call RemoveLocation(udg_Temp_Loc_2)
      • Else - Actions
        • Do nothing

If someone could please help me fix this problem, it would be very much appreciated.

Here's the link to my map in case you didn't understand how the gameplay works:

http://www.hiveworkshop.com/forums/maps-564/warcraft-royale-v1-0-4-a-276874
 
Level 12
Joined
Jan 2, 2016
Messages
973
Well, it's quite simple, really.
It just makes available the training of a unit, which is already enabled.
You need 2 lists:
"Enabled", and "Disabled".
1-st enable a unit from "Disabled" and then disable the unit-type of the trained unit, so the random chance doesn't re-enable it :p

It would look something like this:
Initialization:
Set Enabled[1] = Footman
Set Enabled[2] = Archer
Set Enabled[3] = Rifleman
Set Enabled[4] = Mortar Team
Set Disabled[1] = Giant
.............
Set Disabled[8] = Knight

Then when you begin training a unit do:
Set Enabled[0] = Trained unit-type
Wait 0.00 seconds
Loop from 1 to EnabledAmount
if Enabled[0] is equal to Enabled[Loop] then
set TempInteger = Loop
----- endloop -----
Disable training of Enabled[0]
Set Dice = Random Integer from 1 to DisabledAmount
Set Enabled[TempInteger] = Disabled[Dice]
Enable training of Disabled[Dice]
Set Disabled[Dice] = Enabled[0]
 
Last edited:
Level 2
Joined
Feb 22, 2015
Messages
10
I've never thought of that, it seems to be working fine now! But I have a question: the Loop has to be exactly from 1 to 4? I mean, if I want to add more available units I just need to set the new range of Random Integers from Dice right?

Thank you very much for your help btw!
 
Level 12
Joined
Jan 2, 2016
Messages
973
The loop is from 1 to 'the amount of enabled units'.
I wrote 4, cuz you have 4 enabled units. If you want to have more enabled at the same time later on, then you need to use some variable.
Loop from 1 to IntegerVariable, which is initially 4 (for example)
And when you want to increase/decrease the amount of Enabled (at once) units - set it to the new value.

But do have in mind, that you will also need such variable for the amount of disabled units, so every time you increase this variable - you decrease the other.
And when you increase the enabled units - don't forget to assign some values to the newly opened positions.
Example:
set EnabledAmount = EnabledAmount + 1
set Dice = Random Integer from 1 to DisabledAmount
set Enabled[EnabledAmount] = Disabled[Dice]
set Disabled[Dice] = Disabled[DisabledAmount]
set DisabledAmount = DisabledAmount - 1

I also edited my previous post, so you can see how it'd look like now (+ moved the loop after the wait, so TempInteger wouldn't have a change to get overwritten) :p
 
Status
Not open for further replies.
Top