-- ArmoredPacksMexMod by 2S v2.2.0

-- NOTE:
-- Please do not distribute this code without permission.
-- You can edit this file only for personal use. 
-- If this code is re-released in your mod, please add credits.
-- Thanks..

-------------------------------------------------------------------------------------------------------------------
local ArmoredPacksMexMod = {}
function ArmoredPacksMexMod.unload()	
	UI.REMOVE_BLIP(blip)
end

local Notification = {}

function Notification.unload() end
function Notification.init() end
function Notification.tick() end

function notify(msg) 
	UI._SET_NOTIFICATION_TEXT_ENTRY("STRING")
	UI._ADD_TEXT_COMPONENT_STRING(msg)
	UI._DRAW_NOTIFICATION(FALSE, FALSE)
end

--DISPLAY BLIP
local blip = UI.ADD_BLIP_FOR_COORD(2340.722,3126.413,48.209)
		UI.SET_BLIP_COLOUR(blip, 1)
		UI.SET_BLIP_SPRITE(blip, 426)
		UI.SET_BLIP_NAME_FROM_TEXT_FILE(blip, "Mexican Smuggler")
		UI.SET_BLIP_SCALE(blip, 1)
		UI.SET_BLIP_AS_SHORT_RANGE(blip, true)

-------------MENU KEYS----------------
--NUMPAD
local openMenukey = Keys.E
local upKey = Keys.NumPad8
local downKey = Keys.NumPad2
local selectKey = Keys.NumPad5
local cancelKey = Keys.NumPad0

--ARROW KEYS
local arrowupKey = Keys.Up
local arrowdownKey = Keys.Down
local arrowselectKey = Keys.Return
local arrowcancelKey = Keys.Back

-------------------------------------------------------------------------------------------------------------------
--DO NOT EDIT BEYOND THIS POINT------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------


function mainMexInit()
	APMexGUI = APMexGUIinit()

	--MENU
	APMexGUI.mainMenu("main", "", "MEXICAN SMUGGLER - ALL TERAIN CAR", 0.17, 0.1, 0.234, 0.0522, 0.003, 0.35, 2)
	APMexGUI.addButton("main", "Dubsta 6x6 $249000", spawnMexicanVehicle,"dubsta3", false, 0.35, 0)
	APMexGUI.addButton("main", "Sandking SWB $38000", spawnMexicanVehicle,"sandking2", false, 0.35, 0)
	APMexGUI.addButton("main", "Sandking XL $45000", spawnMexicanVehicle,"sandking", false, 0.35, 0)
	APMexGUI.addButton("main", "Rebel $3000", spawnMexicanVehicle,"rebel2", false, 0.35, 0)
	APMexGUI.addButton("main", "Rancher XL $9000", spawnMexicanVehicle,"rancherxl", false, 0.35, 0)
	APMexGUI.addButton("main", "Mesa MW $187000", spawnMexicanVehicle,"mesa3", false, 0.35, 0)
	APMexGUI.addButton("main", "BF Injection $16000", spawnMexicanVehicle,"bfinjection", false, 0.35, 0)
	APMexGUI.addButton("main", "Dune Buggy $20000", spawnMexicanVehicle,"dune", false, 0.35, 0)
	APMexGUI.addButton("main", "Bifta $75000", spawnMexicanVehicle,"bifta", false, 0.35, 0)
end

local ArmoredPacksMexMod = {}

function ArmoredPacksMexMod.unload()
end
function ArmoredPacksMexMod.init()
mainMexInit()

	--NUMPAD
	local E = openMenukey
	local numpad8 = upKey
	local numpad2 = downKey
	local numpad5 = selectKey
	local numpad0 = cancelKey
	
	--ARROW KEYS
	local keyup = arrowupKey
	local keydown = arrowdownKey
	local keyenter = arrowselectKey
	local keybackspace = arrowcancelKey

	APMexGUI.updateSelection = {["menuOpen"] = {["keys"] = {E},["menu"] = "main"},["menuUp"] = {["keys"] = {numpad8,keyup}}, 
		["menuDown"] = {["keys"] = {numpad2,keydown}},["menuCancel"] = {["keys"] = {numpad0,keybackspace}},["select"] = {["keys"] = {numpad5,keyenter}}}
