• 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 Calculator

Mock

Mock the bear (MTB)
Joined
Jul 29, 2008
Messages
619
Reaction score
109
Location
Brazil
  • By Mock
  • Tested on TFS 0.3.6
  • Beta version

This script is not too much unsefull but is fun and good to have in your server
smile.gif


My wold calculator script you only can calc only this:
Code:
1+1
50-40
100/30
60*25
With this version you can calc something like this:
Code:
50-25/37*(10^1)+67^2-3 [COLOR="White"]= 4529.2432432432[/COLOR]
grin.gif


Well to install add this tag:
Code:
<talkaction log="yes" words="!calc" event="script" value="calc.lua"/>
and on calc.lua:
LUA:
function onSay(cid, words, param, channel) --- Calculator beta by mock
	param = param..'€'
	local lua = ''
	for i,sinal,e in param:gmatch('(%(*%d+%.*%d*%)*)%s*([+-/%*^%%])') do
		lua = lua ..i..sinal
	end
	if param:match('.+%s*(%([-]*%d+%)*)€') then
		lua = lua..param:match('.+%s*(%([-]*%d+%)*)€')
	elseif param:match('.+%s*(%(*[-]%d+%.*%d*%)*)€')  then
		if lua:sub(lua:len(),lua:len()) ~= '-' then
			lua = lua..param:match('%l*(%(*[-]%d+%.*%d*%)*)€')
		else
			lua = lua..param:match('%l*(%(*%d+%.*%d*%)*)€')
		end
	elseif param:match('%l*(%(*[-]*%d+%.*%d*%)*)€') then
		lua = lua..param:match('%l*(%(*[-]*%d+%)*)€')
	end
	if lua == '' then
		doPlayerSendTextMessage(cid,25,'Command ['..param..'] invalid.')
		return true
	end
	local f,e = loadstring('return '..lua) -- wop but dont spent 50 lines
	if not f and e then
		doPlayerSendTextMessage(cid,25,'Command ['..lua..'] invalid.')
		return true
	end
	local f,e = pcall(f)
	if not f and e then
		doPlayerSendTextMessage(cid,25,'Command ['..lua..'] invalid.')
		return true
	end
	doCreatureSay(cid,'Calc: '..lua..' = '..tostring(e),1)
	return true
end

unfortunately lua patterns is not powerfull and i got some problems with script and some calcs you cant execute because some bugs
 
niice moock :D
my homework (in mathematics) will be done by your scripter
:p
 
LOL you know a script is good when you don't understand shit on what's happening in it.
anyways Good work man !
 
Hey guys if you find some bugs please send me, i want to fix all
 
Nice, as always! I'm just wondering, what these first ~50 lines does? Is it protection against executing other lua functions?
 
Mock, you've got to be the greatest scripter in otland at the moment?

You're latest scripts have just astonished everybody in this community, I must say I myself am very stunned by your work.

For example, you're the first one in Open Tibia history to ever add sound to your server?
 
@slawkens
nope, to load lua string.
all these patterns is only to player execute 1+1*... not white true do os.exit() end
LUA:
--protection
for i,sinal,e in  param:gmatch('(%(*%d+%.*%d*%)*)%s*([+-/%*^%%])') do
                lua = lua ..i..sinal
        end
        if param:match('.+%s*(%([-]*%d+%)*)€') then
                lua = lua..param:match('.+%s*(%([-]*%d+%)*)€')
        elseif param:match('.+%s*(%(*[-]%d+%.*%d*%)*)€')  then
                if lua:sub(lua:len(),lua:len()) ~= '-' then
                        lua = lua..param:match('%l*(%(*[-]%d+%.*%d*%)*)€')
                else
                        lua = lua..param:match('%l*(%(*%d+%.*%d*%)*)€')
                end
        elseif param:match('%l*(%(*[-]*%d+%.*%d*%)*)€') then
                lua = lua..param:match('%l*(%(*[-]*%d+%)*)€')
        end
without loadstring some players can execute piece of lua code.
@Colandus
i will thx alot if you show me how to short it
wink.gif
 
PHP:
                if lua:sub(lua:len(),lua:len()) ~= '-' then
                        lua = lua..param:match('%l*(%(*[-]%d+%.*%d*%)*)€')
                else
                        lua = lua..param:match('%l*(%(*%d+%.*%d*%)*)€')
                end
replace:
PHP:
lua = lua..param:match((lua:sub(lua:len(),lua:len()) ~= '-') and '%l*(%(*[-]%d+%.*%d*%)*)€' or '%l*(%(*%d+%.*%d*%)*)€')
and can be some shorter with this changes. : P

Btw. Nice calculator : )
 
Back
Top