MaurO^ Posted January 10, 2018 Share Posted January 10, 2018 Hello, how can I detect when a player loses or receives money? I want to create a dxRectangle that appears when a player loses or recives money Link to comment
WorthlessCynomys Posted January 10, 2018 Share Posted January 10, 2018 Since in your mods, the only way to get money is by your script giving it, make a function that you can call every time you give money to a player. Link to comment
ShayF2 Posted January 11, 2018 Share Posted January 11, 2018 (edited) -- This code is NOT tested and may need adjustments in order to work properly. -- Client Side local money function moneyChange(oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,0,255,255) end addEventHandler('onClientRender',root,function() local newCash = getPlayerMoney(localPlayer) if not money then money = newCash else if newCash > money or newCash < money then moneyChange(money,newCash) money = newCash end end end) -- Serverside local money = {} function moneyChange(player,oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,player,0,255,255) end setTimer(function() for i,plr in pairs(getElementsByType('player')) do local newCash = getPlayerMoney(plr) if not money[plr] then money[plr] = newCash else if newCash > money[plr] or newCash < money[plr] then moneyChange(plr,money[plr],newCash) money[plr] = newCash end end end end,1000,0) I hope that this has helped you, have a nice day. Edited January 11, 2018 by ShayF 1 Link to comment
MaurO^ Posted January 12, 2018 Author Share Posted January 12, 2018 23 hours ago, ShayF said: -- This code is NOT tested and may need adjustments in order to work properly. -- Client Side local money function moneyChange(oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,0,255,255) end addEventHandler('onClientRender',root,function() local newCash = getPlayerMoney(localPlayer) if not money then money = newCash else if newCash > money or newCash < money then moneyChange(money,newCash) money = newCash end end end) -- Serverside local money = {} function moneyChange(player,oldMoney,newMoney) local inc local change if newMoney > oldMoney then inc = 'raised' change = newMoney-oldMoney elseif newMoney < oldMoney then inc = 'lowered' change = oldMoney-newMoney end outputChatBox('Your money has '..inc..' by '..change..' Balance: '..newMoney,player,0,255,255) end setTimer(function() for i,plr in pairs(getElementsByType('player')) do local newCash = getPlayerMoney(plr) if not money[plr] then money[plr] = newCash else if newCash > money[plr] or newCash < money[plr] then moneyChange(plr,money[plr],newCash) money[plr] = newCash end end end end,1000,0) I hope that this has helped you, have a nice day. thanks, it worked for me 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