JademusSreg

UnitCreateMultiple

Sep 5th, 2011
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. // UnitCreateMultiple creates units of multiple types and quantities and returns a unitgroup containing
  2. // the created units. The format for the unitTypes parameter string is:
  3. // "unittype,quantity unittype,quantity" assuming the default controlChar is ","
  4. // An example of use is:
  5. // "Marine,5 Zealot,3 DudeBro,1"
  6. unitgroup UnitCreateMultiple (string unitTypes, int createStyle, int player, point position, fixed face)
  7. {
  8.     string controlChar = ",";
  9.     string space = " ";
  10.     unitgroup g = UnitGroupEmpty();
  11.     int i = 1;
  12.     string word = StringWord(unitTypes,i);
  13.     while (word != null)
  14.     {
  15.         // replace the word's controlChar with a space
  16.         word = StringReplaceWord(word,controlChar,space,c_stringReplaceAll,false);
  17.         // Create units and add them to the unitgroup g
  18.         UnitGroupAddUnitGroup(g,UnitCreate(StringToInt(StringWord(word,2)),StringWord(word,1),createStyle,player,position,face));
  19.         // increment i and set the next word
  20.         i+=1;
  21.         word = StringWord(unitTypes,i);
  22.     }
  23.     return g;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment