Turbe$Z Posted April 21, 2017 Share Posted April 21, 2017 i want create a script, which output the chatbox, when player get money, but how? For example: "+32526$" Link to comment
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 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
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 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
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 (edited) 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 April 21, 2017 by NeXuS™ 1 Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 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 Working.:D But, how to add "+" before lastMoney? The "-" is working, but "+" not Link to comment
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 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") 1 Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 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? Link to comment
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 What should the convertNumber function do? Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 Just now, NeXuS™ said: What should the convertNumber function do? for example: output 99 999 999 instead of 99999999 Link to comment
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 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. 1 Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 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
NeXuS™ Posted April 21, 2017 Share Posted April 21, 2017 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 1 Link to comment
Turbe$Z Posted April 21, 2017 Author Share Posted April 21, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now