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: 4825 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 markerXmarkerYmarkerZ = -684.65417935.6618712.33281
local marker createMarker(markerXmarkerYmarkerZ"cylinder"1.002550150)
local defaultVolumeradioStreamcurrentStationIndexisRadioPlayingisInMarkerisBKeyUsed 1.0nil1falsefalsefalse

-- 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(hitElementmatchingDimension)
    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ć!"02550)
        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(markerXmarkerYmarkerZ0255010100)
        setElementData(localPlayer"radioLightEffect"lightEffect)
    end
end
addEventHandler("onClientMarkerHit"markeronPlayerEnterMarker)

function onPlayerExitMarker(hitElementmatchingDimension)
    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(lightEffectthen
            destroyElement(lightEffect)
            setElementData(localPlayer"radioLightEffect"nil)
        end
    end
end
addEventHandler("onClientMarkerLeave"markeronPlayerExitMarker)

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

        local station stations[currentStationIndex]
        if station then
            radioStream playSound3D(station.urlmarkerXmarkerYmarkerZtrue)
            setSoundVolume(radioStreamdefaultVolume)
            isRadioPlaying true
            outputChatBox("Odtwarzanie stacji: " .. station.name02550)
        else
            outputChatBox("Brak stacji radiowej."25500)
        end
    end
end

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

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

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

function onKeyPress_NumAdd(keystate)
    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(keystate)
    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(0math.min(1defaultVolume amount)), 1)
    
    if newVolume ~= defaultVolume or getTickCount() - lastVolumeUpdateTime 1000 then
        defaultVolume newVolume
        setSoundVolume(radioStreamdefaultVolume)
        lastVolumeUpdateTime getTickCount()

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

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

function updateRadioVolume()
    if isRadioPlaying and isElement(radioStreamthen
        local xygetElementPosition(localPlayer)
        local markerDistance getDistanceBetweenPoints3D(xyzmarkerXmarkerYmarkerZ)
        local maxDistance 30  -- Maksymalna odległośćna której głośność wynosi 0
        local volumeScale math.min(1markerDistance maxDistance)
        setSoundVolume(radioStreamdefaultVolume volumeScale)
    end
end

addEventHandler("onClientRender"rootupdateRadioVolume)

-- Funkcja zaokrąglająca do określonej liczby miejsc dziesiętnych
function math.round(numberdecimals)
    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: 3365 dni
Posty: 281
Nick w MP: AxyZ

Piwa: 234

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 » ChatGPT - na ile poprawnie ten skrypt jest napisany, radio. 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