Log in

View Full Version : Calculator for manual dicers (Only cc's with the automatic calculator atm)



yompa93
04-25-2016, 11:09 PM
The script has been updated, look at the comment below.

Hey, i made this calculator thingy and thought there might be other people who wanted it. :confused:

The calculator channel will multiply anything with 1.8 or the chosen rate.
When you pick up crystal coins it will automatically multiply it by 1.8 and print the result, also putting the most recent calc on the HUD, but sadly it does not count platinum coins.

Here's a picture of it:
13556

And here's the code:


Look at the comment below to get the updated script.

yompa93
04-28-2016, 09:12 PM
Updated the script a bit. After you pickup cash or write in the amount to multiply you can now write "w" to multiply the result with the rate(default 1.8)

The script does NOT count platinums when picked up, write the total amount in the channel instead.

Fixed crash when writing letters without any function in the channel.

Formatted the strings.



-- Calculation ----------------------------------------------------------------------------------------------------------
rate = 1.8

function multi(f)
Result1 = f * rate -- value for 'Most recent calculation' in the HUD.
win = Result1 -- Storing the calc result to multiply further when the guy playing is winning.
ProcessDebugMessage('Calculator', ''..f..' * '..rate..' = '.. string.format('%.2f', Result1) ..'k') -- The calculation in the channel.
HudUpdate() -- Updating the HUD values.
end

-- Channel
CalculatorChannel = Channel.Open('Calculator', onSpeak, onClose)
function ProcessDebugMessage(speaker, message)
CalculatorChannel:SendOrangeMessage(speaker, message)
end

ProcessDebugMessage('Calculator', 'Type a figure to multiply with '..rate..' ')
ProcessDebugMessage('Calculator', 'Type "w" to continue counting a winning streak')

registerNativeEventListener(EVENT_SELF_CHANNELSPEE CH, 'onChannelSpeak')
onChannelSpeak = function(channel, message)
local message = message:lower()
if message == "w" then
if win ~= nil then
ProcessDebugMessage(''..c..' ['..level..']', ''..message..'')
winresult = win * rate
win = win * rate
print(''..winresult..'k')
HudUpdate()

ProcessDebugMessage('Calculator', ''.. string.format('%.2f', winresult) ..'k')
else
ProcessDebugMessage(''..c..' ['..level..']', ''..message..'')
print('There is nothing to multiply with '..rate..'')
ProcessDebugMessage('Calculator', 'There is nothing to multiply with '..rate..'')
end
elseif message ~= string.match(message, '%a+') and message > "0" then
ProcessDebugMessage(''..c..' ['..level..']', ''..message..'')
f = message
multi(f)
elseif message == string.match(message, '%a+') then
ProcessDebugMessage(''..c..' ['..level..']', ''..message..'')
end
end

level = Self.Level()
c = Self.Name()

-- HUD -----------------------------------------------------------------------------------------------------------------
local HUDTitle = HUD.CreateTextDisplay(66, 32, "Most recent calculation", 255, 255, 255)


local HUDData = {}
local data = {}
data.update = ""
data.label = HUD.CreateTextDisplay(66, 46 , data.update, 225, 225, 225)
HUDData = data

function HudUpdate()
local update = string.format('%.2f', win)
HUDData.label:SetText(update)
end

-- Auto-Calculation ----------------------------------------------------------------------------------------------------
oldValue = 0
start = 0
Module.New('MoneyCounter', function(mod)
if start == 0 then
oldValue = Self.ItemCount(3043)
start = 1
end
newValue = Self.ItemCount(3043)
if oldValue ~= newValue then
count = newValue - oldValue
if not (newValue < oldValue) then
Result2 = ''.. count * rate * 10 ..'k'
win = count * rate * 10
print(''..Result2..'')
ProcessDebugMessage('Calculator', ''..Result2..'')
HudUpdate()
end
oldValue = Self.ItemCount(3043)
end
mod:Delay(50)
end)
print("Successfully loaded the script.")


13564

Sheradial
04-29-2016, 12:18 AM
Really nice idea!

yompa93
04-29-2016, 12:56 AM
Really nice idea!

Thank you! :D

kamilqq
04-29-2016, 11:09 AM
Use string.format('%.2f', message), because Your code is like 5021521.5210521521521521521521521521K
Didnt used/tested that just looked on code and saw that numbers XD
Thats just my proposal.

yompa93
04-29-2016, 11:49 AM
Use string.format('%.2f', message), because Your code is like 5021521.5210521521521521521521521521K
Didnt used/tested that just looked on code and saw that numbers XD
Thats just my proposal.

I totally agree, i'm not sure how to use that bit of code though. I'm just learning right now :D
Will do some research, thanks :)

EDIT:
Done formatting the string :)