[Solved] A trigger removing additional units spawned or Jass condition checking the player's units

Status
Not open for further replies.
Level 6
Joined
Mar 9, 2023
Messages
72
Hi! I have a situation where a trigger which when a button is clicked, gives the player one hero, will sometimes spawn an additional hero. I cannot replicate it, as "double clicking" it is seemingly impossible. I have tried writing a conditional check in the jass script to no avail, and tried a few GUI solutions like hooking up the function to a removal trigger, but have not made it work just yet. I have received the recommendation for a condition checking if the player has more than 1 unit/hero during the "hero pick", but since I'm bad I have not yet made sense of it. Does anyone have a solution off the bat or do I just bruteforce awful workarounds?

Edit: "Probably" solved with the helpful comments! Added a check between the code, and a true boolean in the middle. Hope it will work!
JASS:
if udg_Hero[GetPlayerId(GetTriggerPlayer())] == null then
endif
 
Last edited:
It's a bit radical but you can try something like this:

  • Single Hero
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Set VariableSet Integer = (Integer + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Integer Greater than 1
        • Then - Actions
          • Unit - Remove (Triggering unit) from the game
        • Else - Actions
You might need to disable it afterward if you have a resurrection system otherwise it'll remove your revived hero as it enters the map I think
 
We'd have to see your triggers/code to know where you're making the mistake. The solutions suggested to you should work without problems so it sounds like you're doing something weird. It should be pretty simple logic:

Events
Player presses button
Conditions
Button is enabled = true
Actions
Disable button
Create Hero

The way you "disable" the button can vary. I would personally use a Boolean array and toggle it to True when a hero is chosen:
  • Conditions
    • HasAHero[Player number of buttoner press] Equal to False
  • Actions
    • Set Variable HasAHero[Player number of button presser] = True
    • Unit - Create 1 Hero...
Or better yet, kill two birds with one stone and control the button's behavior as well as link the hero to the player at the same time:
  • Conditions
    • Hero[Player number of buttoner press] Equal to No unit
  • Actions
    • Unit - Create 1 Hero...
    • Set Variable Hero[Player number of button presser] = (Last created unit)
 
Last edited:
Status
Not open for further replies.
Back
Top