Admigo Posted September 19, 2011 Share Posted September 19, 2011 Heey all, Can someone help me with dxscoreboard? I want to add money collum with the getplayermoney function. Pls i need this for shop. Thnks admigo Link to comment
Castillo Posted September 19, 2011 Share Posted September 19, 2011 -- server side addEventHandler("onResourceStart",resourceRoot, function() call(getResourceFromName("scoreboard"),"addScoreboardColumn","Money") end ) -- client side local starttick, currenttick local player = getLocalPlayer() addEventHandler("onClientResourceStart",resourceRoot, function () setTimer(updateMoney, 1000000, 0) addEventHandler("onClientRender",root,moneyRender) end) function moneyRender() if not starttick then starttick = getTickCount() end currenttick = getTickCount() if currenttick - starttick >= 1000 then setElementData(player,"Money",getPlayerMoney( player )) starttick = getTickCount() end end function updateMoney() for k, v in ipairs(getElementsByType('player')) do local money = getPlayerMoney(v) setElementData(v,"Money", money) end end Link to comment
Admigo Posted September 19, 2011 Author Share Posted September 19, 2011 Thanks dude for responding. I need to add this in the dxscoreboard resource or the race source? Link to comment
Castillo Posted September 19, 2011 Share Posted September 19, 2011 Make a new resource? don't you know how resource system works? If your scoreboard is called "dxscoreboard" then you need to change call(getResourceFromName("scoreboard"),"addScoreboardColumn","Money") to call(getResourceFromName("dxscoreboard"),"addScoreboardColumn","Money") Link to comment
Admigo Posted September 19, 2011 Author Share Posted September 19, 2011 Thank you so much. U code Works Great;) Is there a shop resource somewhere,so i can make a shop because i dont know how to make that. Link to comment
Castillo Posted September 19, 2011 Share Posted September 19, 2011 (edited) You're welcome. P.S: I made a shop resource a long time ago: https://community.multitheftauto.com/index.php?p= ... ils&id=720 Edited September 19, 2011 by Guest Link to comment
Admigo Posted September 19, 2011 Author Share Posted September 19, 2011 Thank you dude,I will use it! Can you help me with country collum? Link to comment
Admigo Posted September 19, 2011 Author Share Posted September 19, 2011 Why after a map change the money setted to 0? Fix pls Link to comment
Castillo Posted September 19, 2011 Share Posted September 19, 2011 I don't know, I didn't test it on race, I think I'd enough giving you the script, now you'll have to find out why it bugs. Link to comment
Deltanic Posted September 20, 2011 Share Posted September 20, 2011 One thing: Is that timer that loops all players really needed? setElementData is synced between server and client, so whenever the client updates it, the others will receive that info too, so making the loop kinda pointless imo. Also, you're updating the players money even when it hasn't been changed. This can really create a big traffic load, which you surely not want. I'd suggest a variable that holds the current player money, and if the money has been changed, update it. local pMoney = 0 addEventHandler("onClientResourceStart",resourceRoot, function () setTimer(updateMoney, 1000, 0) end) function updateMoney() local newMoney = getPlayerMoney ( localPlayer ) if pMoney ~= newMoney then pMoney = newMoney setElementData ( localPlayer, "Money", newMoney ) end end And after a map change your money is zero? Probably because theres somewhere 'resetMapInfo' called. This resets everything in your map, including money. You should script a custom system if you want to prevent the money reset. Link to comment
Admigo Posted September 20, 2011 Author Share Posted September 20, 2011 Dont work! When map change your money is 0:S Link to comment
Cadu12 Posted September 20, 2011 Share Posted September 20, 2011 You dont need use timer. Use OnClientElementDataChange or OnElementDataChange events Link to comment
Admigo Posted September 20, 2011 Author Share Posted September 20, 2011 Ooh its working but if someone has 0 money ,the collum is blank. How can i fix that? Link to comment
Cadu12 Posted September 20, 2011 Share Posted September 20, 2011 Try: exports.dxscoreboard:scoreboardAddColumn( "Money", 60, "Money" ) Link to comment
HunT Posted September 20, 2011 Share Posted September 20, 2011 ServerSide : exports.scoreboard:addScoreboardColumn('Money') function addMoneyScore () local money = getPlayerMoney ( source ) setElementData ( source, "Money", "$" .. money ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), addMoneyScore ) Edit . . . Test Now Link to comment
Admigo Posted September 20, 2011 Author Share Posted September 20, 2011 This code keeps updating so if a players gets money from a game it changes in scoreboard? Link to comment
Al3grab Posted September 20, 2011 Share Posted September 20, 2011 hi , -- Client Side function moneyTab() exports.scoreboard:scoreboardAddColumn("Money") setElementData(getLocalPlayer(),"Money",tostring (getPlayerMoney(getLocalPlayer))) setTimer( function () setElementData(getLocalPlayer(),"Money",tonumber(getPlayerMoney(getLocalPlayer))) end ,5000,0) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), moneyTab) Money Updates each 5 sec .. Link to comment
Admigo Posted September 21, 2011 Author Share Posted September 21, 2011 Its getting to 0 after a new map. Pls help fix this. Link to comment
HunT Posted September 21, 2011 Share Posted September 21, 2011 1.Rename the directory or .zip dxscoreboard to scoreboard 2.Add this in race_server or made new resource. Type server. ServerSide : exports.scoreboard:addScoreboardColumn('Money') function addMoneyScore () local money = getPlayerMoney ( source ) setElementData ( source, "Money", "$" .. money ) end end addEventHandler ( "onPlayerSpawn", getRootElement(), addMoneyScore ) Start this script and wait next map. Link to comment
Admigo Posted September 21, 2011 Author Share Posted September 21, 2011 Thank you so much Hunterix~! Your code works:P Thank you all for sending the codes!! 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