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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • 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 Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top