function SpawnInit() -- Code goes here :)
		
	

	CreateSpawnCountry('Russia', {"Cold War-Present"}, 1)
	CreateVehicleCategory('Russia', 'Cold War-Present', 'Trucks', 'MOD/img/Trucks.png')
	CreateVehicle("Russia", "Cold War-Present", "Trucks", "GAZ-66", 'MOD/img/preview_gaz66.png' ,{
			{ name = "GAZ-66", xml = "MOD/TABS/vehicles/Soviet Union/Cold War/Cars, Trucks, Tractors & Halftracks/Trucks/GAZ-27/GAZ-66.xml", img = "MOD/img/GAZ-66.png"},			
			{ name = "GAZ-66 Bench", xml = "MOD/TABS/vehicles/Soviet Union/Cold War/Cars, Trucks, Tractors & Halftracks/Trucks/GAZ-27/GAZ-66 Bench.xml", img = "MOD/img/GAZ-66 Bench.png"},					
			{ name = "GAZ-66 Kung", xml = "MOD/TABS/vehicles/Soviet Union/Cold War/Cars, Trucks, Tractors & Halftracks/Trucks/GAZ-27/GAZ-66 Kung.xml", img = "MOD/img/GAZ-66 Kung.png"},					
			{ name = "GAZ-66 Transport", xml = "MOD/TABS/vehicles/Soviet Union/Cold War/Cars, Trucks, Tractors & Halftracks/Trucks/GAZ-27/GAZ-66 Tent No tent.xml", img = "MOD/img/GAZ-66 Transport.png"},					
			{ name = "GAZ-66 Tent", xml = "MOD/TABS/vehicles/Soviet Union/Cold War/Cars, Trucks, Tractors & Halftracks/Trucks/GAZ-27/GAZ-66 Tent .xml", img = "MOD/img/GAZ-66 Tent.png"},				
		}
	)
		
end

-- Dont touch anything below this line -- 

Key = GetString('game.TABS.Vehicles.Modded.Spawn.Menu.Current.Key')
Path = GetString('game.TABS.Vehicles.Modded.Spawn.Menu.Current.Path')

ReturnValue = GetBoolParam('HasReturn', false)
CreateEntries = GetBoolParam('Enabled', false)	
	
Additions = {
	Countries = {},
	Vehicles = {},
	Categories = {},

}

function SerializeSpecialTable(Table)
    local Keys = {
        Main = {
            Primary = "~MainSeperation~",
            Type = "~TypeSeperation~",
            Arguments = "~ArgSeperation~",
            ArgumentType = "~ArgTypeSeperation~",
        },
        Transform = {
            Value = "~TransformValueSeperator~",
            TransformSeperator = "~TransformTypeSeperator~",
            Type = "~TransformVecSeperator~",
        },
        Table = {
            Type = "~TableTypeSeperator~",
            Values = "~TableValueSeperator~",
            
        },
    }
        
    local Strings = {}
    for i=1,#Table do
        local ArgTable = {}
        for j=1,#Table[i].Arguments do
                
            if Table[i].Arguments[j][1] == "Bool" or Table[i].Arguments[j][1] == "String" or Table[i].Arguments[j][1] == "Number" then
                table.insert(ArgTable, ""..Table[i].Arguments[j][1]..Keys.Main.ArgumentType..tostring(Table[i].Arguments[j][2]).."")
        
            elseif Table[i].Arguments[j][1] == "Vec" or Table[i].Arguments[j][1] == "Euler" then
                table.insert(ArgTable, ""..Table[i].Arguments[j][1]..Keys.Main.ArgumentType..table.concat(Table[i].Arguments[j][2],Keys.Transform.Value).."")
                
            elseif Table[i].Arguments[j][1] == "Transform" then
                local TransformTable = {}
                for k=1,#Table[i].Arguments[j][2] do
                    local Type = Table[i].Arguments[j][2][k][1]
                    local Value = Table[i].Arguments[j][2][k][2]
                    table.insert(TransformTable, ""..Type..Keys.Transform.Type..table.concat(Value, Keys.Transform.Value).."")
                end
                table.insert(ArgTable, ""..Table[i].Arguments[j][1]..Keys.Main.ArgumentType..table.concat(TransformTable, Keys.Transform.TransformSeperator).."")
                
            elseif Table[i].Arguments[j][1] == "Table" then
                local NewTable = {}
                for k=1,#Table[i].Arguments[j][2] do
                    local Type = Table[i].Arguments[j][2][k][1]
                    local Value = Table[i].Arguments[j][2][k][2]
                    CoolString = ""
                        
                    if Type == "Bool" or Type == "String" or Type == "Number" then
                        CoolString = ""..Type..Keys.Table.Type..tostring(Value)..""
                    
                    elseif Type == "Vec" then
                        CoolString = ""..Type..Keys.Table.Type..table.concat(Value, Keys.Transform.Value)..""
                        
                    elseif Type == "Euler" then
                        CoolString = ""..Type..Keys.Table.Type..table.concat(Value, Keys.Transform.Value)..""
                        
                    elseif Type == "Transform" then
                        local TransformTable = {}
                        for g=1,#Table[i].Arguments[j][2][k][2] do
                            local NewType = Table[i].Arguments[j][2][k][2][g][1]
                            local NewValue = Table[i].Arguments[j][2][k][2][g][2]
                            table.insert(TransformTable, ""..NewType..Keys.Transform.Type..table.concat(NewValue, Keys.Transform.Value).."")
                        end
                            
                        CoolString = ""..Type..Keys.Table.Type..table.concat(TransformTable, Keys.Transform.TransformSeperator)..""
                    end
                    table.insert(NewTable, CoolString)
                end
                table.insert(ArgTable, ""..Table[i].Arguments[j][1]..Keys.Main.ArgumentType..table.concat(NewTable,Keys.Table.Values).."")
            end    
        end
        local String = ''..Table[i].FunctionName..Keys.Main.Type..table.concat(ArgTable, Keys.Main.Arguments)..''
        table.insert(Strings, String)
    end
    
    return table.concat(Strings, Keys.Main.Primary)
