Money System that doesn't save.

Can someone help me make a money system, that doesn’t save your money. So, when you join, a timer starts, and ever 5 seconds you get 5$ added, but, when you leave, your money resets. Thank you. I have searched for this, but they all are saving money.

I made something that does pretty much that, but it saves. Just take out the saving stuff.

http://entoros.pastebin.com/f2e88e84a

[lua]
if SERVER then
timer.Create(“AddMoney”, 5, 0, function()
for k, ply in ipairs( player.GetAll() ) do
ply.Money = ply.Money or 0
ply.Money = ply.Money + 5
end
end )
concommand.Add(“showmymoney”, function( ply )
ply.Money = ply.Money or 0
ply:PrintMessage( HUD_PRINTCONSOLE, “You have $” … ply.Money … “.”)
end )
end
[/lua]

Ought to be replaced with

This is clearly a major issue that needs to be fixed. :stuck_out_tongue:

a better but kinda worse way to save money is using file.write and then writing your money to the file with your uniqie id and then when you join you set a networked value to that number. thats how i did it in my gamemode anyway: server.citrongamers.com:27029 :slight_smile:

He was asking for a system that dosent save. Not another way to save it. Have a bad reading

my bad :3 but anyway, it makes the thing easier, if you want, i will post my stoof that i use and you can unhook the player initial spawn stuff that loads the players moneys :slight_smile:

aslo, tobba, have a usefull :slight_smile: cause your a wrench XD

[lua]if SERVER then
local meta = _R[“Player”]
function meta:GetMoney()
return self:GetNWInt(“money”)
end
function meta:SetMoney(amount)
self:SetNWInt(“money”, amount)
end
function meta:AddMoney(amount)
self:SetMoney(self:GetMoney() + amount)
end
timer.Simple(“givemoney”, 5, 0, function()
for k, v in pairs(player.GetAll()) do
v:AddMoney(5)
end
end)
else
function GetMoney()
return LocalPlayer():GetNWInt(“money”)
end
end[/lua]

[editline]04:25PM[/editline]

Not sure if it works. wrote in reply box

[lua]
/*----------------------------

	THIS IS THE MONEY MODULE
	EDIT WITH CAUTION
	MADE BY NINGAGLIO
	FOR THE LOBBY GAMEMODE

-----------------------------*/

local ply = FindMetaTable(“Player”)

function ply:GetMoney()
return self:GetNetworkedInt(“money”)
end

if SERVER then
function ply:SetMoney(amt)
self:SetNWInt( “money”, tonumber(amt))
hook.Call( “OnSetMoney”, amt)
end

function ply:GiveMoney(amt)
	self:SetNWInt( "money", tonumber(amt) + self:GetNWInt( "money" ))
	hook.Call("OnGiveMoney", amt )
end

function SaveMoney(pl)
	local ourmoney = pl:GetNWInt( "money" )
	file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt", ourmoney)
end

function LoadMoney(pl)
	pl:SetNWInt( "money" , file.Read(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt"))
	if !file.Exists(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt") then
		pl:SetNWInt("money", 200)
		file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt", 200)
	end
end
function PlayerFind2( ply, target )

players = {}

if not target then
	ply:ChatPrint("Please specify a player.")
	return;
end

for _, v in ipairs( player.GetAll()) do 
	if string.find( string.lower( v:Nick() ), string.lower( target ) ) != nil then
		table.insert( players, v )
	end
end

if #players >1 then
	ply:ChatPrint("Multiple targets found.")
	return nil

	elseif #players <1 then
		ply:ChatPrint("No players found.")
		return nil

	elseif #players == 1 then
		return players[1]
	end
end

local function savemoneywaitwait( ply )
	timer.Create("savemoney_rep2", 2, 1, savemoneywait, ply)
end

local function savemoneywait( ply )
	timer.Create("savemoney_rep", 2, 0, SaveMoney, ply)
end
local function loadwait ( ply )
	timer.Create("loadmoney_wait", 1, 1, LoadMoney, ply)
end

local function connection( ply )
	loadwait( ply )
	savemoneywaitwait( ply )
end



hook.Add("PlayerInitialSpawn", "LoadWaitMoney", connection)

local function getmahmoney( ply )
	Msg( ply:Nick() .. " has " .. ply:GetMoney() .. " emeralds 

")
end

concommand.Add("lobby_getmoney", getmahmoney)

local function setmymoney( ply, cmd, args)
	if ply:IsAdmin() then
		ply:SetMoney( args[1] )
		local ourmoney = ply:GetNWInt( "money" )
		file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(ply:SteamID(), ":", "_") ..".txt", ourmoney)
		print( ply:Nick() .. " Gaver himself / herself " .. tonumber(args[1]))
	end
end

concommand.Add("lobby_setmoney", setmymoney)

local function donate( ply , cmd, args)
	local ply2 = PlayerFind2( ply, args[1])
	if ply2 then
		if ply:GetNWInt("money") >= tonumber(args[1]) then
			ply2:SetNWInt("money", ply2:GetNWInt("money") + tonumber(args[2]))
			ply:SetNWInt("money", ply:GetNWInt("money") - tonumber(args[2]))
			print( ply:Nick() .. " donated " .. tonumber(args[2]) .. " to " .. ply2:Nick())
			local ourmoney = ply:GetNWInt( "money" )
			file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(ply:SteamID(), ":", "_") ..".txt", ourmoney)
		end
	end
end

concommand.Add("lobby_donate", donate) 

end

[/lua]

Please do not give this out claiming its yours, i didnt code it to be given out so it may look messy but it does work !!! though it may have functions i made in other scripts

include it in your init and cl_init and make the client download it

to make it not save, remove the lines 70 to 90 but beware, this WILL cause errors because i am using those functions in other places

I just posted a simple system to do it. hopefully that works instead of 121 lines

:3 lol, but at least mine works :slight_smile: goto server.citrongamers.com:27029 to test it in action :slight_smile:

Four posts in this thread and two of them advertising your server. Cut that out, it’s annoying.

Thanks for the scripts though. :v:

[lua]
AccessorFuncNW(FindMetaTable(“Player”), “Money”, “Money”, 500, FORCE_NUMBER )
[/lua]

1 line, use like so:

[lua]
ply:SetMoney(ply:GetMoney()+5) – Adds 5 money.
print(ply:GetMoney()) – Prints the money.
[/lua]

ewww nwvars

There is nothing wrong with them, only when you’re constantly updating them like every frame is when they start sucking.

I’m sure every client wants to know how much money every other client has.

They could well do, depends on what type of gamemode it is.

Yeah but otherwise we’re just sending data for nothing, with only players using clientside scripts taking advantage of it. :smile: