BriGhtx3 Posted January 11, 2012 Share Posted January 11, 2012 Is it possible to create something that when the amount of money changes, it automaticly saves it? I know that I can use a timer, but I mean sth like a handler Link to comment
GanJaRuleZ Posted January 11, 2012 Share Posted January 11, 2012 Well you can make for yourself too .. Here are is my suggestion : onClientRender You use this as a event handler , for the function , and you must script that everytime it saves the amount of the money Link to comment
Thelastride Posted January 11, 2012 Share Posted January 11, 2012 Here function DXdraw() sWidth, sHeight = guiGetScreenSize() dxDrawText("Money "..tostring (getPlayerMoney(getLocalPlayer()),40,40,sWidth,sHeight,tocolor(0,255,0,255),1.5,"pricedown","right","top",false,false,false) end addEventHandler("onClientRender", getRootElement(), DXdraw) Link to comment
BriGhtx3 Posted January 11, 2012 Author Share Posted January 11, 2012 Hmm alright, would be nice if there was a single Handler but ok Thanks Link to comment
BriGhtx3 Posted January 11, 2012 Author Share Posted January 11, 2012 New problem : I'm trying to show the players country but it always returns false. function setLand() local flag = exports['admin']:getPlayerCountry ( source ) outputChatBox(tostring(flag)) if flag then setElementData(source,"Land",":admin/client/images/flags/"..flag..".png") else setElementData(source,"Land","N/A") end end addEventHandler("onPlayerJoin",getRootElement(), setLand) The country is always set to N/A. I'm living in Germany Link to comment
CapY Posted January 11, 2012 Share Posted January 11, 2012 You need to edit SCOREBOARD resource for that. Link to comment
BriGhtx3 Posted January 11, 2012 Author Share Posted January 11, 2012 I already did it, but it never worked. Edited line 705 added if column.name.... But it still doesn't show it, neither put out the country. Link to comment
BinSlayer1 Posted January 11, 2012 Share Posted January 11, 2012 Money doesn't change out of the blue.. Money only changes when you tell the script to use setPlayerMoney, givePlayerMoney or takePlayerMoney Everytime you use either of those functions, launch your own custom event "onMoneyChange", eventually passing the current money or whatever you like as parameters. use triggerEvent() https://wiki.multitheftauto.com/wiki/TriggerEvent E.g: In case you use givePlayerMoney(player, 300), do this afterwards: triggerEvent ('onMoneyChange', player, getPlayerMoney(player)) PS: You can scrap passing getPlayerMoney, I'm just showing an example Link to comment
Castillo Posted January 12, 2012 Share Posted January 12, 2012 local oldMoney = getPlayerMoney() function renderMoney() newMoney = getPlayerMoney() if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) oldMoney = newMoney end end addEventHandler("onClientRender",root,renderMoney) addEvent("onClientMoneyChange",true) addEventHandler("onClientMoneyChange",root, function (old, new) outputChatBox(tostring(old) ..": ".. tostring(new)) end) Seems to work just fine. Link to comment
codeluaeveryday Posted January 12, 2012 Share Posted January 12, 2012 Solidsnake just created the onMoneyChange event handler Great job, is it ok if I implement this in one of my scripts? Link to comment
Castillo Posted January 12, 2012 Share Posted January 12, 2012 Sure, if it works without any problem, then I see no problem on someone using it. Link to comment
Kenix Posted January 12, 2012 Share Posted January 12, 2012 (edited) Client addEvent( "onClientMoneyChange",true ) addEventHandler( "onClientMoneyChange",root, function( oldMoney,newMoney ) -- .... end ) function _givePlayerMoney( ... ) local args = { ... } if type( args[1] ) == "number" then if triggerEvent( "onClientMoneyChange",localPlayer,getPlayerMoney( ),args[1] ) and givePlayerMoney( ... ) then return true end return false end end Edited January 12, 2012 by Guest Link to comment
BinSlayer1 Posted January 12, 2012 Share Posted January 12, 2012 @Kenix: It's pretty wrong to use clientside functions to alter the money While it's okay to getPlayerMoney clientside, it's not a good idea to givePlayerMoney Link to comment
Thelastride Posted January 12, 2012 Share Posted January 12, 2012 Yes givePlayerMoney client side will give fake money because most of scripts use getPlayerMoney serverside. Link to comment
Kenix Posted January 12, 2012 Share Posted January 12, 2012 This is example with client side. Server addEvent( "onMoneyChange",true ) addEventHandler( "onMoneyChange",root, function( oldMoney,newMoney ) -- .... end ) function _givePlayerMoney( ... ) local args = { ... } if isElement( args[1] ) and type( args[2] ) == "number" then if triggerEvent( "onMoneyChange",args[1],getPlayerMoney( args[1] ),args[2] ) and givePlayerMoney( ... ) then return true end return false end end Link to comment
Scooby Posted January 12, 2012 Share Posted January 12, 2012 Solidsnake, just out of curiosity, why did u add this line? if (oldMoney < newMoney) then surely with that it only works if old money is less.. what if they have more? shouldnt the function be: function renderMoney() newMoney = getPlayerMoney() if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) oldMoney = newMoney end end addEventHandler("onClientRender",root,renderMoney) no offence intended... u do a great job on the forums helping people. Link to comment
BriGhtx3 Posted January 12, 2012 Author Share Posted January 12, 2012 this problem is already solved, the scoreboard thing is the problem oO Link to comment
Castillo Posted January 12, 2012 Share Posted January 12, 2012 Solidsnake, just out of curiosity, why did u add this line? if (oldMoney < newMoney) then surely with that it only works if old money is less.. what if they have more? shouldnt the function be: function renderMoney() newMoney = getPlayerMoney() if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney) oldMoney = newMoney end end addEventHandler("onClientRender",root,renderMoney) no offence intended... u do a great job on the forums helping people. Yup, it was a mistake, this was part of one of my HUD system's, I guess it was intended to do something for the HUD Thanks for finding it out. Corrected the script. Link to comment
Scooby Posted January 13, 2012 Share Posted January 13, 2012 no worries, i was just having a quick read through and noticed it. 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