-- Ped Money v1.0

-- by diamond-optic

--------------------------------------------------

-- Information:

--  Sets nearby ped money to a random value between
--  the min & max values (default 100-500).

--  It only sets the ped's money if they have less
--  then the min value.

--------------------------------------------------

-- Change Log:

--   Version 1.0 (05.09.15)
--     - Initial Release

--------------------------------------------------

-- Configuration:

local Money_Min = 100     -- Min amount of Money to give peds
local Money_Max = 500     -- Max amount of Money to give peds
local Interval  = 5000    -- Interval for nearby ped check (1000 = 1s)

--------------------------------------------------

local Mod_Version = "1.0"
local Mod_Date    = "05.09.15"

local PedMoney = {}
local GameTime = 0

function PedMoney.init()

  print("-------------------------")
  print("Ped Money v".. Mod_Version.. " (".. Mod_Date..")")
  print("by diamond-optic")
  print("-------------------------")

  math.randomseed(os.time())
  
  GameTime = GAMEPLAY.GET_GAME_TIMER()

end

function PedMoney.tick()

  if((GAMEPLAY.GET_GAME_TIMER() - GameTime) > Interval) then
    
    GameTime = GAMEPLAY.GET_GAME_TIMER()
    
    local Table, Count = PED.GET_PED_NEARBY_PEDS(PLAYER.PLAYER_PED_ID(), 0, 1)
     
    for k,v in ipairs(Table) do

      if(PED.IS_PED_HUMAN(v) and PED.GET_PED_MONEY(v) < Money_Min) then
      
        PED.SET_PED_MONEY(v,math.random(Money_Min, Money_Max))

      end
    
    end
  
  end
  
end

return PedMoney