end
function ArmoredPacksMexMod.tick()
	

	
		APMexGUI.tick()
		
end

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

function APMexGUIinit()
	APMexGUI = {}
	APMexGUI.menu = {}
	APMexGUI.buttons = {}
	APMexGUI.updateSelection = {["menuOpen"] = {["keys"] = {},["menu"] = ""},["menuUp"] = {["keys"] = {}},
		["menuDown"] = {["keys"] = {}},["menuCancel"] = {["keys"] = {}},["select"] = {["keys"] = {}}}
	APMexGUI.activeButton = 1
	APMexGUI.activeMenu = ""
	APMexGUI.IndexStatus = {["text"] = "", ["time"] = 0}

	function APMexGUI.mainMenu(menuName, prevMenu, title, xmin, ymin, xmax, ymax, Space, textScale, font)
		if(APMexGUI.menu[menuName] == nil) then
			APMexGUI.menu[menuName] = {}
			lastOffset = ymin + ymax + Space
		end

		APMexGUI.menu[menuName] = {["prevMenu"] = prevMenu,["title"] = title,["xmin"] = xmin,["ymin"] = ymin,
			["xmax"] = xmax,["ymax"] = ymax,["spacing"] = Space,["textScale"] = textScale,
			["font"] = font,["lastOffset"] = lastOffset,["numButtons"] = 0}
	end
	
	function APMexGUI.addButton(mainMenu, text, funct, args, selectable, textScale, font)
		if(APMexGUI.buttons[mainMenu] == nil or APMexGUI.buttons[mainMenu]["settings"] == nil) then
			APMexGUI.buttons[mainMenu] = {["settings"] = {}}
		end

		local currButtonNum = #APMexGUI.buttons[mainMenu].settings + 1
		APMexGUI.menu[mainMenu].numButtons = currButtonNum

		if(selectable) then
			selectableOn = false
		else
		    selectableOn = nil
		end

		APMexGUI.buttons[mainMenu].settings[currButtonNum] = {["mainMenu"] = mainMenu,["text"] = text,["funct"] = funct,
			["args"] = args,["font"] = font,["xmin"] = APMexGUI.menu[mainMenu].xmin,
			["ymin"] = APMexGUI.menu[mainMenu].lastOffset,["xmax"] = APMexGUI.menu[mainMenu].xmax,
			["ymax"] = APMexGUI.menu[mainMenu].ymax,["textScale"] = textScale,
			["selectable"] = selectable,["selectableOn"] = selectableOn}

		APMexGUI.menu[mainMenu]["lastOffset"] = (APMexGUI.menu[mainMenu].lastOffset + APMexGUI.menu[mainMenu].ymax + APMexGUI.menu[mainMenu].spacing)
	end

	function APMexGUI.setActiveMenu(menuName)
		APMexGUI.activeButton = 1
		APMexGUI.activeMenu = menuName
	end

	function APMexGUI.drawIndex()
		if(nextDrawTime == nil or prevText ~= APMexGUI.IndexStatus.text) then
			nextDrawTime = GAMEPLAY.GET_GAME_TIMER() + APMexGUI.IndexStatus.time
		end

		if(nextDrawTime > GAMEPLAY.GET_GAME_TIMER()) then
			prevText = APMexGUI.IndexStatus.text
			UI.SET_TEXT_FONT(0)
			UI.SET_TEXT_SCALE(0.0, 0.35)
			UI.SET_TEXT_COLOUR(255, 255, 255, 255)
			UI.SET_TEXT_WRAP(0, 1)
			UI.SET_TEXT_CENTRE(true)
			UI.SET_TEXT_DROPSHADOW(10, 10, 0, 0, 0)
			UI.SET_TEXT_EDGE(1, 0, 0, 0, 205)
			UI._SET_TEXT_ENTRY("STRING")
			UI._ADD_TEXT_COMPONENT_STRING(APMexGUI.IndexStatus.text)
			UI._DRAW_TEXT(xmin , 0.5)
		else
			APMexGUI.IndexStatus = {["text"] = "", ["time"] = 0}
			nextDrawTime = nil
		end
	end

	function addButtonText(text, xmin, ymin, textScale, font)
		if(text ~= nil and xmin ~= nil and ymin ~= nil and textScale ~= nil and font ~= nil) then
			UI.SET_TEXT_FONT(font)
			UI.SET_TEXT_SCALE(0.0, 0.30)
			UI.SET_TEXT_COLOUR(255, 255, 255, 255)
			UI.SET_TEXT_CENTRE(true)
			UI.SET_TEXT_DROPSHADOW(0, 0, 0, 0, 0)
			UI.SET_TEXT_EDGE(1, 0, 0, 0, 205)
			UI._SET_TEXT_ENTRY("STRING")
			UI._ADD_TEXT_COMPONENT_STRING(text)
			UI._DRAW_TEXT(xmin , ymin - 0.0125)
		else
			print("text: ", text, ", xmin: ", xmin, ", ymin: ", ymin, ", textScale: ", textScale, ", font: ", font)
		    APMexGUI.setActiveMenu("")
		end
	end

	function APMexGUI.drawAPMexGUI()
		if(APMexGUI.activeMenu ~= "" and APMexGUI.activeMenu ~= nil) then
			local name = APMexGUI.activeMenu

			if(APMexGUI.menu[name] ~= nil) then
				local xmin = APMexGUI.menu[name].xmin
				local ymin = APMexGUI.menu[name].ymin
				local xmax = APMexGUI.menu[name].xmax
				local ymax = APMexGUI.menu[name].ymax
				
				local text = APMexGUI.menu[name].title
				local textScale = APMexGUI.menu[name].textScale
				local font = APMexGUI.menu[name].font
				local colors = {["r"] = 0, ["g"] = 0, ["b"] = 0, ["o"] = 255}

				addButtonText(text, xmin, ymin, textScale, font)
				GRAPHICS.DRAW_RECT(xmin, ymin, xmax, ymax, colors.r, colors.g, colors.b, colors.o);

				if(APMexGUI.buttons[name] ~= nil) then
					for i, v in pairs(APMexGUI.buttons[name].settings) do
						local buttonSettings = APMexGUI.buttons[name].settings[i]
						local xmin = buttonSettings.xmin
						local ymin = buttonSettings.ymin
						local xmax = buttonSettings.xmax
						local ymax = buttonSettings.ymax
						
						local font = buttonSettings.font
						local text = buttonSettings.text
						local textScale = buttonSettings.textScale
						local colors = {["r"] = 180, ["g"] = 160, ["b"] = 90, ["o"] = 180}

						if(buttonSettings.selectableOn == true) then
							text = buttonSettings.text .. " [ON]"
						elseif(buttonSettings.selectableOn == false) then
							text = buttonSettings.text .. " [OFF]"
						end
						
						if(i == APMexGUI.activeButton) then
							colors = {["r"] = 210, ["g"] = 190, ["b"] = 140, ["o"] = 200}
						end

						addButtonText(text, xmin, ymin, textScale, font)
						GRAPHICS.DRAW_RECT(xmin, ymin, xmax, ymax, colors.r, colors.g, colors.b, colors.o);
					end
				else
					APMexGUI.setActiveMenu("")
				end
			else
				APMexGUI.setActiveMenu("")
			end
		end
	end

	function APMexGUI.updateIndexStatus(text, time)
		APMexGUI.IndexStatus = {["text"] = text, ["time"] = time}
	end

	function APMexGUI.isButtonselectableOn()
		local activeButton = APMexGUI.buttons[APMexGUI.activeMenu].settings[APMexGUI.activeButton]
		if(activeButton.selectable) then
			return activeButton.selectableOn
		elseif(activeButton.selectable == flse) then
			print("Button \"", APMexGUI.buttons[APMexGUI.activeMenu].settings[APMexGUI.activeButton].text, "\"")
		    return nil
		end
	end

	function APMexGUI.toggleButtonState()
		local activeButton = APMexGUI.buttons[APMexGUI.activeMenu].settings[APMexGUI.activeButton]
		
		if(APMexGUI.isButtonselectableOn() and activeButton.selectable) then
			activeButton.selectableOn = false
		elseif(APMexGUI.isButtonselectableOn() == false and activeButton.selectable) then
			activeButton.selectableOn = true
			print("toggled on")
		end
	end

	function APMexGUI.tick()
		APMexGUI.drawIndex()
		APMexGUI.drawAPMexGUI()

		for i, key in pairs(APMexGUI.updateSelection.menuOpen.keys) do
			if(get_key_pressed(key)) then
				if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
					if(APMexGUI.activeMenu == APMexGUI.updateSelection.menuOpen.menu) then
						APMexGUI.setActiveMenu(APMexGUI.menu[APMexGUI.activeMenu].prevMenu)
					else
					    APMexGUI.setActiveMenu(APMexGUI.updateSelection.menuOpen.menu)
					    APMexGUI.currentSelection = 1
					end
				end
			
			end
		end

		for k, key in pairs(APMexGUI.updateSelection.menuUp.keys) do
			if(get_key_pressed(key) and APMexGUI.activeMenu ~= "") then
				if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
					APMexGUI.activeButton = APMexGUI.activeButton - 1

					if(APMexGUI.activeButton <= 0) then
						APMexGUI.activeButton = APMexGUI.menu[APMexGUI.activeMenu].numButtons
					end
				end
			
			end
		end

		for k, key in pairs(APMexGUI.updateSelection.menuDown.keys) do
			if(get_key_pressed(key) and APMexGUI.activeMenu ~= "") then
				if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
					APMexGUI.activeButton = APMexGUI.activeButton + 1
					if(APMexGUI.activeButton > APMexGUI.menu[APMexGUI.activeMenu].numButtons) then
						APMexGUI.activeButton = 1
					end
				end
			
			end
		end

		for k, key in pairs(APMexGUI.updateSelection.select.keys) do
			if(get_key_pressed(key) and APMexGUI.activeMenu ~= "") then
			   if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
				local currButton = APMexGUI.buttons[APMexGUI.activeMenu].settings[APMexGUI.activeButton]
				
				if(type(currButton.funct) == "function" and type(currButton.args) == "table") then
					APMexGUI.toggleButtonState()
					currButton.funct(currButton.args[1], currButton.args[2], currButton.args[3], currButton.args[4], currButton.args[5], currButton.args[6], currButton.args[7], currButton.args[8], currButton.args[9], currButton.args[10], currButton.args[11], currButton.args[12], currButton.args[13], currButton.args[14], currButton.args[15], currButton.args[16], currButton.args[17], currButton.args[18], currButton.args[19], currButton.args[20])

				elseif(type(currButton.funct) == "function" and type(currButton.args) == "string" or type(currButton.args) == "number"or type(currButton.args) == "boolean") then
					APMexGUI.toggleButtonState()
					currButton.funct(currButton.args)
					
				elseif(currButton.args == nil) then
					APMexGUI.toggleButtonState()
					currButton.funct()

				else
					print("function: ", currButton.funct, ", args: ", currButton.args)
				end
			   end
			
			end
		end

		for k, key in pairs(APMexGUI.updateSelection.menuCancel.keys) do
			if(get_key_pressed(key) and APMexGUI.activeMenu ~= "") then
				if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
					APMexGUI.setActiveMenu(APMexGUI.menu[APMexGUI.activeMenu].prevMenu)
				end
			
			end
		end
	end

	return APMexGUI
