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
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top