end

function SendToListener(TBL)
    if CreateEntries then
		TriggerEvent("Tabs Vehicle Spawner Listener", SerializeSpecialTable(TBL))
	end
end

function CreateSpawnCountry(country, periods, page, image)
	local Code = {
		{
			FunctionName = "ExternalCreateSpawnCountry",
			Arguments = {
				{"String", country},
				{"Table", {}},
				{"Number", page},
				{"String", image},
				{"String", Key},	
				{"String", Path},
			}
		},
	}
	if type(periods) == 'table' then
		for i=1,#periods do
			table.insert(Code[1].Arguments[2][2], {"String", periods[i]})
		end
	else
		table.insert(Code[1].Arguments[2][2], {"String", periods})
	end
	SendToListener(Code)
	if ReturnValue then
		table.insert(Additions.Countries, country)
	end
end

function CreateVehicle(country, period, category, name, image, variants)
	local ArgKeys = {'~Divider1~','~Divider2~','~Divider3~'}
	local Code = {
		{
			FunctionName = "ExternalCreateVehicle",
			Arguments = {
				{"String", country},
				{"String", period},
				{"String", category},
				{"String", name},
				{"String", image},
				{"String", nil},
				{"String", Key},
				{"String", Path},
			}
		},
	}
	local Strings = {}
	for i=1,#variants do
		local Strings2 = {}
		for k, v in pairs(variants[i]) do
			table.insert(Strings2, ''..k..''..ArgKeys[1]..''..v..'')
		end
		table.insert(Strings, table.concat(Strings2, ArgKeys[2]))
	end
	Code[1].Arguments[6][2] = table.concat(Strings, ArgKeys[3])
	SendToListener(Code)
	if ReturnValue then
		table.insert(Additions.Vehicles, name)
	end
end

function CreateEra(country, periods)
		local Code = {
		{
			FunctionName = "ExternalCreateEra",
			Arguments = {
				{"String", country},
				{"Table", {}},
			}
		},
	}

	if type(periods) == 'table' then
		for i=1,#periods do
			table.insert(Code[1].Arguments[2][2], {"String", periods[i]})
		end
	else
		table.insert(Code[1].Arguments[2][2], {"String", periods})
	end
	SendToListener(Code)
end

function CreateVehicleCategory(country, period, category, image)
	local Code = {
		{
			FunctionName = "ExternalCreateVehicleCategory",
			Arguments = {
				{"String", country},
				{"String", period},
				{"String", category},
				{"String", image},
				{"String", Key},	
				{"String", Path},
			}
		},
	}
	
	SendToListener(Code)
	if ReturnValue then
		table.insert(Additions.Categories, category)
	end
end

function init()
	SpawnInit()
	if ReturnValue then
		local SerialKey = {'~TheKeyIsCool~', '~TheKeyIsCooler~', '~TheKeyIsCoolest~'}
		local Strings = {}
		for k,v in pairs(Additions) do
			table.insert(Strings, ''..k..SerialKey[1]..table.concat(v,SerialKey[2])..'')
		end
		SetString('game.TABS.Vehicles.Modded.Spawn.Menu.Current.Return', table.concat(Strings, SerialKey[3]))
	end
end