Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2023-12-07, 16:34


sabarupl







Wiek: 43
Na forum: 4966 dni
Posty: 347

Piwa: 163

Respekt: 230
Respekt: 230Respekt: 230

Od dawien dawna testuje sobie ChatGPT. ChatGPT napisał mi nie jeden skrypt do MTA. Co o dziwo większość z nich działa. Jedno co mnie ciekawi na ile one są sprawne żeby można by było je wrzucić na serwer i nie powodowały błędów, mogli z nich korzystać inni gracze itd.
Sam się na dokładnej budowie skryptów nie znam, nie ogarniam tego. Jedynie potrafię takie bardzo proste skrypty napisać. Moim konikiem jest modelowanie modeli i w połączeniu z ChatGPT daje nowe możliwości w tworzeniu modeli. Tutaj dla przykładu podaje skrypt na radio. Radio można włączyć po przez markera. Zmienić stacje, wyłączyć i zmieniać głośność i to za pomocą klawiszy na klawiaturze. W sumie pytam z ciekawości. na ile on jest poprawnie napisany?
local markerX, markerY, markerZ = -684.65417, 935.66187, 12.33281
local marker = createMarker(markerX, markerY, markerZ, "cylinder", 1.0, 0, 255, 0, 150)
local defaultVolume, radioStream, currentStationIndex, isRadioPlaying, isInMarker, isBKeyUsed = 1.0, nil, 1, false, false, false

-- Dodaj stacje radiowe
local stations = {
    { url = "http://audio.radio.opole.pl:9000/ro1mp3", name = "Radio Opole" },
    { url = "http://n-16-8.dcs.redcdn.pl/sc/o2/Eurozet/live/meloradio.livx?audio=5", name = "Meloradio" },
    { url = "http://srv0.streamradiowy.eu:80/radio90-aac", name = "Radio 90" }
}

local lastVolumeUpdateTime = 0  -- Czas ostatniej aktualizacji głośności
local lastVolumeChangeMessage = ""  -- Ostatni komunikat o zmianie głośności
local lightEffect = nil  -- Zmienna przechowująca efekt światła

function onPlayerEnterMarker(hitElement, matchingDimension)
    if hitElement == localPlayer and matchingDimension then
        if not isRadioPlaying then
            outputChatBox("Wciśnij klawisz N aby włączyć radio, ponownie N żeby zmienić stacje, B żeby wyłączyć!", 0, 255, 0)
        end
        isInMarker = true
        bindKey("n", "down", onKeyPress_N)
        bindKey("b", "down", onKeyPress_B)
        bindKey("num_add", "down", onKeyPress_NumAdd)  -- Klawisz plus na klawiaturze numerycznej
        bindKey("num_sub", "down", onKeyPress_NumSub)  -- Klawisz minus na klawiaturze numerycznej

        -- Dodaj efekt światła
        lightEffect = createLight(markerX, markerY, markerZ, 0, 255, 0, 10, 10, 0)
        setElementData(localPlayer, "radioLightEffect", lightEffect)
    end
end
addEventHandler("onClientMarkerHit", marker, onPlayerEnterMarker)

function onPlayerExitMarker(hitElement, matchingDimension)
    if hitElement == localPlayer and matchingDimension then
        isInMarker = false
        unbindKey("n", "down", onKeyPress_N)
        unbindKey("b", "down", onKeyPress_B)
        unbindKey("num_add", "down", onKeyPress_NumAdd)
        unbindKey("num_sub", "down", onKeyPress_NumSub)

        -- Usuń efekt światła
        if isElement(lightEffect) then
            destroyElement(lightEffect)
            setElementData(localPlayer, "radioLightEffect", nil)
        end
    end
end
addEventHandler("onClientMarkerLeave", marker, onPlayerExitMarker)

