[RE-RELEASE] garages async/couchdb

Dude you are such a badass, been trying so hard to get checkplate working! Keep it up man.

np man enjoy it while its still up, because its possible they may take it back down lol… idk for sure though.

Thanks man, nice work

No problem thank you for the reply!

Hey ! Sorry for my english, i’m french, i have a little problem,

I have only one place in the garage. I can buy several vehicles and store them, but only the first one is registered in the database, and there is only him that I can leave. All other vehicles purchased enter the garage but do not exit. The garage is locked in a single place. How can I increase this number of places?

So where i can get es_garages?

will this one work? [Release] [ES] es_garages | Vehicle Ownership & Garages

or you have also a modified version for it?

Yes the es garages you mentioned is the correct one. At the bottom of its thread i put all the vehicles so you dont have to :slight_smile:

1 Like

this dose work with couch right ?

yes, however you do also need mysql-async

You need them both, but you dont need es 2.0 just es 3.0

Will this work for addon vehicles? We run custom PD cars, was curious as to if we could spawn them via the Cops FiveM mod garage, register it, then save it in our garage

as long as you can spawn them via the model name then sure, you just gotta add them!

Awesome, appreciate the work man!

Np, and dont forget to send your love to the original creator of the base files as well!

So I added our custom police cars to the database under vehicles table but it will not let us register them. Also can’t seem to get the check plate working, replaced all you said, still no luck. Anything special I have to do there like with the weaponshop database ?

Just keeps saying “No nearby vehicle” or w/e

what do you mean you added them to the database? if you add new cars to the system, you need to do it in es_garages, in that script you can add cars in the vehicles tables in server file and client file.

Oh ok may not work out then, don’t want civs buying out cop cars haha. But I added them to the vehicle table on mysql

I know I am always asking questions and such but did we confirm the replacement codes you posted for the vehicle check plate work? I am running all 3 of these scripts and esm 3.x. Have my everything on couchdb minus the ply_garages and ply_prefecture.

This is the code that allows check-plate feature on police script this is server.lua

local couchFunctions = {}
local namesforperps = {
"Trisha Blevins",
"Kyle Smith",
"Timmothy Holland",
"Reba Forks",
"Jennifer Rollins",
"Sandy Barns",
"Alexandria Scott",
"Dillone Scott",

}
if(db.driver == "mysql") then
	require "resources/essentialmode/lib/MySQL"
	MySQL:open(db.sql_host, db.sql_database, db.sql_user, db.sql_password)
elseif(db.driver == "mysql-async") then
	require "resources/mysql-async/lib/MySQL"
	TriggerEvent('es:exposeDBFunctions', function(dbExposed)
		couchFunctions = dbExposed
		dbExposed.createDatabase("police", function()end)
	end)

	
end

local inServiceCops = {}

function addCop(identifier)
	
	if(db.driver == "mysql") then
		local result = "nil"
		local query = MySQL:executeQuery("SELECT * FROM police WHERE identifier = '@identifier'", { ['@identifier'] = identifier})
		local resultq = MySQL:getResults(query, {'rank'}, "identifier")
		
		if(not resultq[1]) then
			result = "nil"
		else
			result = resultq[1].rank
		end
		
		if(result == "nil") then
			MySQL:executeQuery("INSERT INTO police (`identifier`) VALUES ('@identifier')", { ['@identifier'] = identifier})
		end
		
	elseif(db.driver == "mysql-async") then
		MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier = @identifier", { ['@identifier'] = identifier}, function (result)
			if(result[1] == nil) then
				MySQL.Async.execute("INSERT INTO police (`identifier`) VALUES @identifier", { ['@identifier'] = identifier})
			end
		end)
	
		couchFunctions.getDocumentByRow("police", "identifier", identifier, function(document)
			if(document == false) then
				couchFunctions.createDocument("police", {
					identifier = identifier,
					rank = "Recruit"
				}, function()end)
			end
		end)
	end
