ed
This commit is contained in:
		
							parent
							
								
									75b73b9c45
								
							
						
					
					
						commit
						6b4ab46e6c
					
				
					 3 changed files with 229 additions and 2 deletions
				
			
		
							
								
								
									
										181
									
								
								resources/[carscripts]/mh_garage/server/vehicleadmin.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								resources/[carscripts]/mh_garage/server/vehicleadmin.lua
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,181 @@ | |||
| -- vehicleadmin.lua - Füge diese Datei in deinen server-Ordner ein | ||||
|  | ||||
| -- Erweitere die Log-Funktion für das Fahrzeugadmin-System | ||||
| RegisterServerEvent('vehicleadmin:log') | ||||
| AddEventHandler('vehicleadmin:log', function(action, plate, garage) | ||||
|     local src = source | ||||
|     local Player = QBCore.Functions.GetPlayer(src) | ||||
|      | ||||
|     if not Player then return end | ||||
|      | ||||
|     local playerName = Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname | ||||
|     local citizenid = Player.PlayerData.citizenid | ||||
|     local jobName = Player.PlayerData.job.name | ||||
|     local jobLabel = Player.PlayerData.job.label | ||||
|      | ||||
|     local logText = "" | ||||
|     local logColor = "blue" | ||||
|      | ||||
|     if action == "move" then | ||||
|         logText = playerName .. " (" .. jobLabel .. ") hat Fahrzeug " .. plate .. " in Garage " .. garage .. " gestellt." | ||||
|     elseif action == "delete" then | ||||
|         logText = playerName .. " (" .. jobLabel .. ") hat Fahrzeug " .. plate .. " von der Map gelöscht." | ||||
|         logColor = "orange" | ||||
|     elseif action == "repair" then | ||||
|         logText = playerName .. " (" .. jobLabel .. ") hat Fahrzeug " .. plate .. " repariert." | ||||
|         logColor = "green" | ||||
|     end | ||||
|      | ||||
|     -- Verwende die bestehende Log-Funktion | ||||
|     sendToDiscord("Fahrzeugadmin", logText, logColor) | ||||
|      | ||||
|     -- Speichere den Log in der Datenbank (optional) | ||||
|     MySQL.Async.execute('INSERT INTO admin_logs (action, player_name, citizenid, job, target_plate, target_garage, timestamp) VALUES (?, ?, ?, ?, ?, ?, NOW())', | ||||
|         {action, playerName, citizenid, jobName, plate, garage or "none"}) | ||||
| end) | ||||
|  | ||||
| -- Füge zusätzliche Callback-Funktionen für erweiterte Features hinzu | ||||
| QBCore.Functions.CreateCallback('vehicleadmin:getVehicleHistory', function(source, cb, plate) | ||||
|     local src = source | ||||
|     local Player = QBCore.Functions.GetPlayer(src) | ||||
|      | ||||
|     if not Player then  | ||||
|         cb(false) | ||||
|         return  | ||||
|     end | ||||
|      | ||||
|     -- Prüfe, ob der Spieler die Berechtigung hat | ||||
|     local hasPermission = false | ||||
|     local playerJob = Player.PlayerData.job.name | ||||
|      | ||||
|     if QBCore.Functions.HasPermission(src, 'admin') then | ||||
|         hasPermission = true | ||||
|     elseif playerJob == 'police' or playerJob == 'mechanic' then | ||||
|         hasPermission = true | ||||
|     end | ||||
|      | ||||
|     if not hasPermission then | ||||
|         cb(false) | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Hole den Fahrzeugverlauf aus der Datenbank | ||||
|     MySQL.Async.fetchAll('SELECT * FROM admin_logs WHERE target_plate = ? ORDER BY timestamp DESC LIMIT 20', {plate}, function(results) | ||||
|         if results and #results > 0 then | ||||
|             cb(results) | ||||
|         else | ||||
|             cb({}) | ||||
|         end | ||||
|     end) | ||||
| end) | ||||
|  | ||||
| -- Füge einen Event-Handler für das Löschen von Fahrzeugen hinzu | ||||
| RegisterServerEvent('vehicleadmin:deleteVehicle') | ||||
| AddEventHandler('vehicleadmin:deleteVehicle', function(plate) | ||||
|     local src = source | ||||
|     local Player = QBCore.Functions.GetPlayer(src) | ||||
|      | ||||
|     if not Player then return end | ||||
|      | ||||
|     -- Prüfe, ob der Spieler die Berechtigung hat | ||||
|     local hasPermission = false | ||||
|     local playerJob = Player.PlayerData.job.name | ||||
|      | ||||
|     if QBCore.Functions.HasPermission(src, 'admin') then | ||||
|         hasPermission = true | ||||
|     elseif playerJob == 'police' or playerJob == 'mechanic' then | ||||
|         hasPermission = true | ||||
|     end | ||||
|      | ||||
|     if not hasPermission then | ||||
|         TriggerClientEvent('ox_lib:notify', src, { | ||||
|             title = 'Keine Berechtigung', | ||||
|             description = 'Du hast keine Berechtigung für diese Aktion', | ||||
|             type = 'error' | ||||
|         }) | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Lösche das Fahrzeug aus der Datenbank | ||||
|     MySQL.Async.execute('DELETE FROM player_vehicles WHERE plate = ?', {plate}, function(rowsChanged) | ||||
|         if rowsChanged > 0 then | ||||
|             -- Lösche auch alle zugehörigen Schlüssel | ||||
|             MySQL.Async.execute('DELETE FROM vehicle_keys WHERE plate = ?', {plate}) | ||||
|              | ||||
|             -- Lösche das Fahrzeug aus dem Parking-System | ||||
|             MySQL.Async.execute('DELETE FROM vehicle_parking WHERE plate = ?', {plate}) | ||||
|              | ||||
|             -- Log die Aktion | ||||
|             TriggerEvent('vehicleadmin:log', "delete_permanent", plate, nil) | ||||
|              | ||||
|             TriggerClientEvent('ox_lib:notify', src, { | ||||
|                 title = 'Fahrzeugverwaltung', | ||||
|                 description = 'Fahrzeug wurde permanent gelöscht', | ||||
|                 type = 'success' | ||||
|             }) | ||||
|         else | ||||
|             TriggerClientEvent('ox_lib:notify', src, { | ||||
|                 title = 'Fahrzeugverwaltung', | ||||
|                 description = 'Fahrzeug nicht gefunden', | ||||
|                 type = 'error' | ||||
|             }) | ||||
|         end | ||||
|     end) | ||||
| end) | ||||
|  | ||||
| -- Füge einen Event-Handler für das Ändern des Fahrzeugbesitzers hinzu | ||||
| RegisterServerEvent('vehicleadmin:changeOwner') | ||||
| AddEventHandler('vehicleadmin:changeOwner', function(plate, newOwnerCID) | ||||
|     local src = source | ||||
|     local Player = QBCore.Functions.GetPlayer(src) | ||||
|      | ||||
|     if not Player then return end | ||||
|      | ||||
|     -- Prüfe, ob der Spieler die Berechtigung hat | ||||
|     if not QBCore.Functions.HasPermission(src, 'admin') then | ||||
|         TriggerClientEvent('ox_lib:notify', src, { | ||||
|             title = 'Keine Berechtigung', | ||||
|             description = 'Nur Admins können den Besitzer ändern', | ||||
|             type = 'error' | ||||
|         }) | ||||
|         return | ||||
|     end | ||||
|      | ||||
|     -- Prüfe, ob der neue Besitzer existiert | ||||
|     MySQL.Async.fetchAll('SELECT * FROM players WHERE citizenid = ?', {newOwnerCID}, function(players) | ||||
|         if not players or #players == 0 then | ||||
|             TriggerClientEvent('ox_lib:notify', src, { | ||||
|                 title = 'Fehler', | ||||
|                 description = 'Spieler mit dieser Citizen ID nicht gefunden', | ||||
|                 type = 'error' | ||||
|             }) | ||||
|             return | ||||
|         end | ||||
|          | ||||
|         -- Ändere den Besitzer des Fahrzeugs | ||||
|         MySQL.Async.execute('UPDATE player_vehicles SET citizenid = ? WHERE plate = ?', {newOwnerCID, plate}, function(rowsChanged) | ||||
|             if rowsChanged > 0 then | ||||
|                 -- Erstelle einen neuen Schlüssel für den neuen Besitzer | ||||
|                 MySQL.Async.execute('INSERT INTO vehicle_keys (plate, owner, count) VALUES (?, ?, 1) ON DUPLICATE KEY UPDATE count = 1', {plate, newOwnerCID}) | ||||
|                  | ||||
|                 -- Log die Aktion | ||||
|                 local newOwnerInfo = json.decode(players[1].charinfo) | ||||
|                 local newOwnerName = newOwnerInfo.firstname .. " " .. newOwnerInfo.lastname | ||||
|                  | ||||
|                 TriggerEvent('vehicleadmin:log', "change_owner", plate, newOwnerName) | ||||
|                  | ||||
|                 TriggerClientEvent('ox_lib:notify', src, { | ||||
|                     title = 'Fahrzeugverwaltung', | ||||
|                     description = 'Fahrzeugbesitzer wurde geändert', | ||||
|                     type = 'success' | ||||
|                 }) | ||||
|             else | ||||
|                 TriggerClientEvent('ox_lib:notify', src, { | ||||
|                     title = 'Fahrzeugverwaltung', | ||||
|                     description = 'Fahrzeug nicht gefunden', | ||||
|                     type = 'error' | ||||
|                 }) | ||||
|             end | ||||
|         end) | ||||
|     end) | ||||
| end) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98