You have still to convert the string in a valid integer.
It can be done of course, but it's not straight forward, for example 'hpea' (human peasant) is not a decimal base.
Hopefully there is already a resource for that :
http://www.hiveworkshop.com/forums/jass-resources-412/snippet-ascii-190746/Ok, here we go :
| 1 | library SpawnUnitByChat requires Ascii initializer init |
| 2 | |
| 3 | globals |
| 4 | private constant string KEY = "-spawn" |
| 5 | private constant player PLAYER = Player(0) // first player (red) |
| 6 | private constant real X = 0 |
| 7 | private constant real Y = 0 |
| 8 | endglobals |
| 9 | |
| 10 | private function Actions takes nothing returns nothing |
| 11 | local string chat = GetEventPlayerChatString() |
| 12 | local integer i = -1 |
| 13 | local string s = "" |
| 14 | local string unitid = "" |
| 15 | local string count = "" |
| 16 | |
| 17 | chat = SubString(chat,StringLength(KEY)+1,StringLength(chat)) |
| 18 | loop |
| 19 | set i = i+1 |
| 20 | set s = SubString(chat,i,i+1) |
| 21 | exitwhen s == " " or s == null |
| 22 | set unitid = unitid+s |
| 23 | endloop |
| 24 | |
| 25 | loop |
| 26 | set i = i+1 |
| 27 | set s = SubString(chat,i,i+1) |
| 28 | exitwhen s == " " or s == null |
| 29 | set count= count+s |
| 30 | endloop |
| 31 | |
| 32 | set i = S2I(count) |
| 33 | loop |
| 34 | set i = i-1 |
| 35 | call CreateUnit(PLAYER,S2A(unitid),X,Y,0) |
| 36 | exitwhen i <= 0 |
| 37 | endloop |
| 38 | |
| 39 | endfunction |
| 40 | |
| 41 | private function init takes nothing returns nothing |
| 42 | local trigger trig = CreateTrigger() |
| 43 | |
| 44 | call TriggerRegisterPlayerChatEvent(trig,PLAYER,KEY,false) |
| 45 | call TriggerAddAction(trig,function Actions) |
| 46 | endfunction |
| 47 | |
| 48 | endlibrary |
Note that i've written the code directly here, not tested, it could have errors, also you need to follow
exactly this pattern :
-spawn unitid X
Where X is the numbers of units (optional).
We could improve the script and allow or not more spaces between the arguments, and add safety, but oh well i have not found an interesting string parsing library, so meh ...