• How to spend cash on custom code?
    4 replies, posted
How do i spend cash with this code Init [CODE]MONEY_STARTAMOUNT = 1000 --Can be changed to your starting amount function FirstSpawn( ply ) local cash = ply:GetPData("money") --Get the saved money amount if cash == nil then --If it doesn't exist supply the player with the starting money amount ply:SetPData("money", MONEY_STARTAMOUNT) --Save it ply:SetMoney( MONEY_STARTAMOUNT ) --Set it to the networked ints that can be called from the client too else ply:SetMoney( cash ) --If not, set the networked ints to what we last saved end end hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn ) function PrintCash( pl ) pl:ChatPrint("Your cash is: " .. pl:GetMoney()) end function fPlayerDisconnect( ply ) print("Player Disconnect: Money saved to SQLLite and TXT") ply:SaveMoney() ply:SaveMoneyTXT() end concommand.Add("cash_get",PrintCash) [/CODE] sh_player.lua [CODE]local meta = FindMetaTable("Player") --Get the meta table of player function meta:AddMoney(amount) local current_cash = self:GetMoney() self:SetMoney( current_cash + amount ) end function meta:SetMoney(amount) self:SetNetworkedInt( "Money", amount ) self:SaveMoney() end function meta:SaveMoney() local cash = self:GetMoney() self:SetPData("money", cash) end function meta:SaveMoneyTXT() file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString()) end function meta:TakeMoney(amount) --Add money function here self:AddMoney(-amount) end function meta:GetMoney() return self:GetNetworkedInt( "Money" ) end [/CODE]
I'm guessing ply:TakeMoney(10) would take 10 money (Dollars/Euros/whatever) from the player if thats what you mean?
thanks that works but when i choose a new map it dosent save
[QUOTE=MasterKenneth;45493217]thanks that works but when i choose a new map it dosent save[/QUOTE] I think you have to mess with mysql or sqlite stuff for that.
im planing to buy perks, powerups and useful items
Sorry, you need to Log In to post a reply to this thread.