function playRadio()
    if isInMarker and not isRadioPlaying then
        stopRadio()

        local station = stations[currentStationIndex]
        if station then
            radioStream = playSound3D(station.url, markerX, markerY, markerZ, true)
            setSoundVolume(radioStream, defaultVolume)
            isRadioPlaying = true
            outputChatBox("Odtwarzanie stacji: " .. station.name, 0, 255, 0)
        else
            outputChatBox("Brak stacji radiowej.", 255, 0, 0)
        end
    end
end

function stopRadio()
    if isElement(radioStream) then
        stopSound(radioStream)
        radioStream = nil
        isRadioPlaying = false
    end
end

function onKeyPress_N(key, state)
    if key == "n" and state == "down" then
        if isRadioPlaying then
            changeRadioStation()
        else
            playRadio()
        end
    end
end

function onKeyPress_B(key, state)
    if key == "b" and state == "down" then
        if isRadioPlaying then
            stopRadio()
            outputChatBox("Radio zostało wyłączone.", 0, 255, 0)
        end
    end
end

function onKeyPress_NumAdd(key, state)
    if key == "num_add" and state == "down" then
        if isRadioPlaying and defaultVolume < 1.0 then
            adjustRadioVolume(0.1)  -- Zwiększ głośność o 0.1
        end
    end
end

function onKeyPress_NumSub(key, state)
    if key == "num_sub" and state == "down" then
        if isRadioPlaying and defaultVolume > 0.0 then
            adjustRadioVolume(-0.1)  -- Zmniejsz głośność o 0.1
        end
    end
end

function adjustRadioVolume(amount)
    local newVolume = math.round(math.max(0, math.min(1, defaultVolume + amount)), 1)
    
    if newVolume ~= defaultVolume or getTickCount() - lastVolumeUpdateTime > 1000 then
        defaultVolume = newVolume
        setSoundVolume(radioStream, defaultVolume)
        lastVolumeUpdateTime = getTickCount()

        local volumeMessage = "Głośność radia: " .. math.floor(defaultVolume * 100) .. "%"
        if volumeMessage ~= lastVolumeChangeMessage then
            outputChatBox(volumeMessage, 0, 255, 0)
            lastVolumeChangeMessage = volumeMessage
        end
    end
end

function changeRadioStation()
    if isInMarker then
        currentStationIndex = currentStationIndex % #stations + 1
        stopRadio()
        playRadio()
    end
end

function updateRadioVolume()
    if isRadioPlaying and isElement(radioStream) then
        local x, y, z = getElementPosition(localPlayer)
        local markerDistance = getDistanceBetweenPoints3D(x, y, z, markerX, markerY, markerZ)
        local maxDistance = 30  -- Maksymalna odległość, na której głośność wynosi 0
        local volumeScale = 1 - math.min(1, markerDistance / maxDistance)
        setSoundVolume(radioStream, defaultVolume * volumeScale)
    end
end

addEventHandler("onClientRender", root, updateRadioVolume)

-- Funkcja zaokrąglająca do określonej liczby miejsc dziesiętnych
function math.round(number, decimals)
    local factor = 10 ^ (decimals or 0)
    return math.floor(number * factor + 0.5) / factor
end


Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Wysłany: 2023-12-07, 16:49


VVirmex

Sgrypter luja






Wiek: 21
Na forum: 3506 dni
Posty: 284
Nick w MP: AxyZ

Piwa: 235

Respekt: 110
Respekt: 110

Sprawa jest prosta - jeśli nie wyrzuca ci żadnych błędów na debugscript 3 po przetestowaniu w pełni działania skryptu, to bez problemu powinien chodzić i być używany przez graczy. Jedynym zgrzytem może być optymalizacja, ale na mój rzut oka wygląda wszystko okej :)

Postaw piwo autorowi tego posta
 

 
Więcej szczegółów
Wystawiono 1 piw(a):
borsuk
Tagi: chatgpt :: ile :: poprawnie :: ten :: skrypt :: jest :: napisany :: radio.
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku