• Help with a Money System
    9 replies, posted
I got this from one of the Lua tutorials on the Gmod wiki. It works as it should, except that It says there are no tokens, right after a wallet has been made for the player and stuffed with tokens. When I have Paydays turned on, it will show the token amount after it adds the amount from a payday. Here's the parts for the problem that I need looked over. I can add more if you need it. [CODE] if SERVER then -- If this file is on a server do: (SERVER) local pm = FindMetaTable("Player") -- We state that entities under the $ function PlayerMoneySpawn( ply ) ply:Money_Create() end hook.Add("PlayerInitialSpawn", "MoneySystemStart", PlayerMoneySpawn) function pm:Money_Create() -- DONT TOUCH! THIS FUNCTION SAVES THE SHIT print("Creating money account for: "..self:Nick().." with "..ST$ if self:GetPData( "tokens" ) == nil then -- if there is no data$ self:SetPData( "tokens", STARTMONEY ) -- if there is no$ self:SetNWInt( "tokens", STARTMONEY ) end end else -- IF THIS FILE IS ON A PLAYER PC DO... (CLIENT) local function Money_Draw() ///////////////////////////////////////////////////////////////// ///////// FOR ADVANCED USERS: MAKE A HUD HERE /////////////// ///////////////////////////////////////////////////////////////// if not MONEY_HUD then return end local mulleh = LocalPlayer():GetNWInt( "tokens" ) -- The amount of money you got draw.DrawText("Tokens: "..mulleh, "", 60, 60, Color(255,255,255,255)) end hook.Add("HUDPaint", "MoneyPainting", Money_Draw) end [/CODE]
I don't see MONEY_HUD being defined anywhere. Also that end in right before the else can be confusing.
Its not the full thing, just snips. The variable "MONEY_HUD" is true
End your print on line 10 Or just replace it with this: print("Creating money account for: "..self:Nick().." with blar")
Oh, I copied this from my console instead of my editor, didn't realize it truncated the lines. Line10: [CODE] print("Creating money account for: "..self:Nick().." with "..STARTMONEY.." tokens") [/CODE] This still isn't relevant to the problem. Everything about the script works fine, except it doesnt show the start amount until money is added. Say "STARTMONEY" is 15. Payday is 1. After the payday, it'll show 16. Before that it shows 0
I saw you're using a modified Chief's Money System, so I downloaded it to see what was wrong and you were right. Simply replace pm:Money_Create() function with [lua] function pm:Money_Create() if self:GetPData("tokens") == nil then print("Creating money account for: " .. self:Nick() .. " with " .. STARTMONEY .. " tokens") self:SetPData("tokens", STARTMONEY) self:SetNWInt("tokens", STARTMONEY) else self:SetNWInt("tokens", self:GetPData("tokens")) end end [/lua] Basically, it was doing a check if there were no tokens, and if there weren't set them to starting amount. However, there was nothing setting the players amount to the already saved amount. Now there is.
Thanks man! Shows the amount as soon as I start. Quick question though, does the data in the meta table get saved between server restarts? I ask because, after updating that script and re-uploading it to my test server, I joined and started with 65 tokens.
Yes it saves because of the GetPData and SetPData. You started with that amount probably because you set/added your tokens multiple times. If you don't want to save get rid of the PData's and replace with NWInt's. Gustavgr16 = mad
Any other time I've tried it resets the data when I stop/start the server. I'll get someone else to join to see. Payday isn't working either. EDIT: nvm, working as intended. Does "PData" mean "Persistant Data" ?
Maybe, but it saves data to the database. So if you set someone's PData it'll be there when they re-connect.
Sorry, you need to Log In to post a reply to this thread.