end

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

--PRICES
	--OFF_ROAD
local ordubsta6x6Cost = 249000
local orsandkingswbCost = 38000
local orsandkingxlCost = 45000
local orrebelCost = 3000
local orrancherxlCost = 9000
local ormesamwCost = 187000
local orbodhiCost = 25000
local orinjectionCost = 16000
local ordunebuggyCost = 20000
local orbiftaCost = 75000

--CARNAME
	--OFF_ROAD
local ordubsta6x6CarName = "Dubsta 6x6"
local orsandkingswbCarName = "Sandking SWB"
local orsandkingxlCarName = "Sandking XL"
local orrebelCarName = "Rebel"
local orrancherxlCarName = "Rancher XL"
local ormesamwCarName = "Off-Road Mesa"
local orbodhiCarName = "Bodhi"
local orinjectionCarName = "BF Injection"
local ordunebuggyCarName = "Dune Buggy"
local orbiftaCarName = "Bifta"

local showMenu = false

local buy = false
local timebuy = 99999
local CarName = "not set"

local spawned = false
local jPed
local mesaM

--DO NOT EDIT BEYOND THIS POINT
-------------------------------------------------------------------------------------------------------------------

--Pay System
function Pay(pay)

local playerPed = PLAYER.PLAYER_PED_ID()

		if (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_zero"))) then
			model = 0
		elseif (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_one"))) then                                
			model = 1                                         
		elseif (PED.IS_PED_MODEL(playerPed, GAMEPLAY.GET_HASH_KEY("player_two"))) then
			model = 2
		end
	
		local statname = "SP"..model.."_TOTAL_CASH"
		local hash = GAMEPLAY.GET_HASH_KEY(statname)
		local bool, val = STATS.STAT_GET_INT(hash, 0, -1)

		STATS.STAT_SET_INT(hash, val - pay, true)

end

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

function ArmoredPacksMexMod.tick()

	local playerPed = PLAYER.PLAYER_PED_ID()
	local playerPedinV = PED.IS_PED_IN_ANY_VEHICLE(playerPed, false)
	local playerCoords = ENTITY.GET_ENTITY_COORDS(playerPed, true)
	local buyPoint = GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS(playerCoords.x, playerCoords.y, playerCoords.z, 2340.722, 3126.413, 48.209, true	)
	local player = PLAYER.GET_PLAYER_PED(playerPed)
	local location = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
	
	--SHOW MENU FLAG
	if (not playerPedinV and buyPoint < 3 and not showMenu) then
		if PED._IS_PED_DEAD(jPed, true) then
			notify("The Dealer is not here, come back later.")
		else
			notify("Hola amigo, looking for something? PRESS E")
		
			if get_key_pressed(Keys.E) then
				showMenu = true
			end
		end
	end

	--SHOW MENU
	if(showMenu == true) then
		APMexGUI.tick()
	end

	--CLOSE MENU
	if(buyPoint > 2 and get_key_pressed(Keys.E)) then
		showMenu = false
	elseif(buyPoint > 10 and showMenu == true) then
		showMenu = false
	end

	--PLAYER & DEALER DISTANCE
	if(buyPoint > 5 and showMenu == true) then
		notify("PRESS E to close the Menu")
	end

	--SPAWN/DESPAWN DEALER
	if(spawned == false and GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( location.x, location.y, location.z,2340.722, 3126.413, 48.209, false ) < 150 ) then
		spawnMexicanDealer()
		spawned = true
	elseif(spawned == true and GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( location.x, location.y, location.z,2340.722, 3126.413, 48.209, false ) > 150 ) then
		PED.DELETE_PED(jPed)
		PED.DELETE_PED(mPed[0])
		PED.DELETE_PED(mPed[1])
		PED.DELETE_PED(mPed[2])
		PED.DELETE_PED(mPed[3])
		PED.DELETE_PED(mPed[4])
		PED.DELETE_PED(mPed[5])
		PED.DELETE_PED(mPed[6])
		PED.DELETE_PED(mPed[7])
		PED.DELETE_PED(mPed[8])
		PED.DELETE_PED(mPed[9])
		PED.DELETE_PED(mPed[10])
		PED.DELETE_PED(mPed[11])
		jefeMoney = 0
		spawned = false
	end
		
	
end

--DEALER SPAWN
function spawnMexicanDealer()

	local weapon = GAMEPLAY.GET_HASH_KEY("WEAPON_SMG")
	local weapon2 = GAMEPLAY.GET_HASH_KEY("WEAPON_PUMPSHOTGUN")
	local weapon3 = GAMEPLAY.GET_HASH_KEY("WEAPON_SNIPERRIFLE")

	---JEFE---
	local jefe = GAMEPLAY.GET_HASH_KEY("G_M_M_MexBoss_01")
	STREAMING.REQUEST_MODEL(jefe)
	while(not STREAMING.HAS_MODEL_LOADED(jefe)) do
		wait(50)
	end
	jPed = PED.CREATE_PED(1, jefe, 2340.722, 3126.413, 48.209, 347, true, true)
	PED.SET_PED_CAN_SWITCH_WEAPON(jPed, true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(jPed, weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(jPed, GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(jPed, false)
	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(jefe)
	jefeMoney = (GAMEPLAY.GET_RANDOM_INT_IN_RANGE(7000,70000))
	PED.SET_PED_MONEY(jPed, jefeMoney)

	---MATON---
	maton = GAMEPLAY.GET_HASH_KEY("G_M_Y_MexGang_01")

	STREAMING.REQUEST_MODEL(maton)
	
	while(not STREAMING.HAS_MODEL_LOADED(maton)) do
		wait(50)
	end
	
	mPed = {}
	
	mPed[0] = PED.CREATE_PED(1, maton, 2354.610, 3128.721, 48.209, 296, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[0], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[0], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[0], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[0], false)
	
	mPed[1] = PED.CREATE_PED(1, maton, 2357.192, 3138.044, 48.209, 198, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[1], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[1], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[1], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[1], false)
	
	mPed[2] = PED.CREATE_PED(1, maton, 2344.730, 3130.321, 48.209, 8, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[2], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[2], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[2], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[2], false)
	
	mPed[3] = PED.CREATE_PED(1, maton, 2353.668, 3121.116, 48.209, 34, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[3], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[3], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[3], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[3], false)
	
	mPed[4] = PED.CREATE_PED(1, maton, 2356.355, 3113.036, 48.209, 265, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[4], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[4], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[4], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[4], false)

	mPed[5] = PED.CREATE_PED(1, maton, 2350.576, 3143.351, 48.209, 140, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[5], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[5], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[5], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[5], false)

	mPed[6] = PED.CREATE_PED(1, maton, 2339.303, 3123.959, 48.209, 348, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[6], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[6], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[6], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[6], false)

	mPed[7] = PED.CREATE_PED(1, maton, 2339.675, 3118.144, 48.209, 80, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[7], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[7], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[7], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[7], false)

	mPed[8] = PED.CREATE_PED(1, maton, 2349.246, 3114.210, 48.209, 348, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[8], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[8], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[8], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[8], false)

	mPed[9] = PED.CREATE_PED(1, maton, 2357.300, 3122.221, 48.209, 346, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[9], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[9], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[9], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[9], false)

	mPed[10] = PED.CREATE_PED(1, maton, 2341.098, 3142.318, 55.862, 84, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[10], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[10], weapon3, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[10], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[10], false)

	mPed[11] = PED.CREATE_PED(1, maton, 2339.535, 3133.238, 55.870, 86, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(mPed[11], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(mPed[11], weapon3, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(mPed[11], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(mPed[11], false)
	
	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(maton)
	
	STREAMING.REQUEST_MODEL(GAMEPLAY.GET_HASH_KEY("mesa"))
	
	while(not STREAMING.HAS_MODEL_LOADED(GAMEPLAY.GET_HASH_KEY("mesa"))) do
		wait(50)
	end
	
	mesaM = VEHICLE.CREATE_VEHICLE(GAMEPLAY.GET_HASH_KEY("mesa"), 2344.268, 3141.806, 48.209, 171, true, true)
	VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(mesaM)
	ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(mesaM)
end

--VEHICLE SPAWN
function spawnMexicanVehicle(modelString) 

	print (timebuy)
	print(TIME.GET_CLOCK_DAY_OF_MONTH())
	print(TIME.GET_CLOCK_DAY_OF_MONTH() ~= timebuy)

if(TIME.GET_CLOCK_DAY_OF_MONTH() ~= timebuy) then
	
	local cost
		

	timebuy = TIME.GET_CLOCK_DAY_OF_MONTH()
		
	STREAMING.REQUEST_MODEL(GAMEPLAY.GET_HASH_KEY(modelString))
		
	while(not STREAMING.HAS_MODEL_LOADED(GAMEPLAY.GET_HASH_KEY(modelString))) do
		wait(50)
	end
		
	local vehM = VEHICLE.CREATE_VEHICLE(GAMEPLAY.GET_HASH_KEY(modelString), 2352.135, 3132.612, 48.209, 259, true, true)
	VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(vehM)
		
			VEHICLE.SET_VEHICLE_NEEDS_TO_BE_HOTWIRED(vehM, false) 		
			VEHICLE.SET_VEHICLE_HAS_BEEN_OWNED_BY_PLAYER(vehM, true)
			VEHICLE.SET_VEHICLE_IS_STOLEN(vehM, false)
			VEHICLE.SET_VEHICLE_IS_WANTED(vehM, false)
			VEHICLE.SET_VEHICLE_MOD_KIT(vehM, 0)
			VEHICLE.SET_VEHICLE_MOD(vehM, 16, 4, true)
			VEHICLE.SET_VEHICLE_WHEEL_TYPE(vehM, 120)
			VEHICLE.SET_VEHICLE_WINDOW_TINT(vehM, 3) 
			VEHICLE.SET_CAN_RESPRAY_VEHICLE(vehM, true)
			VEHICLE.SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(vehM, 237, 201, 175)
			VEHICLE.SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(vehM, 244, 164, 96) 
			VEHICLE.SET_VEHICLE_TYRES_CAN_BURST(vehM, true) 
			VEHICLE.SET_VEHICLE_WHEELS_CAN_BREAK(vehM, true) 			
			VEHICLE.SET_VEHICLE_NUMBER_PLATE_TEXT(vehM, "3LD14BL0")
		
	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(GAMEPLAY.GET_HASH_KEY(modelString))

	if(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dubsta3")) then cost = ordubsta6x6Cost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("sandking2")) then cost = orsandkingswbCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("sandking")) then cost = orsandkingxlCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rebel2")) then cost = orrebelCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rancherxl")) then cost = orrancherxlCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("mesa3")) then cost = ormesamwCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bodhi")) then cost = orbodhiCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bfinjection")) then cost = orinjectionCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dune")) then cost = ordunebuggyCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bifta")) then cost = orbiftaCost
	end
	
	if(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dubsta3")) then CarName = ordubsta6x6CarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("sandking2")) then CarName = orsandkingswbCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("sandking")) then CarName = orsandkingxlCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rebel2")) then CarName = orrebelCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rancherxl")) then CarName = orrancherxlCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("mesa3")) then CarName = ormesamwCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bodhi")) then CarName = orbodhiCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bfinjection")) then CarName = orinjectionCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dune")) then CarName = ordunebuggyCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("bifta")) then CarName = orbiftaCarName
	end
	
	ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(vehM)
		
	Pay(cost)
	buy = true
	notify("Thank you, Your " .. CarName .. " is already delivered. Stay safe!")
		
elseif(TIME.GET_CLOCK_DAY_OF_MONTH() == timebuy) then
	notify("Wait for another shipment")
end
		wait(5)
		
		
end


------------------------------------------------------------------------------
return ArmoredPacksMexMod

-- Credits to: Alexander Blade & headscript--