init.lua look like this now and doesent working:
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'sh_player.lua' )
AddCSLuaFile( "sh_player.lua" )
include( 'shared.lua' )
MONEY_STARTAMOUNT = 1000 --Can be changed to your starting amount
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)
function ManualSaver( ply )
ply:SaveMoneyTXT()
end
concommand.Add("cash_save",ManualSaver)
function MoneyPerKill(victim, killer, weapon)
killer:SetNWInt("Money", killer:GetNWInt("Money") + 25)
end
hook.Add("OnNPCKilled","MoneyPerKill",MoneyPerKill)
function meta:LoadMoneyTXT()
local location = tostring( gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt" )
if file.Exists(location) then
return file.Read(location )
else
ply:SetMoney( MONEY_STARTAMOUNT )
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
and sh_player
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()
local location = tostring( gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt" )
if file.Exists(location) then
file.Delete(location)
file.Write(location, self:GetMoney())
else
file.Write(location, self:GetMoney())
end
end
function meta:TakeMoney(amount)
--Add money function here
self:AddMoney(-amount)
end
function meta:GetMoney()
return self:GetNetworkedInt( "Money" )
end
still not working please fix it to me
PS: I love goats xD
the saving is working but not loading i want it to load my cash :p