Simple math command

This is a simple math command that I made simply because it seemed quite handy.

It lets you do a few basic things any calculator would let you do but the main benefit of this was for the people who have super low-end computers, a couple people on my server lagged like crazy and often crashed their entire system when alt-tabbing out so I made this command so they didn’t have to

Im not that great at coding lua so if you could improve it do post a reply :smiley:

Install:

  • paste it into any client script and restart that resource

how to use:

  • /sum type value1 value2 (e.g /sum add 10 10 - you will get 20 obviously)
  • /sum random

Screenshot_1067


-- Simple Math command | made by Envious
RegisterCommand('sum', function(source, args)
	if args[3] then -- I dont think im doing this bit right but it works for now
		if args[1] == "add" then
			num = args[2] + args[3]
			TriggerEvent('chatMessage', "The value is", {128, 1280, 128}, num)
		elseif args[1] == "div" then
			num = args[2] / args[3]
			TriggerEvent('chatMessage', "The value is", {128, 1280, 128}, num)
		elseif args[1] == "mult" then
			num = args[2] * args[3]
			TriggerEvent('chatMessage', "The value is", {128, 1280, 128}, num)
		elseif args[1] == "perc" then
			num = args[2] / 100 * args[3]
			TriggerEvent('chatMessage', "The value is", {128, 1280, 128}, num)
		elseif args[1] == "sub" then
			num = args[2] - args[3]
			TriggerEvent('chatMessage', "The value is", {128, 1280, 128}, num)
		end
	elseif args[1] then
		if args[1] == "random" then
			math.randomseed(GetGameTimer())
			math.random(); math.random(); math.random();
			num = math.random(1000000,9000000) -- got to make it authentic-ish
			TriggerEvent('chatMessage', "The random number ", {128, 1280, 128}, "SA" ..num.. "2018") --we use this for Gun serial numbers on our server
		else
			TriggerEvent('chatMessage', "^8[System]^0: ^3do /sum div/mult/add/random or perc and then your first and second argument")
		end
	else
		TriggerEvent('chatMessage', "^8[System]^0: ^3do /sum div/mult/add/random or perc and then your first and second argument")
	end
end)

you want to do this to make it so the number is always random

math.randomseed(os.time())
math.random(); math.random(); math.random();
num = math.random(1000000,9000000) -- got to make it authentic-ish

Now add expression evaluation/parsing and order of operations :smiley:

The os.time() didn’t work so i used GetGameTimer() instead, There likely is a better alternative to what I’ve done.

math.randomseed(GetGameTimer())
math.random(); math.random(); math.random();
num = math.random(1000000,9000000) -- got to make it authentic-ish

Could you give me a small example of this?

Might be a tricky one, but a nice challenge. Something like this:

A)

/math “2^(1+3*6) / 2”

Could get converted into singulair instructions:

B)

local a = mul(3, 6)
a = add(a, 1)
a = pow(a, 2)
a = div(a, 2)
a = 262144

Might be a nice challenge for you, evaluate the expression (a) and break it down into instructions (b).
Note that you have to do order of operations correctly.

1 Like

Only works on server side scripts.

1 Like