174 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			174 lines
		
	
	
	
		
			4.7 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| local nearTV = false
 | |
| local menuOpen = false
 | |
| 
 | |
| -- TV-Suche
 | |
| CreateThread(function()
 | |
|     while true do
 | |
|         local playerPed = PlayerPedId()
 | |
|         local playerCoords = GetEntityCoords(playerPed)
 | |
|         nearTV = false
 | |
| 
 | |
|         for _, model in pairs(Config.TVModels) do
 | |
|             local tv = GetClosestObjectOfType(playerCoords, 1.5, model, false, false, false)
 | |
|             if tv ~= 0 then
 | |
|                 nearTV = true
 | |
|                 break
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         if nearTV then
 | |
|             ShowHelpNotification(Config.Texts.PressE)
 | |
|             if IsControlJustReleased(0, 38) then -- "E" drücken
 | |
|                 OpenMainMenu()
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         Wait(0)
 | |
|     end
 | |
| end)
 | |
| 
 | |
| -- Hauptmenü öffnen
 | |
| function OpenMainMenu()
 | |
|     if menuOpen then return end
 | |
|     menuOpen = true
 | |
| 
 | |
|     local selected = NativeMenu(Config.MainMenu, Config.Texts.MainMenuTitle)
 | |
| 
 | |
|     if selected == "solo" then
 | |
|         OpenGameSelect("solo")
 | |
|     elseif selected == "duel" then
 | |
|         OpenGameSelect("duel")
 | |
|     end
 | |
| 
 | |
|     menuOpen = false
 | |
| end
 | |
| 
 | |
| -- Spielauswahl Menü
 | |
| function OpenGameSelect(mode)
 | |
|     local selectedGame = NativeMenu(Config.MiniGames, Config.Texts.SelectGameTitle)
 | |
| 
 | |
|     if selectedGame then
 | |
|         if mode == "solo" then
 | |
|             StartGame(selectedGame, nil)
 | |
|         elseif mode == "duel" then
 | |
|             SelectPlayer(function(target)
 | |
|                 StartGame(selectedGame, target)
 | |
|             end)
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| -- Spieler auswählen
 | |
| function SelectPlayer(callback)
 | |
|     local players = GetPlayers()
 | |
|     local playerMenu = {}
 | |
| 
 | |
|     for _, player in pairs(players) do
 | |
|         if player ~= PlayerId() then
 | |
|             local name = GetPlayerName(player)
 | |
|             table.insert(playerMenu, {label = name, id = GetPlayerServerId(player)})
 | |
|         end
 | |
|     end
 | |
| 
 | |
|     if #playerMenu == 0 then
 | |
|         ShowNotification(Config.Texts.NoPlayers)
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     local selected = NativeMenu(playerMenu, Config.Texts.InviteTitle)
 | |
| 
 | |
|     if selected then
 | |
|         callback(selected)
 | |
|     end
 | |
| end
 | |
| 
 | |
| -- Spiel starten
 | |
| function StartGame(gameType, opponent)
 | |
|     if opponent then
 | |
|         ShowNotification(Config.Texts.InviteSent)
 | |
|         -- Hier Server-Event für Duell senden
 | |
|     else
 | |
|         ShowNotification(Config.Texts.GameStarted .. gameType)
 | |
|         -- Hier Solo-Game starten
 | |
|     end
 | |
| end
 | |
| 
 | |
| -- Native Menü-Generator
 | |
| function NativeMenu(options, title)
 | |
|     local selected = 1
 | |
|     local active = true
 | |
| 
 | |
|     while active do
 | |
|         Wait(0)
 | |
|         DrawRect(0.5, 0.2, 0.3, 0.05, 0, 0, 0, 180)
 | |
|         DrawText2D(title, 0.5, 0.18, 0.8)
 | |
| 
 | |
|         for i = 1, #options do
 | |
|             local y = 0.22 + (i * 0.03)
 | |
|             if i == selected then
 | |
|                 DrawRect(0.5, y, 0.3, 0.03, 255, 255, 255, 100)
 | |
|             end
 | |
|             DrawText2D(options[i].label, 0.5, y, 0.5)
 | |
|         end
 | |
| 
 | |
|         if IsControlJustPressed(0, 172) then -- Pfeil Hoch
 | |
|             selected = selected - 1
 | |
|             if selected < 1 then selected = #options end
 | |
|         elseif IsControlJustPressed(0, 173) then -- Pfeil Runter
 | |
|             selected = selected + 1
 | |
|             if selected > #options then selected = 1 end
 | |
|         elseif IsControlJustPressed(0, 18) then -- Enter
 | |
|             local option = options[selected]
 | |
|             if option.action then
 | |
|                 return option.action
 | |
|             elseif option.game then
 | |
|                 return option.game
 | |
|             elseif option.id then
 | |
|                 return option.id
 | |
|             end
 | |
|             active = false
 | |
|         elseif IsControlJustPressed(0, 202) then -- Backspace
 | |
|             active = false
 | |
|         end
 | |
|     end
 | |
| 
 | |
|     return nil
 | |
| end
 | |
| 
 | |
| -- Text zeichnen
 | |
| function DrawText2D(text, x, y, scale)
 | |
|     SetTextFont(4)
 | |
|     SetTextProportional(0)
 | |
|     SetTextScale(scale, scale)
 | |
|     SetTextColour(255, 255, 255, 255)
 | |
|     SetTextCentre(1)
 | |
|     BeginTextCommandDisplayText("STRING")
 | |
|     AddTextComponentSubstringPlayerName(text)
 | |
|     EndTextCommandDisplayText(x, y)
 | |
| end
 | |
| 
 | |
| -- Spieler abrufen
 | |
| function GetPlayers()
 | |
|     local players = {}
 | |
|     for i = 0, 255 do
 | |
|         if NetworkIsPlayerActive(i) then
 | |
|             table.insert(players, i)
 | |
|         end
 | |
|     end
 | |
|     return players
 | |
| end
 | |
| 
 | |
| -- Notification
 | |
| function ShowNotification(msg)
 | |
|     BeginTextCommandThefeedPost("STRING")
 | |
|     AddTextComponentSubstringPlayerName(msg)
 | |
|     EndTextCommandThefeedPostMessagetext("CHAR_MULTIPLAYER", "CHAR_MULTIPLAYER", true, 1, "TV Game", msg)
 | |
|     EndTextCommandThefeedPostTicker(false, false)
 | |
| end
 | |
| 
 | |
| -- Hilfe Notification
 | |
| function ShowHelpNotification(msg)
 | |
|     BeginTextCommandDisplayHelp("STRING")
 | |
|     AddTextComponentSubstringPlayerName(msg)
 | |
|     EndTextCommandDisplayHelp(0, 0, 1, -1)
 | |
| end
 | 
