• Gmod Money system and buy system help
    3 replies, posted
How do i get this down i already have some code but theres errors with them dont know the problem [CODE]sh_player.lua include( 'sh_player.lua' ) AddCSLuaFile( "sh_player.lua" ) 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] it crashes my game [CODE]function GM:PlayerShouldTakeDamage( victim, pl ) if pl:IsPlayer() then -- check the attacker is player if( pl:Team() == victim:Team() and GetConVarNumber( "mp_friendlyfire" ) == 0 ) then -- check the teams are equal and that friendly fire is off. return false -- do not damage the player end end return true -- damage the player end 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( ply ) ply:ChatPrint("Your cash is: " .. ply: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]
What are the errors?
I cant load the game with this code [editline]25th July 2014[/editline] I Fixed the crashing i get this error [ERROR] gamemodes/spsnowballfight/gamemode/init.lua:223: attempt to call method 'GetMoney' (a nil value) 1. unknown - gamemodes/spsnowballfight/gamemode/init.lua:223 2. unknown - lua/includes/modules/concommand.lua:69
How many more threads are you going to create? We're not here to spoonfeed you. Learn Lua if you want to code. Don't expect us to help with every error and stick to one thread.
Sorry, you need to Log In to post a reply to this thread.