split_text {
; Usage: /split_text <formatted string>
; eg. /split_text Rome, "Saudi Arabia", Sweden black pistol, machine gun
var %input = $regsubex($1-, /\s*\x2c\s*/g, $chr(44))
%input = $regsubex(%input, /(?<=^|\x2c)(?:(\w+)|"([^"]+)")\s+([^\x2c]+)/, $+(\1,$cr,\2))
var %cities = $gettok(%input, 1, 13), %weapons = $gettok(%input, 2, 13), %weapon
var %i = $numtok(%cities, 44), %weaponcount = $numtok(%weapons, 44), %city
while %i {
%city = $replace($noqt($gettok(%cities, %i, 44)), $chr(32), _)
%j = 1
while %j <= %weaponcount {
%weapon = $gettok(%weapons, %j, 44)
.hadd -m Items %city $addtok($hget(Items, %city), %weapon, 44)
inc %j
}
dec %i
}
}