end

function remCop(identifier)
	if(db.driver == "mysql") then
		MySQL:executeQuery("DELETE FROM police WHERE identifier = '@identifier'", { ['@identifier'] = identifier})
	elseif(db.driver == "mysql-async") then
		MySQL.Async.execute("DELETE FROM police WHERE identifier = @identifier", { ['@identifier'] = identifier})
	
		couchFunctions.getDocumentByRow("police", "identifier", identifier, function(document)
			if(document ~= false) then
				couchFunctions.updateDocument("police", document._id, {
					identifier = document.identifier .. "/"
				}, function()end)
			end
		end)
	end
end

function checkIsCop(identifier)
	if(db.driver == "mysql") then
		local query = MySQL:executeQuery("SELECT * FROM police WHERE identifier = '@identifier'", { ['@identifier'] = identifier})
		local result = MySQL:getResults(query, {'rank'}, "identifier")
		
		if(not result[1]) then
			TriggerClientEvent('police:receiveIsCop', source, "unknown")
		else
			TriggerClientEvent('police:receiveIsCop', source, result[1].rank)
		end
	elseif(db.driver == "mysql-async") then
		MySQL.Async.fetchAll("SELECT * FROM police WHERE identifier = @identifier", { ['@identifier'] = identifier}, function (result)
			if(result[1] == nil) then
				TriggerClientEvent('police:receiveIsCop', source, "unknown")
			else
				TriggerClientEvent('police:receiveIsCop', source, result[1].rank)
			end
		end)
	
		couchFunctions.getDocumentByRow("police", "identifier", identifier, function(document)
			if(document == false) then
				TriggerClientEvent('police:receiveIsCop', source, "unknown")
			else
				TriggerClientEvent('police:receiveIsCop', source, document.rank)
			end
		end)
	end
end

AddEventHandler('playerDropped', function()
	if(inServiceCops[source]) then
		inServiceCops[source] = nil
		
		if(config.useJobSystem == true) then
			TriggerEvent("jobssystem:disconnectReset", source, config.job.officer_not_on_duty_job_id)
		end
		
		for i, c in pairs(inServiceCops) do
			TriggerClientEvent("police:resultAllCopsInService", i, inServiceCops)
		end
	end
end)

if(config.useCopWhitelist == true) then
	RegisterServerEvent('police:checkIsCop')
	AddEventHandler('police:checkIsCop', function()
		local identifier = getPlayerID(source)
		checkIsCop(identifier)
	end)
end
RegisterServerEvent('bank:withdrawAmende')
AddEventHandler('bank:withdrawAmende', function(amount)
    TriggerEvent('es:getPlayerFromId', source, function(user)
        local player = user.identifier
        local bankbalance = bankBalance(player)
		withdraw(player, amount)
		local new_balance = bankBalance(player)
		TriggerClientEvent("es_freeroam:notify", source, "CHAR_BANK_MAZE", 1, "Maze Bank", false, "New Balance: ~g~$" .. new_balance)
		TriggerClientEvent("banking:updateBalance", source, new_balance)
		TriggerClientEvent("banking:removeBalance", source, amount)
		CancelEvent()
    end)
end)
RegisterServerEvent('police:takeService')
AddEventHandler('police:takeService', function()

	if(not inServiceCops[source]) then
		inServiceCops[source] = GetPlayerName(source)
		
		for i, c in pairs(inServiceCops) do
			TriggerClientEvent("police:resultAllCopsInService", i, inServiceCops)
		end
	end
end)

RegisterServerEvent('police:breakService')
AddEventHandler('police:breakService', function()

	if(inServiceCops[source]) then
		inServiceCops[source] = nil
		
		for i, c in pairs(inServiceCops) do
			TriggerClientEvent("police:resultAllCopsInService", i, inServiceCops)
		end
	end
end)

RegisterServerEvent('police:getAllCopsInService')
AddEventHandler('police:getAllCopsInService', function()
	TriggerClientEvent("police:resultAllCopsInService", source, inServiceCops)
end)

RegisterServerEvent('police:checkingPlate')
AddEventHandler('police:checkingPlate', function(plate)

	if(db.driver == "mysql") then
		local executed_query = MySQL:executeQuery("SELECT Nom FROM user_vehicle JOIN users ON user_vehicle.identifier = users.identifier WHERE vehicle_plate = '@plate'", { ['@plate'] = plate })
		local result = MySQL:getResults(executed_query, { 'Nom' }, "identifier")
		if (result[1]) then
			for _, v in ipairs(result) do
				TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["vehicle_checking_plate_part_1"]..plate..txt[config.lang]["vehicle_checking_plate_part_2"] .. v.Nom..txt[config.lang]["vehicle_checking_plate_part_3"])
			end
		else
			TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["vehicle_checking_plate_part_1"]..plate..txt[config.lang]["vehicle_checking_plate_not_registered"])
		end
	elseif(db.driver == "mysql-async") then
		MySQL.Async.fetchAll("SELECT * FROM user_vehicle WHERE vehicle_plate = @plate", { ['@plate'] = plate }, function (result)
				local isworking = false
				local name = " "
				local rands = math.random(1, 8)
				local chances = math.random(1, 1000)
				--TriggerClientEvent("chatMessage", source, "test ", {255, 0, 0}, " " .. tostring(result) .. " " .. tostring(plate))
				for _, v in ipairs(result) do
								--TriggerClientEvent("chatMessage", source, "test ", {255, 0, 0}, " " .. tostring(v.id))
								for i = 0, 31 do
								
								--if NetworkIsPlayerActive( i ) then
								--TriggerClientEvent("chatMessage", source, "test ", {255, 0, 0}, " " .. tostring(v.id))
								--local ids = GetPlayerFromServerId(1)
								--TriggerClientEvent("chatMessage", source, "test ", {255, 0, 0}, " " .. tostring(v.id))
									TriggerEvent('es:getPlayerFromId', i, function(user)
										
											--TriggerClientEvent("chatMessage", source, "test ", {255, 0, 0}, " " .. tostring(v.id))
											if user.identifier == v.identifier then
												name = GetPlayerName(tonumber(i))
												if name ~= " " then
													TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["vehicle_checking_plate_part_1"]..plate..txt[config.lang]["vehicle_checking_plate_part_2"] .. name..txt[config.lang]["vehicle_checking_plate_part_3"])
												end
											end
										
									end)
									--end
								end
										
								
							
						--end
					
					
				
			
				
			
		end
		if name == " " and chances < 500 then
			TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["vehicle_checking_plate_part_1"]..plate..txt[config.lang]["vehicle_checking_plate_part_2"] .. namesforperps[rands]..txt[config.lang]["vehicle_checking_plate_part_3"] .. " It seems the owner of this vehicle has not registered it!")
		elseif name == " " then
			TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["vehicle_checking_plate_part_1"]..plate..txt[config.lang]["vehicle_checking_plate_part_2"] .. namesforperps[rands]..txt[config.lang]["vehicle_checking_plate_part_3"] .. " It seems the owner has not registered the vehicle!")
		end
		end)
	end
	
end)
-- jail addon
RegisterServerEvent('jail:teleportToJail')
AddEventHandler('jail:teleportToJail', function(t, amount)
	TriggerClientEvent('jail:teleportPlayer', t, amount)
end)
-- jail addon end
RegisterServerEvent('police:confirmUnseat')
AddEventHandler('police:confirmUnseat', function(t)
	TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["unseat_sender_notification_part_1"] .. GetPlayerName(t) .. txt[config.lang]["unseat_sender_notification_part_2"])
	TriggerClientEvent('police:unseatme', t)
end)

