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 :
library SpawnUnitByChat requires Ascii initializer init
globals
private constant string KEY = "-spawn"
private constant player PLAYER = Player(0) // first player (red)
private constant real X = 0
private constant real Y = 0
endglobals
private function Actions takes nothing returns nothing
local string chat = GetEventPlayerChatString()
local integer i = -1
local string s = ""
local string unitid = ""
local string count = ""
chat = SubString(chat,StringLength(KEY)+1,StringLength(chat))
loop
set i = i+1
set s = SubString(chat,i,i+1)
exitwhen s == " " or s == null
set unitid = unitid+s
endloop
loop
set i = i+1
set s = SubString(chat,i,i+1)
exitwhen s == " " or s == null
set count= count+s
endloop
set i = S2I(count)
loop
set i = i-1
call CreateUnit(PLAYER,S2A(unitid),X,Y,0)
exitwhen i <= 0
endloop
endfunction
private function init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterPlayerChatEvent(trig,PLAYER,KEY,false)
call TriggerAddAction(trig,function Actions)
endfunction
endlibraryNote 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 ...