• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Secret messages

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I made this script while testing out some string functions,
I guess this can be used for some sort of secret language or something.

The script basically turns up to 8 characters into bytes.
words must be seperated by a ",".

The script will also convert bytes to characters.
bytes must be seperated by ",".

Lua:
<talkaction words="!tobytes;!frombytes;!reverse" event="script" value="SCRIPT_NAME.lua"/>

Lua:
  function onSay(cid, words, param, channel)
 
    if(param == '') then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
    end

    if words == "!tobytes" then
        local ret = ''
        for str = 1, param:len() do
            ret = ret .. param:sub(str, str):byte() .. ", "
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    elseif words == "!frombytes" then
        local ret = ''
        for _, s in ipairs(string.explode(param, ",")) do
            ret = ret .. string.char(tonumber(s))
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    elseif words == "!reverse" then
			doPlayerSendTextMessage(cid,20,'REVERSAL\nNormal: \''..param..'\' \nReversal: '..string.reverse(param))
	end
    return true
end
fixed by Jano

Example.

Code:
!tobytes whats up

will be

Code:
119,104,97,116,115,32,117,112

and

Code:
!frombytes 119,104,97,116,115,32,117,112

will be

Code:
whats up

Yours,
unknown666

#Edit
Added "!reverse" command.

E.g.
Code:
!reverse hello otland[code]

will be this

[code][COLOR="black"]REVERSAL
Normal: 'hello otland' 
Reversal: 'dnalto olleh'[/COLOR]
 
Last edited:
Code:
function onSay(cid, words, param, channel)
 
    if(param == '') then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
    end

    if words == "!tobytes" then
        local ret = ''
        for str = 1, param:len() do
            ret = ret .. param:sub(str, str):byte() .. ", "
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    elseif words == "!frombytes" then
        local ret = ''
        for _, s in ipairs(string.explode(param, ",")) do
            ret = ret .. string.char(tonumber(s))
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    end
    return true
end

no limit and no need to write like "w,h,a,t"
 
Hmm, I forgot about string.len() :$.

Just a question,
what does string.sub() do, because I don't really understand it's meaning in lua wiki.
 
Hmm, I forgot about string.len() :$.

Just a question,
what does string.sub() do, because I don't really understand it's meaning in lua wiki.

from lua.org

string.sub (s, i [, j])

Returns the substring of s that starts at i and continues until j.
 
Code:
function onSay(cid, words, param, channel)
 
    if(param == '') then
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
    end

    if words == "!tobytes" then
        local ret = ''
        for str = 1, param:len() do
            ret = ret .. param:sub(str, str):byte() .. ", "
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    elseif words == "!frombytes" then
        local ret = ''
        [b]for _, s in ipairs(string.explode(param, ",")) do[/b]
            ret = ret .. string.char(tonumber(s))
        end
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ret)
    end
    return true
end

no limit and no need to write like "w,h,a,t"
bug?:
Code:
string.explode = function (str, sep, limit)
	if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
		return {}
	end

	local i, pos, tmp, t = 0, 1, "", {}
	for s, e in function() return string.find(str, sep, pos) end do
		tmp = str:sub(pos, s - 1):trim()
		table.insert(t, tmp)
		pos = e + 1

		i = i + 1
		if(limit ~= nil and i == limit) then
			break
		end
	end

	tmp = str:sub(pos):trim()
	table.insert(t, tmp)
	return t
end
u cant loop it unless its like this:
Code:
return {t = t}
ur code will raise an error "bad arg etc etc table expected got function value etc etc"
 
bug?:
Code:
string.explode = function (str, sep, limit)
    if(type(sep) ~= 'string' or isInArray({tostring(str):len(), sep:len()}, 0)) then
        return {}
    end

    local i, pos, tmp, t = 0, 1, "", {}
    for s, e in function() return string.find(str, sep, pos) end do
        tmp = str:sub(pos, s - 1):trim()
        table.insert(t, tmp)
        pos = e + 1

        i = i + 1
        if(limit ~= nil and i == limit) then
            break
        end
    end

    tmp = str:sub(pos):trim()
    table.insert(t, tmp)
    return t
end
u cant loop it unless its like this:
Code:
return {t = t}
ur code will raise an error "bad arg etc etc table expected got function value etc etc"

dont try to teach me, noob
 
Added "!reverse" command to the script,
will probably keep updating this script as I'm learning string functions
 
Back
Top