RegisterServerEvent('police:dragRequest')
AddEventHandler('police:dragRequest', function(t)
	TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["drag_sender_notification_part_1"] .. GetPlayerName(t) .. txt[config.lang]["drag_sender_notification_part_2"])
	TriggerClientEvent('police:toggleDrag', t, source)
end)

RegisterServerEvent('police:targetCheckInventory')
AddEventHandler('police:targetCheckInventory', function(target)

	local identifier = getPlayerID(target)
	
	if(config.useVDKInventory == true) then
		if(db.driver == "mysql") then
			local strResult = txt[config.lang]["checking_inventory_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_inventory_part_2"]
			local executed_query = MySQL:executeQuery("SELECT * FROM `user_inventory` JOIN items ON items.id = user_inventory.item_id WHERE user_id = '@username'", { ['@username'] = identifier })
			local result = MySQL:getResults(executed_query, { 'quantity', 'libelle', 'item_id', 'isIllegal' }, "item_id")
			if (result) then
				for _, v in ipairs(result) do
					if(v.quantity ~= 0) then
						strResult = strResult .. v.quantity .. "*" .. v.libelle .. ", "
					end
					if(v.isIllegal == "1" or v.isIllegal == "True" or v.isIllegal == 1 or v.isIllegal == true) then
						TriggerClientEvent('police:dropIllegalItem', target, v.item_id)
					end
				end
			end
			
			TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
			
		elseif(db.driver == "mysql-async") then
			MySQL.Async.fetchAll("SELECT * FROM `user_inventory` JOIN items ON items.id = user_inventory.item_id WHERE user_id = @username", { ['@username'] = identifier }, function (result)
				local strResult = txt[config.lang]["checking_inventory_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_inventory_part_2"]
				
				for _, v in ipairs(result) do
					if(v.quantity ~= 0) then
						strResult = strResult .. v.quantity .. "*" .. v.libelle .. ", "
					end
					
					if(v.isIllegal == "1" or v.isIllegal == "True" or v.isIllegal == 1 or v.isIllegal == true) then
						TriggerClientEvent('police:dropIllegalItem', target, v.item_id)
					end
				end
				
				TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
			end)
		end
	end
	local check = true
	if(check == true) then
	
		if(db.driver == "mysql") then
			local strResult = txt[config.lang]["checking_weapons_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_weapons_part_2"]
		
			local executed_query = MySQL:executeQuery("SELECT * FROM user_weapons WHERE identifier = '@username'", { ['@username'] = identifier })
			local result = MySQL:getResults(executed_query, { 'weapon_model' }, 'identifier' )
			if (result) then
				for _, v in ipairs(result) do
					strResult = strResult .. v.weapon_model .. ", "
				end
			end
			
			TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
			
		elseif(db.driver == "mysql-async") then
				local del = {}
			
				local strResult = txt[config.lang]["checking_weapons_part_1"] .. GetPlayerName(target) .. txt[config.lang]["checking_weapons_part_2"]
				TriggerEvent('es:getPlayerFromId', target, function(user)
					TriggerEvent('es:exposeDBFunctions', function(db)
						db.getDocumentByRow('es_weashop', 'identifier', user.identifier, function(dbuser)
							for i=1, #dbuser.weapons do
								strResult = strResult .. dbuser.weapons[i] .. ", "
							end
							RemoveAllPedWeapons(target, true)
							TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, strResult)
							db.updateDocument('es_weashop', dbuser._id, {weapons = del, cost = del})
						end)
					end)
				end)
				
				
				
			
		end
	end	
end)

RegisterServerEvent('police:finesGranted')
AddEventHandler('police:finesGranted', function(target, amount)
	TriggerClientEvent('police:payFines', target, amount, source)
	TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["send_fine_request_part_1"]..amount..txt[config.lang]["send_fine_request_part_2"]..GetPlayerName(target))
end)

