• Money system lagging when gaining money.
    4 replies, posted
I got this money system, but it seems to lag everytime the payday comes around, can someone please point me in the right direction to stop this. [lua]local STARTMONEY = 15 -- This is the amount of cash that players start with local PAYDAYS = true -- Should there be paydays? true = yes, false = no local PAYDAY_AMOUNT = 5 -- If there are paydays, what should the salary be? local PAYDAY_INTERVAL = 60 -- If there are paydays, what should the payday interval be? (Seconds) local PAYDAY_SOUND = true -- If there are paydays, should a sound play when there's a payday? true = yes, false = no local MONEY_HUD = false -- Should the money be displayed on the screen? true = yes, false = no if SERVER then -- If this file is on a server do: (SERVER) local pm = FindMetaTable("Player") -- We state that entities under the meta table "player" is called pm, just to make it easier! 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()) if self:GetPData( "cash" ) == nil then -- if there is no data under "cash", create some! self:SetPData( "cash", STARTMONEY ) -- if there is no "cash" data, give them 15 cash to begin with! end end function pm:Money_Set( cash ) -- player:Money_Set = SET THE MONEY OF A PLAYER self:SetPData( "cash", tonumber(cash) ) -- Saves the cash to the server self:SetNWInt( "cash", tonumber(cash) ) -- Sends the amount to the players' screens end function pm:Money_Add( cash ) -- player:Money_Add = ADD MONEY FOR A PLAYER if cash > 0 then -- If the cash to give is over 0... local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money self:Money_Set( current + cash ) -- Set the money to: The old amount of money + the money wished to be added end end function pm:Money_Has( cash ) -- player:Money_Add = GET THE MONEY FOR A PLAYER local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money if current >= tonumber(cash) then -- if the old amount si over the amount checked... return true -- say it's true! else return false -- if not, say it's false! end end function pm:Money_Get() -- player:Money_Add = GET THE MONEY FOR A PLAYER local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money return current end function pm:Money_Take( cash ) -- player:Money_Add = TAKE MONEY FOR A PLAYER if self:Money_Has( cash ) then -- if you got the amount of money... local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money self:Money_Set( current - cash ) -- Take the old amount of money and take away the amount given! end end if PAYDAYS then timer.Create( "payday_timer", PAYDAY_INTERVAL, 0, function() for k, ply in pairs(player.GetAll()) do ply:Money_Add( PAYDAY_AMOUNT ) if PAYDAY_SOUND then ply:EmitSound("items/ammo_pickup.wav") end end 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( "cash" ) -- The amount of money you got draw.DrawText("Money: "..mulleh, "Trebuchet18", 60, 60, Color(255,255,255,255)) end hook.Add("HUDPaint", "MoneyPainting", Money_Draw) end][/lua]
[QUOTE=samwilki;22716924]I got this money system, but it seems to lag everytime the payday comes around, can someone please point me in the right direction to stop this. [lua]local STARTMONEY = 15 -- This is the amount of cash that players start with local PAYDAYS = true -- Should there be paydays? true = yes, false = no local PAYDAY_AMOUNT = 5 -- If there are paydays, what should the salary be? local PAYDAY_INTERVAL = 60 -- If there are paydays, what should the payday interval be? (Seconds) local PAYDAY_SOUND = true -- If there are paydays, should a sound play when there's a payday? true = yes, false = no local MONEY_HUD = false -- Should the money be displayed on the screen? true = yes, false = no if SERVER then -- If this file is on a server do: (SERVER) local pm = FindMetaTable("Player") -- We state that entities under the meta table "player" is called pm, just to make it easier! 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()) if self:GetPData( "cash" ) == nil then -- if there is no data under "cash", create some! self:SetPData( "cash", STARTMONEY ) -- if there is no "cash" data, give them 15 cash to begin with! end end function pm:Money_Set( cash ) -- player:Money_Set = SET THE MONEY OF A PLAYER self:SetPData( "cash", tonumber(cash) ) -- Saves the cash to the server self:SetNWInt( "cash", tonumber(cash) ) -- Sends the amount to the players' screens end function pm:Money_Add( cash ) -- player:Money_Add = ADD MONEY FOR A PLAYER if cash > 0 then -- If the cash to give is over 0... local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money self:Money_Set( current + cash ) -- Set the money to: The old amount of money + the money wished to be added end end function pm:Money_Has( cash ) -- player:Money_Add = GET THE MONEY FOR A PLAYER local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money if current >= tonumber(cash) then -- if the old amount si over the amount checked... return true -- say it's true! else return false -- if not, say it's false! end end function pm:Money_Get() -- player:Money_Add = GET THE MONEY FOR A PLAYER local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money return current end function pm:Money_Take( cash ) -- player:Money_Add = TAKE MONEY FOR A PLAYER if self:Money_Has( cash ) then -- if you got the amount of money... local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money self:Money_Set( current - cash ) -- Take the old amount of money and take away the amount given! end end if PAYDAYS then timer.Create( "payday_timer", PAYDAY_INTERVAL, 0, function() for k, ply in pairs(player.GetAll()) do ply:Money_Add( PAYDAY_AMOUNT ) if PAYDAY_SOUND then ply:EmitSound("items/ammo_pickup.wav") end end 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( "cash" ) -- The amount of money you got draw.DrawText("Money: "..mulleh, "Trebuchet18", 60, 60, Color(255,255,255,255)) end hook.Add("HUDPaint", "MoneyPainting", Money_Draw) end][/lua][/QUOTE] Yeh it's better to use ply instead of everyone [lua] if PAYDAYS then function Payday(ply) ply:Money_Add( PAYDAY_AMOUNT ) if PAYDAY_SOUND then ply:EmitSound("items/ammo_pickup.wav") end end timer.Create( "payday_timer", PAYDAY_INTERVAL, 0, Payday, ply) end [/lua] Try that see if its any different.
Try precaching the sound you play. Put this before timer.Create() [lua] util.PrecacheSound("items/ammo_pickup.wav") [/lua]
[QUOTE=MightyHaku;22724264]Try precaching the sound you play. Put this before timer.Create() [lua] util.PrecacheSound("items/ammo_pickup.wav") [/lua][/QUOTE] Won't need to it's already in the HL2 soundcache gfc it self.
Sorry, you need to Log In to post a reply to this thread.