Jump to content

How to create this money script?


Turbe$Z

Recommended Posts

If you use setPlayerMoney, you can just do this on client side.

local lastMoney = 0

setTimer(function()
	local playerMoney = getPlayerMoney(localPlayer)
	if playerMoney ~= lastMoney then
		outputChatBox("Your money got " .. (playerMoney < lastMoney and "decreased" or "increased") .. " by " .. math.abs(playerMoney-lastMoney))
	end
	lastMoney = playerMoney
end, 100, 0)

I think this one should work.

Link to comment
22 minutes ago, NeXuS™ said:

If you use setPlayerMoney, you can just do this on client side.


local lastMoney = 0

setTimer(function()
	local playerMoney = getPlayerMoney(localPlayer)
	if playerMoney ~= lastMoney then
		outputChatBox("Your money got " .. (playerMoney < lastMoney and "decreased" or "increased") .. " by " .. math.abs(playerMoney-lastMoney))
	end
	lastMoney = playerMoney
end, 100, 0)

I think this one should work.

how to make this into dx? :/ 

Link to comment
local lastMoney = 0
local drawMoney = nil

setTimer(function()
	local playerMoney = getPlayerMoney(localPlayer)
	if playerMoney ~= lastMoney then
		drawMoney = playerMoney - lastMoney
		if isTimer(resetingTimer) then killTimer(resetingTimer) end
		resetingTimer = setTimer(function()
			drawMoney = nil
		end, 500, 1)
	end
	lastMoney = playerMoney
end, 100, 0)

addEventHandler("onClientRender", getRootElement(), function()
	if drawMoney then
		dxDrawText(drawMoney, 0, 0, 100, 100, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold")
	end
end)

Try this one.

Edited by NeXuS™
  • Like 1
Link to comment
14 minutes ago, NeXuS™ said:

local lastMoney = 0
local drawMoney = nil

setTimer(function()
	local playerMoney = getPlayerMoney(localPlayer)
	if playerMoney ~= lastMoney then
		drawMoney = playerMoney - lastMoney
		if isTimer(resetingTimer) then killTimer(resetingTimer) end
		resetingTimer = setTimer(function()
			drawMoney = nil
		end, 500, 1)
	end
	lastMoney = playerMoney
end, 100, 0)

addEventHandler("onClientRender", getRootElement(), function()
	if drawMoney then
		dxDrawText(drawMoney, 0, 0, 100, 100, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold")
	end
end)

Try this one.

Thanks :D Working.:D But, how to add "+" before lastMoney? The "-" is working, but "+" not :/

Link to comment
6 minutes ago, NeXuS™ said:

dxDrawText((drawMoney > 0 and ("+" .. drawMoney) or drawMoney), 0, 0, 100, 100, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold")

 

local lastMoney = 0
local drawMoney = nil

setTimer(function()
	local playerMoney2 = getPlayerMoney(localPlayer)
	local convertedMoney2 = convertNumber(playerMoney2)
	if playerMoney2 ~= lastMoney then
		drawMoney = playerMoney2 - lastMoney
		if isTimer(resetingTimer) then killTimer(resetingTimer) end
		resetingTimer = setTimer(function()
			drawMoney = nil
		end, 3000, 1)
	end
	lastMoney = playerMoney2
end, 50, 0)

addEventHandler("onClientRender", getRootElement(), function()
	if drawMoney then
		removeEventHandler("onClientRender", root, alappenz)
		dxDrawText((drawMoney > 0 and ("+" .. drawMoney) or drawMoney), screenW * 0.8674, screenH * 0.0389, screenW * 0.9889, screenH * 0.0644, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold", "center", "center")
	end
end)

function convertNumber ( number )  
	local formatted = number  
	while true do      
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1 %2')    
		if ( k==0 ) then      
			break   
		end  
	end  
	return formatted
end

Thanks:D convertNumber why not working? O.o 

Link to comment
function comma_value(n) -- credit http://richard.warburton.it
	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end

Try to use this one instead, this is a better format.

  • Like 1
Link to comment
4 minutes ago, NeXuS™ said:

function comma_value(n) -- credit http://richard.warburton.it	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..rightend

Try to use this one instead, this is a better format.

local lastMoney = 0
local drawMoney = nil

setTimer(function()
	local playerMoney2 = getPlayerMoney(localPlayer)
	local convertedMoney2 = comma_value(playerMoney2)
	if playerMoney2 ~= lastMoney then
		drawMoney = playerMoney2 - lastMoney
		if isTimer(resetingTimer) then killTimer(resetingTimer) end
		resetingTimer = setTimer(function()
			drawMoney = nil
		end, 3000, 1)
	end
	lastMoney = playerMoney2
end, 50, 0)

addEventHandler("onClientRender", getRootElement(), function()
	if drawMoney then
		removeEventHandler("onClientRender", root, alappenz)
		dxDrawText((drawMoney > 0 and ("+" .. drawMoney) or drawMoney), screenW * 0.8674, screenH * 0.0389, screenW * 0.9889, screenH * 0.0644, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold", "center", "center")
	else
		addEventHandler("onClientRender", root, alappenz)
	end
end)

function comma_value(n) -- credit http://richard.warburton.it
	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end

still not working :/

Link to comment

You ain't using the convertedMoney2  variable anywhere.

local lastMoney = 0
local drawMoney = nil

setTimer(function()
	local playerMoney2 = getPlayerMoney(localPlayer)
	if playerMoney2 ~= lastMoney then
		drawMoney = playerMoney2 - lastMoney
		if isTimer(resetingTimer) then killTimer(resetingTimer) end
		resetingTimer = setTimer(function()
			drawMoney = nil
		end, 3000, 1)
	end
	lastMoney = playerMoney2
end, 50, 0)

addEventHandler("onClientRender", getRootElement(), function()
	if drawMoney then
		removeEventHandler("onClientRender", root, alappenz)
		dxDrawText((drawMoney > 0 and ("+" .. comma_value(drawMoney)) or comma_value(drawMoney)), screenW * 0.8674, screenH * 0.0389, screenW * 0.9889, screenH * 0.0644, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold", "center", "center")
	else
		addEventHandler("onClientRender", root, alappenz)
	end
end)

function comma_value(n) -- credit http://richard.warburton.it
	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
end

 

  • Like 1
Link to comment
3 minutes ago, NeXuS™ said:

You ain't using the convertedMoney2  variable anywhere.


local lastMoney = 0local drawMoney = nilsetTimer(function()	local playerMoney2 = getPlayerMoney(localPlayer)	if playerMoney2 ~= lastMoney then		drawMoney = playerMoney2 - lastMoney		if isTimer(resetingTimer) then killTimer(resetingTimer) end		resetingTimer = setTimer(function()			drawMoney = nil		end, 3000, 1)	end	lastMoney = playerMoney2end, 50, 0)addEventHandler("onClientRender", getRootElement(), function()	if drawMoney then		removeEventHandler("onClientRender", root, alappenz)		dxDrawText((drawMoney > 0 and ("+" .. comma_value(drawMoney)) or comma_value(drawMoney)), screenW * 0.8674, screenH * 0.0389, screenW * 0.9889, screenH * 0.0644, drawMoney > 0 and tocolor(0, 255, 0) or tocolor(255, 0, 0), 1, "default-bold", "center", "center")	else		addEventHandler("onClientRender", root, alappenz)	endend)function comma_value(n) -- credit http://richard.warburton.it	local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')	return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..rightend

 

oooh, thank you:D

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...