Creating X Amount of units

Nums

New Member
Reaction score
1
Hey all.

I was wondering if it was possible to create X amount of units, where X is user specified via a chat command.
So a player could type:
-10footmen
spawning 10 footmen, but could also type
-5footmen
spawning 5 instead.

I know I could go through and add each trigger separately but I was wondering if its possible to do this using only one.
 

SpaceBar

New Member
Reaction score
16
I know you can, but i am not 120% sure how you go about it. You can set a random integer.

Code:
~~Events~
Player red types -footmen as a substring
~~Conditions~~
~~Actions~~
Create (random integer between 1 and 10) footmen for player red at (centre of (playable map area)) facing default building facing degrees

Of course this isn't what you wanted but other than that i'm clueless
 

Galdiuz

Creator of Photon Command
Reaction score
98
You need to do it with substrings. Something like this:
Code:
Untitled Trigger 001
    Events
        Player - Player 1 (Red) types a chat message containing -footmen as A substring
    Conditions
    Actions
        Unit - Create (Integer((Substring((Entered chat string), 9, 10)))) Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
 

Zurtrogx

Active Member
Reaction score
24
This first trigger is similar to the one by Galdiuz, but it has no leaks.
This is the normal way to do it:
-function <number>

Example:
-footmen 5

Trigger:
  • Normal
    • Events
      • Player - Player types a chat message containing -footmen as A substring
    • Conditions
    • Actions
      • Set temp_point = YOUR LOCATION
      • Set number = (Integer((Substring((Entered chat string), 9, (Length of (Entered chat string))))))
      • Unit - Create number Footman for (Triggering player) at temp_point facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_temp_point)


With the event, you can set it to either one player, or as many as you want. If you want another player to be able to use this function, simply add that player number/colour into the event.

temp_point is a point variable. Set this to wherever you want the units to spawn.
Make sure to use Custom script: call RemoveLocation (udg_temp_point) at the end to remove leaks.
If you change the variable to another name make sure the change it in the Custom Script as well. If you change it to a_location, then the Custom Script will become:
Custom Script: call RemoveLocation (udg_a_location)

Your way:
-<number>function

Example:
-5footmen

Trigger:
  • Special
    • Events
      • Player - Player types a chat message containing footmen as A substring
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Substring((Entered chat string), 1, 1)) Equal to -
        • Then - Actions
          • Set temp_point = YOUR LOCATION
          • Set number = (Integer((Substring((Entered chat string), 2, (Length of (Entered chat string))))))
          • Unit - Create number Footman for (Triggering player) at temp_point facing Default building facing degrees
          • Custom script: call RemoveLocation (udg_temp_point)
        • Else - Actions

Take note that in this version, the message is footmen (without the -).
The IF part then checks if there is a - is the string. If there is, then it takes the integer of the string, from position 2 (the spot after the -) to the end of the string. Please take note that is numbers are placed AFTER the text, the integer will return as 0.
Examples:
-5footmen = 5
-footmen5 = 0
-12footmen5 = 12 (not 125 or 1205)

So, now you can decide which way to do it.
Either the general way, or your way.

Hope this helps.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Those GUI CreateNUnits will leaks, so use natives "CreateUnit" and loop to prevent leak.
PHP:
 Events
        Player - Player 1 (Red) types a chat message containing -footmen as A substring
    Conditions
    Actions
        local integer min = 1
        local integer max = (Integer((Substring((Entered chat string), 9, 10)))) 
        loop
        exitwhen min>max
             Unit - Create Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
        set min = min + 1
        endloop
 

Exide

I am amazingly focused right now!
Reaction score
448
Those GUI CreateNUnits will leaks, so use natives "CreateUnit" and loop to prevent leak.
PHP:
 Events
        Player - Player 1 (Red) types a chat message containing -footmen as A substring
    Conditions
    Actions
        local integer min = 1
        local integer max = (Integer((Substring((Entered chat string), 9, 10)))) 
        loop
        exitwhen min>max
             Unit - Create Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing (270.0) degrees
        set min = min + 1
        endloop

You should use the correct code tags.
What is your trigger? A weird mixture of JASS and GUI?
 

HydraRancher

Truth begins in lies
Reaction score
197
Heres my trigger, I use it for my map as a testing one.
Trigger:
  • spawn
    • Events
    • Conditions
      • (Substring((Entered chat string), 1, 5)) Equal to (==) spawn
    • Actions
      • Unit - Create (Integer((Substring((Entered chat string), 7, 8)))) (Unit-type((Substring((Entered chat string), 10, (Integer((Entered chat string))))))) for (Triggering player) at (Center of (Playable map area)) facing Default building facing (270.0) degrees

So the command is [spawn 99 footman]
etc.
 

Nums

New Member
Reaction score
1
I don't know much about JASS, I just use the editors GUI and adding those posted above as a custom scripts just gave a whole mess of errors.


How would I do it using the editors GUI?
 

Nums

New Member
Reaction score
1
I tried.
But i sat there for ages looking through the GUI list trying to find the right ones. I found most of the except for ones like

"(Substring((Entered chat string), 1, 1)) Equal to -"
"Set number = (Integer((Substring((Entered chat string), 2, (Length of (Entered chat string))))))"

---

also the "Set number"

Im assuming "number" is a variable? what type?

Sorry for the noobness

---

Finally got it to work!

Thanks heaps :)
 

Nums

New Member
Reaction score
1
Ok, I got another question.
I have multiple triggers to summon each type of unit (footman, frostwyrm, archers, etc)
Is it possible to put a limit on how many can be spawned.

Say the limit was 20
They could summon 20 footman, or 10 footman, 10 frostwyrms, or 10 footman, 5 archers, 5 frostwyrms, etc.
 

Dirac

22710180
Reaction score
147
Create some var like this...

Set NumberOfUnitsSummoned = Y
set Counting = Counting + NumberOfUnitsSummoned
If
Counting greater than X
Then
Set NumberOfUnitsSummoned = Counting - X
Set Counting = X

Create NumberOfUnitsSummoned Footmas at....
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top