RegisterServerEvent('police:finesETA')
AddEventHandler('police:finesETA', function(officer, code)
	if(code==1) then
		TriggerClientEvent("police:notify", officer, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, GetPlayerName(source)..txt[config.lang]["already_have_a_pendind_fine_request"])
	elseif(code==2) then
		TriggerClientEvent("police:notify", officer, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, GetPlayerName(source)..txt[config.lang]["request_fine_timeout"])
	elseif(code==3) then
		TriggerClientEvent("police:notify", officer, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, GetPlayerName(source)..txt[config.lang]["request_fine_refused"])
	elseif(code==0) then
		TriggerClientEvent("police:notify", officer, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, GetPlayerName(source)..txt[config.lang]["request_fine_accepted"])
	end
end)

RegisterServerEvent('police:cuffGranted')
AddEventHandler('police:cuffGranted', function(t)
	TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["toggle_cuff_player_part_1"]..GetPlayerName(t)..txt[config.lang]["toggle_cuff_player_part_2"])
	TriggerClientEvent('police:getArrested', t)
end)

RegisterServerEvent('police:forceEnterAsk')
AddEventHandler('police:forceEnterAsk', function(t, v)
	TriggerClientEvent("police:notify", source, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["force_player_get_in_vehicle_part_1"]..GetPlayerName(t)..txt[config.lang]["force_player_get_in_vehicle_part_2"])
	TriggerClientEvent('police:forcedEnteringVeh', t, v)
end)

-----------------------------------------------------------------------
----------------------EVENT SPAWN POLICE VEH---------------------------
-----------------------------------------------------------------------
RegisterServerEvent('CheckPoliceVeh')
AddEventHandler('CheckPoliceVeh', function(vehicle)
	TriggerClientEvent('FinishPoliceCheckForVeh',source)
	TriggerClientEvent('policeveh:spawnVehicle', source, vehicle)
end)

-----------------------------------------------------------------------
---------------------COMMANDE ADMIN AJOUT / SUPP COP-------------------
-----------------------------------------------------------------------
if(config.useCopWhitelist) then

	TriggerEvent('es:addGroupCommand', 'copadd', "admin", function(source, args, user)
		 if(not args[2]) then
			TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["usage_command_copadd"])	
		else
			if(GetPlayerName(tonumber(args[2])) ~= nil)then
				local player = tonumber(args[2])
				addCop(getPlayerID(player))
				TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["command_received"])
				TriggerClientEvent("police:notify", player, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["become_cop_success"])
				TriggerClientEvent('police:nowCop', player)
			else
				TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["no_player_with_this_id"])
			end
		end
	end, function(source, args, user) 
		TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["not_enough_permission"])
	end)

	TriggerEvent('es:addGroupCommand', 'coprem', "admin", function(source, args, user) 
		 if(not args[2]) then
			print("nein")
			TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["usage_command_coprem"])	
		else
			if(GetPlayerName(tonumber(args[2])) ~= nil)then
				local player = tonumber(args[2])
				remCop(getPlayerID(player))
				TriggerClientEvent("police:notify", player, "CHAR_ANDREAS", 1, txt[config.lang]["title_notification"], false, txt[config.lang]["remove_from_cops"])
				TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["command_received"])
				TriggerClientEvent('police:noLongerCop', player)
			else
				TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["no_player_with_this_id"])
			end
		end
	end, function(source, args, user) 
		TriggerClientEvent('chatMessage', source, txt[config.lang]["title_notification"], {255, 0, 0}, txt[config.lang]["not_enough_permission"])
	end)
	
end

-- get's the player id without having to use bugged essentials
function getPlayerID(source)
    local identifiers = GetPlayerIdentifiers(source)
    local player = getIdentifiant(identifiers)
    return player
end

-- gets the actual player id unique to the player,
-- independent of whether the player changes their screen name
function getIdentifiant(id)
    for _, v in ipairs(id) do
        return v
    end
end

Dont worry about asking questions, I am here because i like to help people and i would hope if i needed help with a script then someone would help me :slight_smile: and so far people have!

If this for mysql, async or couch? I am running Couch for pretty much everything.