Solved how to make calculator in skript?

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

shlumbis_

Member
Feb 21, 2024
2
1
3
So basically i need a calculator for my idiot friends to use, the command needs to work like this /calc 1 + 1 and the answer is the result of those, and i dont just need one "+", i need multiplying, subtracting and deviding too.
Big Pre Thanks :emoji_grinning:
 
Im sure this will work, didnt test it in game since im on phone.


Code:
command /calc <number> <text> <number>:
    trigger:
        if arg-2 is "+":
            set {_n1} to arg-1
            set {_n2} to arg-3
            set {_r} to ({_n1} + {_n2})
            send "&8[&bMATH&8] &6%{_r}%" to player
        else if arg-2 is "-":
            set {_n1} to arg-1
            set {_n2} to arg-3
            set {_r} to ({_n1} - {_n2})
            send "&8[&bMATH&8] &6%{_r}%" to player
        else if arg-2 is "*":
            set {_n1} to arg-1
            set {_n2} to arg-3
            set {_r} to ({_n1} * {_n2})
            send "&8[&bMATH&8] &6%{_r}%" to player
        else if arg-2 is "/":
            set {_n1} to arg-1
            set {_n2} to arg-3
            set {_r} to ({_n1} / {_n2})
            send "&8[&bMATH&8] &6%{_r}%" to player
        else:
            send "&8[&bMATH&8] &cCorrect usage: 1 + 1" to player
            
on tab complete of "/calc":
    set tab completions for position 1 to "<number>"
    set tab completions for position 2 to "+", "-", "/" and "*"
    set tab completions for position 3 to "<number>"
 
  • Love
Reactions: shlumbis_
this is probably necroposting, but the method that they gave you can easily be used to crash the server you run it on

i suggest limiting the number lengths/values
 
this is probably necroposting, but the method that they gave you can easily be used to crash the server you run it on

i suggest limiting the number lengths/values

Hey there! This code is used by three servers, one of which has 4,000 daily players. So far, my code has not caused any of the servers to crash, and it doesn't seem logical to assume it would. As you can see, everything is stored locally and then deleted; the code checks each item individually, ensuring optimal performance. I'm not sure why you would think it might crash a server.
 
Code:
# Settings
variables:
    {p} = "&8[&7Calc] &b"

# Code
command /calc <int> <text> <int>:
    permission: example.calc
    permission message: &cYou are not allowed to do that!
    usage: &cInvalid usage! Usage: /calc Number Operator Number
    trigger:
        if arg-2 is "+" or "-" or "*" or "/":
            if arg-2 is "+":
                {math} = arg-1 + arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "-":
                {math} = arg-1 - arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "*":
                {math} = arg-1 * arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "/":
                {math} = arg-1 / arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
        else:
            send "&cInvalid operator!"
 
Code:
# Settings
variables:
    {p} = "&8[&7Calc] &b"

# Code
command /calc <int> <text> <int>:
    permission: example.calc
    permission message: &cYou are not allowed to do that!
    usage: &cInvalid usage! Usage: /calc Number Operator Number
    trigger:
        if arg-2 is "+" or "-" or "*" or "/":
            if arg-2 is "+":
                {math} = arg-1 + arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "-":
                {math} = arg-1 - arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "*":
                {math} = arg-1 * arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
            else if arg-2 is "/":
                {math} = arg-1 / arg-3
                echo "%{p}% %arg-1%%arg-2%%arg-3%=%{math}%"
        else:
            send "&cInvalid operator!"

The issue with your code lies in the use of echo, which is not part of Skript's native (vanilla) syntax. Additionally, you haven't specified any required addons that would support this functionality, making the script incompatible with a standard Skript installation.