checking LUA for command for map money system

Any aspects of level design for the Source engine.

checking LUA for command for map money system

Postby smashballs on Tue Jun 18, 2013 1:03 am

I am trying to make a money system for a Garry's Mod map and I need to know how to see for certain commands in a LUA file that counts money like:
Code: Select all
local STARTMONEY = 15 -- This is the amount of cash that players start with
local PAYDAYS = false -- Should there be paydays?    true = yes,    false = no
local PAYDAY_AMOUNT = 5 -- If there are paydays, what should the salary be?
local PAYDAY_INTERVAL = 8 -- 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 = true -- 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)


I just need to know how to find a console command in a LUA file to put in a point_clientcommand's Output function to make this give, take, or set money.

- Is there a way to make commands with some sort of other file so I may use this with console?
Last edited by smashballs on Tue Jun 18, 2013 1:11 am, edited 1 time in total.
smashballs
Member
Member
 
Joined: Wed May 29, 2013 2:39 am

Re: checking LUA for command for map money system

Postby Armageddon on Tue Jun 18, 2013 1:07 am

Might want to try this over on Facepunch.
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Re: checking LUA for command for map money system

Postby smashballs on Tue Jun 18, 2013 1:13 am

Armageddon wrote:Might want to try this over on Facepunch.

Well I can put this on there to see what I get for help, but there might be someone with skills in this field here
smashballs
Member
Member
 
Joined: Wed May 29, 2013 2:39 am

Re: checking LUA for command for map money system

Postby Armageddon on Tue Jun 18, 2013 1:29 am

I don't think anyone here has touched Lua or Gmod gamemodes, Facepunch is well versed in that area. Just being helpful. :P
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Return to Hammer Editor Help

Who is online

Users browsing this forum: Bing [Bot]