Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

I'm working on a fivem volleyball script I want to display a message on the middle of…

  1. User

    I'm working on a fivem volleyball script I want to display a message on the middle of the screen when an event is triggered with the argument game it will show you won a point or it will say you lost a point

  2. Assistant

    To display a message in the middle of the screen when an event is triggered in a FiveM script, you can use the drawText function with some styling. Here, I will provide you with an example of how you can display the message according to the value of the 'game' argument:

    -- Draw text on screen function
    function drawText(text, x, y, scale, red, green, blue, alpha)
        SetTextFont(4)
        SetTextProportional(0)
        SetTextScale(scale, scale)
        SetTextColour(red, green, blue, alpha)
        SetTextDropShadow(0, 0, 0, 0, 255)
        SetTextEdge(1, 0, 0, 0, 255)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry("STRING")
        AddTextComponentString(text)
        DrawText(x, y)
    end
    
    -- Function which will be called when the event is triggered
    function onVolleyballEvent(game)
        local text = ""
        local red, green, blue = 255, 255, 255
    
        if game == "won" then
            text = "You won a point!"
            green, blue = 0, 0
        elseif game == "lost" then
            text = "You lost a point!"
            red, green = 0, 0
        end
    
        local screenWidth, screenHeight = GetScreenResolution()
        local x = screenWidth / 2 / screenWidth
        local y = screenHeight / 2 / screenHeight
        local scale = 0.5
    
        -- Show message for 5 seconds
        local endTime = GetGameTimer() + 5000
        while GetGameTimer() < endTime do
            drawText(text, x, y, scale, red, green, blue, 255)
            Wait(0)
        end
    end
    
    -- Trigger the event
    TriggerEvent('volleyballEvent', onVolleyballEvent)
    

    Make sure to initialize the event in your script beforehand and replace 'volleyballEvent' with the name of your event. This example assumes the 'game' argument will be either "won" or "lost". You may modify this code to fit your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.