Code (not my, but I fixed small bug):
Code: Select all
function Tokenize( sChar, sInput )
local tReturn = {}
for sWord in string.gmatch( sInput, "[^"..sChar.."]+" ) do
table.insert( tReturn, tonumber(sWord) or sWord )
end
return tReturn
end
function GetTok( sInput, iPosition, Separator, iRange )
local Separator = string.format( '%c', Separator )
local tTokens = Tokenize( Separator, sInput )
if iPosition == 0 then
return sInput
end
local iStart, iStop = ( iPosition > 0 ) and iPosition or ( #tTokens + iPosition + 1 )
if not iRange or iPosition == iRange then
return tTokens[ iStart ]
end
if iRange > 0 then
iStop = iRange
elseif iRange == 0 or ( iStart + iRange ) > #tTokens then
iStop = #tTokens
else
iStop = iStart + iRange + 1
end
if iStart == iStop then
return tTokens[ iStart ]
end
if iStart > iStop then
iStart, iStop = iStop, iStart
end
if (iStart == iPosition) then
return table.concat( tTokens, Separator, iStart, iStop )
end
end
function NumTok(text, C)
local count, tokens = 0, Tokenize(C, text)
for token in tokens:gmatch("%Z+") do count = count+1 end
return count
end
ID's for 'Separator' here (ID 32 = space): http://www.asciitable.com
How it works:
Code: Select all
local info = GetTok("/elo test gettok",0,32)
local info2 = GetTok("/elo test gettok",1,32)
local info3 = GetTok("/elo test gettok",2,32)
local info4 = GetTok("/elo test gettok",3,32)
print(" ")
print(info)
print(info2)
print(info3)
print(info4)
print(" ")
Code: Select all
27/02/2019 17:08:49.567 /elo test gettok
27/02/2019 17:08:49.567 /elo
27/02/2019 17:08:49.567 test
27/02/2019 17:08:49.567 gettok
Code: Select all
function onPlayerCMD(playerid, text)
local vehid = isPlayerInAnyVehicle(playerid)
local cmd = GetTok(text,1,32,1)
if(cmd == "/cmd" or cmd == "/cmds" or cmd == "/komendy") then
--[[
old first cmd line (for compare)
if(string.sub(text, 1, 4) == "/cmd" or string.sub(text, 1, 5) == "/cmds" or string.sub(text, 1, 8) == "/komendy") then
]]--
sendPlayerMsg(playerid,"* List of commands IV-DM:",0xFFFFFFFF)
sendPlayerMsg(playerid,"* /heal, /kill, /skin, /wep, /telpos, /teles",0xFF00FF80)
sendPlayerMsg(playerid,"* /fix, /flip, /randcol, /randcol2, /randcol3, /randcol4, /v",0xFF00FF80)
end
end
registerEvent("onPlayerCMD", "onPlayerCommand")