Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Calculator Mice BY Unlocker001
- -- Use this variable to change language (currently available languages: AR, EN)
- local defaultLanguage = "AR"
- local text = {}
- text.AR = {}
- text.AR.help =
- [[
- : الاوامر
- ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
- <b>!help</b> لإظهار لائحة المساعدة
- <b>!calc</b> إظهار/إخفاء الالة الحاسبة
- <b>!move</b> تسمح لك بتحريك الالة الحاسبة بالضغط على الفأرة
- <b>!Num</b> ادخال الرقم مباشرة
- !مثال: 23423
- <b>!NumOpNum</b> حساب العمليات التي تريد حسابها
- !امثلة: 4+5
- !21*3
- !21x3
- !2-4323
- <b>!pi</b> (3.1415...) لكتابة الرقم بي
- ]]
- text.AR.welcome = ui.addPopup(0, 0, "<font color='#5eb6d6' face='DejaVu Sans Mono' size='30'><p align='center'>الالة الحاسبة</p></font><br><font color='#ffd711' face='DejaVu Sans Mono' size='18'><p align='center'>مرحباً بكم في سكربت الالة الحاسبة ارجوا ان يعجبكم</p><br><p align='center'>اكتب !calc لإظهار/إخفاء الالة الحاسبة و !help لرؤية قائمة الاوامر</p></font><br><font color='#EB1D51' face='DejaVu Sans Mono' size='18'><p align='center'>السكربت معد من طرف</p><br><p align='center'>Unlocker001</p></font>", nil, 97, 69.5, 622, true)
- text.AR.move = ui.addPopup(0, 0, "<font color='#5eb6d6' face='DejaVu Sans Mono' size='30'><p align='center'>التحريك</p></font><br><font color='#ffd711' face='DejaVu Sans Mono' size='18'><p align='center'>لتحريك الالة الحاسبة عليك كتابة</p><br><p align='center'>!move</p></font><br><font color='#EB1D51' face='DejaVu Sans Mono' size='18'><p align='center'>والضغط على المكان التي تريد<br> ان تكون به الالة الحاسبة و اكتب<br>!move<br>لايقاف التحريك</p><br><p ", nil, 479, 27, 305, true)
- text.EN = {}
- text.EN.help =
- [[
- Commands:
- ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
- <b>!help</b> Shows this help
- <b>!calc</b> Shows or hides the calculator
- <b>!move</b> Allows you to move the calculator by clicking
- <b>!Num</b> Directly enters the given number
- Example: !23423
- <b>!NumOpNum</b> Does the desired operation
- Examples: !4+5
- !21*3
- !21x3
- !2-4323
- <b>!pi</b> Enters the PI constant (3.1415...)
- ]]
- text.EN.welcome = ui.addPopup(0, 0, "<font color='#5eb6d6' face='DejaVu Sans Mono' size='30'><p align='center'>Calculator</p></font><br><font color='#ffd711' face='DejaVu Sans Mono' size='18'><p align='center'>Welcome to Calculator Script, I hope you like </p><br><p align='center'>Type !calc to show or hide the calculator and !help to see a list of commands.</p></font><br><font color='#EB1D51' face='DejaVu Sans Mono' size='18'><p align='center'>by</p><br><p align='center'>Unlocker001</p></font>", nil, 137, 60, 554, true)
- text.EN.move = ui.addPopup(0, 0, "<font color='#5eb6d6' face='DejaVu Sans Mono' size='30'><p align='center'>Moving</p></font><br><font color='#ffd711' face='DejaVu Sans Mono' size='18'><p align='center'>To move the calculator type :</p><br><p align='center'>!move</p></font><br><font color='#EB1D51' face='DejaVu Sans Mono' size='18'><p align='center'>and click anywhere on the screen to move the calculator.<br>Type '!move'<br>again when you're done.</p><br><p ", nil, 486.5, 28, 305, true)
- local mice = {}
- local buttonText = {
- "7","8","9","/",
- "4","5","6","x",
- "1","2","3","-",
- "0",".","?","+",
- "C","<","="
- }
- local buttonCallback = {
- "number7", "number8", "number9", "divide",
- "number4", "number5", "number6", "times",
- "number1", "number2", "number3", "minus",
- "number0", "point", "random", "plus",
- "clear", "delete", "equal"
- }
- local operator = {
- divide = "/",
- times = "x",
- minus = "-",
- plus = "+"
- }
- function main()
- for name in pairs(tfm.get.room.playerList) do
- eventNewPlayer (name)
- end
- system.disableChatCommandDisplay ("help")
- system.disableChatCommandDisplay ("calc")
- system.disableChatCommandDisplay ("move")
- system.disableChatCommandDisplay ("pi")
- end
- function eventNewPlayer (name)
- mice[name] = {}
- mice[name].calcShown = false
- mice[name].data = {0,nil,nil}
- mice[name].moveCalc = false
- mice[name].calc={
- x = 20,
- y = 40
- }
- showMessage (getTrans().welcome, name)
- system.bindMouse (name, true)
- end
- function showCalc (name)
- mice[name].calcShown = true
- local x0 = mice[name].calc.x
- local y0 = mice[name].calc.y
- ui.addTextArea (10, "", name, x0, y0, 184, 300, nil, nil, 0.6)
- ui.addTextArea (11, "", name, x0 + 20, y0 + 20, 144, 40, nil, nil, 0.2)
- refreshCalc (name)
- for j=0,4 do
- for i=1,4 do
- local n = 4*(j) + i
- local text = string.format ("<a href='event:%s'><p align='center'><font size='14'>%s</font></p></a>", buttonCallback[n], buttonText[n])
- if j==4 and i==3 then
- ui.addTextArea (20 + n, text, name, x0+20 + (i-1)*40, y0+90 + j*40, 64, 24, nil, nil, 0.4)
- break
- else
- ui.addTextArea (20 + n, text, name, x0+20 + (i-1)*40, y0+90 + j*40, 24, 24, nil, nil, 0.4)
- end
- end
- end
- end
- function refreshCalc (name)
- local data = mice[name].data
- local op = data[2] and operator[data[2]] or ""
- local text = string.format ("<font size='14'><TD>%s<br>%s %s</TD></font>", data[1] or "MATH ERROR", op, data[3] or "")
- ui.updateTextArea (11, text, name)
- end
- function hideCalc (name)
- mice[name].calcShown = false
- for i=10,11 do
- ui.removeTextArea (i, name)
- end
- for i=21,39 do
- ui.removeTextArea (i, name)
- end
- end
- function eventTextAreaCallback (id, name, callback)
- local data = mice[name].data
- if callback:sub(1,6) == "number" and tonumber(callback:sub(7,-1)) then
- local digit = tonumber(callback:sub(7,-1))
- if not data[2] and not data[3] then
- mice[name].data[1] = tonumber((data[1] or 0) .. digit)
- else
- mice[name].data[3] = tonumber((data[3] or 0) .. digit)
- end
- elseif callback == "divide" or callback == "times" or callback == "minus" or callback == "plus" then
- if not data[3] then
- mice[name].data[2] = callback
- else
- calculate (name)
- mice[name].data[2] = callback
- end
- elseif callback == "equal" then
- calculate (name)
- elseif callback == "clear" then
- mice[name].data[1] = 0
- mice[name].data[2] = nil
- mice[name].data[3] = nil
- elseif callback == "delete" and data[1] then
- if data[3] then
- mice[name].data[3] = tonumber (string.sub(data[3], 1, -2)) or 0
- elseif not data[2] then
- mice[name].data[1] = tonumber (string.sub(data[1], 1, -2)) or 0
- end
- end
- refreshCalc(name)
- end
- function calculate (name)
- data = mice[name].data
- local result
- if not data[2] or not data[3] then
- result = data[1]
- else
- if data[2] == "divide" then
- if data[3] == 0 then
- result = nil
- else
- result = data[1] / data[3]
- end
- elseif data[2] == "times" then
- result = data[1] * data[3]
- elseif data[2] == "minus" then
- result = data[1] - data[3]
- elseif data[2] == "plus" then
- result = data[1] + data[3]
- end
- end
- mice[name].data[1] = result
- mice[name].data[2] = nil
- mice[name].data[3] = nil
- end
- function eventChatCommand (name, mes)
- if mes == "calc" then
- toggleCalc(name)
- -- debug
- --elseif mes == "data" then
- -- print ((mice[name].data[1] or "Nil") .. " " .. (mice[name].data[2] or "Nil") .. " " .. (mice[name].data[3] or "Nil"))
- elseif mes == "move" then
- if mice[name].moveCalc then
- mice[name].moveCalc = false
- else
- mice[name].moveCalc = true
- showMessage (getTrans().move, name)
- end
- elseif mes == "help" then
- showMessage (getTrans().help, name, 400)
- elseif mice[name].calcShown and tonumber(mes) then
- enterNumber (name, tonumber(mes))
- refreshCalc(name)
- elseif mice[name].calcShown and mes == "pi" then
- enterNumber (name, math.pi)
- refreshCalc(name)
- elseif mice[name].calcShown then
- local n1, op, n2
- n1, op, n2 = mes:match ("(%d+)([%-%+/%*x])(%d+)")
- if n1 and op and n2 then
- mice[name].data[1] = n1
- mice[name].data[2] = operatorName(op)
- mice[name].data[3] = n2
- calculate(name)
- refreshCalc(name)
- end
- end
- end
- function operatorName (operator)
- if operator == "/" then
- return "divide"
- elseif operator == "*" or operator == "x" then
- return "times"
- elseif operator == "-" then
- return "minus"
- elseif operator == "+" then
- return "plus"
- end
- end
- function enterNumber (name, number)
- local data = mice[name].data
- if not data[2] and not data[3] then
- mice[name].data[1] = number
- else
- mice[name].data[3] = number
- end
- end
- function toggleCalc(name)
- if mice[name].calcShown then
- hideCalc(name)
- else
- showCalc(name)
- end
- end
- function eventMouse (name, mx, my)
- if mice[name].moveCalc then
- mice[name].calc.x = mx
- mice[name].calc.y = my
- showCalc (name)
- end
- end
- function showMessage (message, name, width)
- if not width then width = 200 end
- ui.addPopup (0, 0, message, name, 780 - width, 40, width)
- end
- function getTrans ()
- local com = tfm.get.room.community
- if text[com] then
- return text[com]
- else
- return text[defaultLanguage]
- end
- end
- main()
Add Comment
Please, Sign In to add comment