-- ArmoredPacksAadMod 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 ArmoredPacksAadMod = {}
function ArmoredPacksAadMod.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(1546.275,6332.880,24.080)
		UI.SET_BLIP_COLOUR(blip, 1)
		UI.SET_BLIP_SPRITE(blip, 426)
		UI.SET_BLIP_NAME_FROM_TEXT_FILE(blip, "African Arms Dealer")
		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 mainAadInit()
	APAadGUI = APAadGUIinit()

	--MENU
	APAadGUI.mainMenu("main", "", "AFRICAN AD - MILITARY VEHICLE", 0.17, 0.1, 0.234, 0.0522, 0.003, 0.35, 2)
	APAadGUI.addButton("main", "Mltry. Rhino $1960000", spawnAfricanVehicle,"rhino", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Barracks Semi $430000", spawnAfricanVehicle,"barracks2", false, 0.35, 0)	
	APAadGUI.addButton("main", "Mltry. Barracks $450000", spawnAfricanVehicle,"barracks", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Crusader $83000", spawnAfricanVehicle,"crusader", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Technical Weaponized $434000", spawnAfricanVehicle,"technical", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Duke O'Death $286000", spawnAfricanVehicle,"dukes2", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Mesa $187000", spawnAfricanVehicle,"mesa3", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Guardian $355500", spawnAfricanVehicle,"guardian", false, 0.35, 0)
	APAadGUI.addButton("main", "Mltry. Patriot $102000", spawnAfricanVehicle,"patriot", false, 0.35, 0)
end

local ArmoredPacksAadMod = {}

function ArmoredPacksAadMod.unload()
end
function ArmoredPacksAadMod.init()
mainAadInit()

	--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

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

	
		APAadGUI.tick()
		
end

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

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

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

		APAadGUI.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 APAadGUI.addButton(mainMenu, text, funct, args, selectable, textScale, font)
		if(APAadGUI.buttons[mainMenu] == nil or APAadGUI.buttons[mainMenu]["settings"] == nil) then
			APAadGUI.buttons[mainMenu] = {["settings"] = {}}
		end

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

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

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

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

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

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

		if(nextDrawTime > GAMEPLAY.GET_GAME_TIMER()) then
			prevText = APAadGUI.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(APAadGUI.IndexStatus.text)
			UI._DRAW_TEXT(xmin , 0.5)
		else
			APAadGUI.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)
		    APAadGUI.setActiveMenu("")
		end
	end

	function APAadGUI.drawAPAadGUI()
		if(APAadGUI.activeMenu ~= "" and APAadGUI.activeMenu ~= nil) then
			local name = APAadGUI.activeMenu

			if(APAadGUI.menu[name] ~= nil) then
				local xmin = APAadGUI.menu[name].xmin
				local ymin = APAadGUI.menu[name].ymin
				local xmax = APAadGUI.menu[name].xmax
				local ymax = APAadGUI.menu[name].ymax
				
				local text = APAadGUI.menu[name].title
				local textScale = APAadGUI.menu[name].textScale
				local font = APAadGUI.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(APAadGUI.buttons[name] ~= nil) then
					for i, v in pairs(APAadGUI.buttons[name].settings) do
						local buttonSettings = APAadGUI.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"] = 120, ["g"] = 100, ["b"] = 80, ["o"] = 180}

						if(buttonSettings.selectableOn == true) then
							text = buttonSettings.text .. " [ON]"
						elseif(buttonSettings.selectableOn == false) then
							text = buttonSettings.text .. " [OFF]"
						end
						
						if(i == APAadGUI.activeButton) then
							colors = {["r"] = 170, ["g"] = 150, ["b"] = 130, ["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
					APAadGUI.setActiveMenu("")
				end
			else
				APAadGUI.setActiveMenu("")
			end
		end
	end

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

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

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

	function APAadGUI.tick()
		APAadGUI.drawIndex()
		APAadGUI.drawAPAadGUI()

		for i, key in pairs(APAadGUI.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(APAadGUI.activeMenu == APAadGUI.updateSelection.menuOpen.menu) then
						APAadGUI.setActiveMenu(APAadGUI.menu[APAadGUI.activeMenu].prevMenu)
					else
					    APAadGUI.setActiveMenu(APAadGUI.updateSelection.menuOpen.menu)
					    APAadGUI.currentSelection = 1
					end
				end
			
			end
		end

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

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

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

		for k, key in pairs(APAadGUI.updateSelection.select.keys) do
			if(get_key_pressed(key) and APAadGUI.activeMenu ~= "") then
			   if lastTime==nil or GAMEPLAY.GET_GAME_TIMER()-lastTime>120 then lastTime=GAMEPLAY.GET_GAME_TIMER()
				local currButton = APAadGUI.buttons[APAadGUI.activeMenu].settings[APAadGUI.activeButton]
				
				if(type(currButton.funct) == "function" and type(currButton.args) == "table") then
					APAadGUI.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
					APAadGUI.toggleButtonState()
					currButton.funct(currButton.args)
					
				elseif(currButton.args == nil) then
					APAadGUI.toggleButtonState()
					currButton.funct()

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

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

	return APAadGUI
end

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

--PRICES
	--ARMORED
local armddukesCost = 286000
local armdguardianCost = 355500

	--MILITARY
local mltryrhinoCost = 1960000
local mltrybarrackssemiCost = 430000
local mltrybarracksCost = 450000
local mltryicrusaderCost = 83000
local mltrytechnicalwpnzCost = 434000

	--OFF_ROAD
local ormesamwCost = 187000

	--SUV
local suvpatriotCost = 102000

--CARNAME
	--ARMORED
local armddukesCarName = "Mltry. Duke O'Death"
local armdguardianCarName = "Mltry. Guardian"

	--MILITARY
local mltryrhinoCarName = "Rhino Tank"
local mltrybarrackssemiCarName = "Barracks Semi"
local mltrybarracksCarName = "Barracks"
local mltryicrusaderCarName = "Crusader"
local mltrytechnicalwpnzCarName = "Mltry. Technical"

	--OFF_ROAD
local ormesamwCarName = "Mltry. Mesa"

	--SUV
local suvpatriotCarName = "Mltry. Patriot"

local showMenu = false

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

local spawned = false
local hPed
local sadlerA

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

--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 ArmoredPacksAadMod.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, 1545.899, 6333.035, 24.080, true	)
	local player = PLAYER.GET_PLAYER_PED(playerPed)
	local location = ENTITY.GET_ENTITY_COORDS( playerPed, nil )
	
	--SHOW MENU FLAG
	if (not playerPedinV and buyPoint < 2 and not showMenu) then
		if PED._IS_PED_DEAD(hPed, true) then
			notify("The Dealer is not here, come back later.")
		else
			notify("Hello my friend, what can i get for you? PRESS E")
		
			if get_key_pressed(Keys.E) then
				showMenu = true
			end
		end
	end

	--SHOW MENU
	if(showMenu == true) then
		APAadGUI.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,1546.275, 6332.880, 24.080, false ) < 150 ) then
		spawnAfricanDealer()
		spawned = true
	elseif(spawned == true and GAMEPLAY.GET_DISTANCE_BETWEEN_COORDS( location.x, location.y, location.z,1546.275, 6332.880, 24.080, false ) > 150 ) then
		PED.DELETE_PED(hPed)
		PED.DELETE_PED(tPed[0])
		PED.DELETE_PED(tPed[1])
		PED.DELETE_PED(tPed[2])
		PED.DELETE_PED(tPed[3])
		PED.DELETE_PED(tPed[4])
		PED.DELETE_PED(tPed[5])
		PED.DELETE_PED(tPed[6])
		PED.DELETE_PED(tPed[7])
		PED.DELETE_PED(tPed[8])
		PED.DELETE_PED(tPed[9])
		PED.DELETE_PED(tPed[10])
		PED.DELETE_PED(tPed[11])
		PED.DELETE_PED(tPed[12])
		PED.DELETE_PED(tPed[13])
		PED.DELETE_PED(tPed[14])
		handelaarMoney = 0
		spawned = false
	end
		
	
end

--DEALER SPAWN
function spawnAfricanDealer()

	local weapon = GAMEPLAY.GET_HASH_KEY("WEAPON_ASSAULTRIFLE")
	local weapon2 = GAMEPLAY.GET_HASH_KEY("WEAPON_MG")
	local weapon3 = GAMEPLAY.GET_HASH_KEY("WEAPON_RPG")
	local weapon4 = GAMEPLAY.GET_HASH_KEY("WEAPON_SNIPERRIFLE")

	---HANDELAAR---
	local handelaar = GAMEPLAY.GET_HASH_KEY("S_M_Y_Dealer_01")
	STREAMING.REQUEST_MODEL(handelaar)
	while(not STREAMING.HAS_MODEL_LOADED(handelaar)) do
		wait(50)
	end
	hPed = PED.CREATE_PED(1, handelaar, 1546.275, 6332.880, 24.080, 61, true, true)
	PED.SET_PED_CAN_SWITCH_WEAPON(hPed, true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(hPed, weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(hPed, GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(hPed, false)
	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(handelaar)
	handelaarMoney = (GAMEPLAY.GET_RANDOM_INT_IN_RANGE(12000,100000))
	PED.SET_PED_MONEY(hPed, handelaarMoney)

	---THUG---
	thug = GAMEPLAY.GET_HASH_KEY("A_M_Y_SouCent_03")

	STREAMING.REQUEST_MODEL(thug)
	
	while(not STREAMING.HAS_MODEL_LOADED(thug)) do
		wait(50)
	end
	
	tPed = {}
	
	tPed[0] = PED.CREATE_PED(1, thug, 1534.674, 6341.081, 24.189, 82, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[0], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[0], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[0], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[0], false)
	
	tPed[1] = PED.CREATE_PED(1, thug, 1533.751, 6338.325, 24.194, 71, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[1], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[1], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[1], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[1], false)
	
	tPed[2] = PED.CREATE_PED(1, thug, 1510.060, 6325.420, 24.607, 46, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[2], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[2], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[2], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[2], false)
	
	tPed[3] = PED.CREATE_PED(1, thug, 1546.838, 6335.788, 24.082, 98, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[3], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[3], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[3], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[3], false)

	tPed[4] = PED.CREATE_PED(1, thug, 1524.083, 6332.274, 25.231, 53, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[4], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[4], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[4], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[4], false)

	tPed[5] = PED.CREATE_PED(1, thug, 1506.337, 6319.052, 24.083, 84, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[5], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[5], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[5], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[5], false)

	tPed[6] = PED.CREATE_PED(1, thug, 1522.654, 6325.699, 28.651, 55, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[6], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[6], weapon3, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[6], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[6], false)

	tPed[7] = PED.CREATE_PED(1, thug, 1501.078, 6337.520, 23.937, 39, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[7], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[7], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[7], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[7], false)
	
	tPed[8] = PED.CREATE_PED(1, thug, 1504.702, 6328.056, 24.083, 10, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[8], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[8], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[8], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[8], false)

	tPed[9] = PED.CREATE_PED(1, thug, 1524.643, 6328.703, 24.191, 342, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[9], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[9], weapon2, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[9], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[9], false)

	tPed[10] = PED.CREATE_PED(1, thug, 1552.489, 6332.951, 24.083, 278, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[10], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[10], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[10], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[10], false)

	tPed[11] = PED.CREATE_PED(1, thug, 1551.309, 6321.452, 24.083, 330, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[11], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[11], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[11], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[11], false)

	tPed[12] = PED.CREATE_PED(1, thug, 1516.507, 6316.422, 24.083, 243, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[12], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[12], weapon, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[12], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[12], false)

	tPed[13] = PED.CREATE_PED(1, thug, 1485.145, 6311.291, 30.210, 1, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[13], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[13], weapon3, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[13], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[13], false)

	tPed[14] = PED.CREATE_PED(1, thug, 1509.653, 6302.065, 35.932, 8, true,true)
	PED.SET_PED_CAN_SWITCH_WEAPON(tPed[14], true)
	WEAPON.GIVE_DELAYED_WEAPON_TO_PED(tPed[14], weapon4, 1000, false)
	PED.SET_PED_RELATIONSHIP_GROUP_HASH(tPed[14], GAMEPLAY.GET_HASH_KEY("PRIVATE_SECURITY"))
	ENTITY.SET_ENTITY_INVINCIBLE(tPed[14], false)

	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(thug)
	
	STREAMING.REQUEST_MODEL(GAMEPLAY.GET_HASH_KEY("sadler"))
	
	while(not STREAMING.HAS_MODEL_LOADED(GAMEPLAY.GET_HASH_KEY("sadler"))) do
		wait(50)
	end
	
	sadlerA = VEHICLE.CREATE_VEHICLE(GAMEPLAY.GET_HASH_KEY("sadler"), 1522.355, 6333.492, 24.099, 57, true, true)
	VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(sadlerA)
	ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(sadlerA)
	
end

--VEHICLE SPAWN
function spawnAfricanVehicle(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 vehA = VEHICLE.CREATE_VEHICLE(GAMEPLAY.GET_HASH_KEY(modelString),  1526.007, 6344.897, 24.101, 104, true, true)
	VEHICLE.SET_VEHICLE_ON_GROUND_PROPERLY(vehA)
		
			VEHICLE.SET_VEHICLE_NEEDS_TO_BE_HOTWIRED(vehA, false) 		
			VEHICLE.SET_VEHICLE_HAS_BEEN_OWNED_BY_PLAYER(vehA, true)
			VEHICLE.SET_VEHICLE_IS_STOLEN(vehA, false)
			VEHICLE.SET_VEHICLE_IS_WANTED(vehA, false)
			VEHICLE.SET_VEHICLE_MOD_KIT(vehA, 0)
			VEHICLE.SET_VEHICLE_MOD(vehA, 16, 3, true)
			VEHICLE.SET_VEHICLE_WHEEL_TYPE(vehA, 120)
			VEHICLE.SET_VEHICLE_WINDOW_TINT(vehA, 3) 
			VEHICLE.SET_CAN_RESPRAY_VEHICLE(vehA, true)
			VEHICLE.SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(vehA, 210, 180, 140) 
			VEHICLE.SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(vehA, 222, 184, 135)
			VEHICLE.SET_VEHICLE_TYRES_CAN_BURST(vehA, false) 
			VEHICLE.SET_VEHICLE_WHEELS_CAN_BREAK(vehA, false) 			
			VEHICLE.SET_VEHICLE_NUMBER_PLATE_TEXT(vehA, "R3B3L10N")
		
	STREAMING.SET_MODEL_AS_NO_LONGER_NEEDED(GAMEPLAY.GET_HASH_KEY(modelString))

	if(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dukes2")) then cost = armddukesCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("guardian")) then cost = armdguardianCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rhino")) then cost = mltryrhinoCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("barracks2")) then cost = mltrybarrackssemiCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("crusader")) then cost = mltryicrusaderCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("barracks")) then cost = mltrybarracksCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("technical")) then cost = mltrytechnicalwpnzCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("mesa3")) then cost = ormesamwCost
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("patriot")) then cost = suvpatriotCost
	end
	
	if(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("dukes2")) then CarName = armddukesCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("guardian")) then CarName = armdguardianCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("rhino")) then CarName = mltryrhinoCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("barracks2")) then CarName = mltrybarrackssemiCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("crusader")) then CarName = mltryicrusaderCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("barracks")) then CarName = mltrybarracksCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("technical")) then CarName = mltrytechnicalwpnzCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("mesa3")) then CarName = ormesamwCarName
	elseif(GAMEPLAY.GET_HASH_KEY(modelString) == GAMEPLAY.GET_HASH_KEY("patriot")) then CarName = suvpatriotCarName
	end
	
	ENTITY.SET_VEHICLE_AS_NO_LONGER_NEEDED(vehA)
		
	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 ArmoredPacksAadMod

-- Credits to: Alexander Blade & headscript--