Jump to content

playSound


Mr.Miracle

Recommended Posts

No thats not what he meant, he means that in the assault gamemod when the attack team finishs all objectives a sound will play. here's the script:

Server Side:

  
assaultTimers = {}
 
--[[
This one is called when a map is loaded. It reads the mapfile, creates the text displays and
lets player choose their teams, starting the first round afterwards
]]
function startAssaultMap(startedMap)
    local mapRoot = getResourceRootElement(startedMap)
    outputDebugString("Starting assault map..")
    if (readOptions(startedMap) == false) then
        outputChatBox("Error loading map")
        return
    end
   
    setWeather(options.weather)
   
    -- simulate the end of a round
    attacker = team2
   
    -- Create Objectives Text items
    removeTextItems()
    objectiveTextItem = {}
    objectiveTextItemShadow = {}
    local pos = 0.3
    for k,v in ipairs(options.objective) do
        --outputChatBox("created textdisplay for "..v.name)
        -- Objectives on the right
        --objectiveTextItem[k] = textCreateTextItem(v.name, 0.92, pos, "low", 255,255,255,255,1.4,"right")
        --objectiveTextItemShadow[k] = textCreateTextItem(v.name, 0.921, pos + 0.001, "low", 0, 0, 0, 255, 1.4,"right")
       
        -- Objectives on the left
        objectiveTextItem[k] = textCreateTextItem(v.name, 0.04, pos, "low", 255,255,255,255,1.4,"left")
        objectiveTextItemShadow[k] = textCreateTextItem(v.name, 0.041, pos + 0.001, "low", 0, 0, 0, 255, 1.4,"left")
       
        textDisplayAddText( statusDisplay, objectiveTextItemShadow[k] )
        textDisplayAddText( statusDisplay, objectiveTextItem[k] )
        pos = pos + 0.03
    end
   
    -- Remove player from noMapLoadedDisplay, fadeCamera and show team select display
    local players = getElementsByType("player")
    for k,v in ipairs(players) do
        fadeCamera(v,true)
        setNoMapLoaded( v, false )
        selectTeam( v )
        --outputConsole(getClientName(v))
        triggerClientEvent2( v, "assaultCreateGui", options )
    end
   
    noMapLoaded = false
   
    startRound()
end
--[[
Removes all required map-based settings when a map is stopped (but only if the resource wasnt stopped too)
]]
function stopAssaultMap()
    --outputDebugString(getResourceState(getResourceFromName("assault")))
    --outputDebugString(tostring(isElement(noMapLoadedDisplay)))
    outputDebugString("Stopping assault map..")
 
 
   
    noMapLoaded = true
   
    clearAllObjectives()
    removeTextItems()
   
    for k,v in pairs(assaultTimers) do
        if (isTimer(v)) then killTimer(v) end
    end
   
    -- Stop round timer
    --if (isTimer(assaultTimers.updateTimeLeft)) then
    --  killTimer(assaultTimers.updateTimeLeft)
    --end
    -- Add all players to noMapLoadedDisplay/toggleAllControls
    local players = getElementsByType("player")
    for k,v in ipairs(players) do
        setNoMapLoaded( v, true )
        textDisplayRemoveObserver( waitingDisplay, v )
        textDisplayRemoveObserver( waitingDisplay2, v )
       
        --toggleAllControls( v, false )
    end
end
 
function stopAssault()
    outputDebugString("Stopping assault..")
    removeEventHandler( "onGamemodeMapStop", getRootElement(), stopAssaultMap )
    call(getResourceFromName("scoreboard"), "removeScoreboardColumn", "score")
end
 
function removeTextItems()
-- Destroy map specific textitems
    if (objectiveTextItem == nil) then return end
    for k,v in ipairs(objectiveTextItem) do
        --textDisplayRemoveText(statusDisplay,v)
        --textDisplayRemoveText(objectiveTextItemShadow[k],statusDisplay)
        textDestroyTextItem(objectiveTextItemShadow[k])
        textDestroyTextItem(v)
        --outputChatBox("removing textitem")
    end
end
 
function setNoMapLoaded( player, bool )
    if (isElement(noMapLoadedDisplay) == false) then return end
   
    if (bool == true) then
        textDisplayAddObserver( noMapLoadedDisplay, player )
       
    else
        setTimer(textDisplayRemoveObserver,1000,1,noMapLoadedDisplay, player )
       
    end
end
 
--[[
This one prepares Assault when it is started. It creates the required teams, does some basic settings
and shows a text display as long as no map is loaded
]]
function startAssault(resource)
 
    noMapLoaded = true
   
    --outputChatBox("Now playing assault..")
   
    team1 = createTeam("Red",255,0,0)
    team2 = createTeam("Blue",0,0,255)
    team1Name = "Red"
    team2Name = "Blue"
   
    setTeamFriendlyFire( team1, false )
    setTeamFriendlyFire( team2, false )
 
   
 
    statusDisplay = textCreateDisplay()
    timeLeftTextItem = textCreateTextItem( "", 0.5, 0.02, "low", 255,255,255,255,1.8, "center" )
    textDisplayAddText( statusDisplay, timeLeftTextItem )
   
    waitingCreateDisplay()
    selectTeamCreateDisplay()
   
    local players = getElementsByType("player")
    for k,v in ipairs(players) do
        textDisplayAddObserver( statusDisplay, v )
        setNoMapLoaded( v, true )
        setElementDataLocal(v,"assaultToggleLogo",false)
        setElementDataLocal(v,"assaultCreateGui",false)
        setElementDataLocal(v,"assaultClientScriptLoaded",false)
        showPlayerHudComponent( v, "money", false )
    end
   
    attackerDisplay = textCreateDisplay()
    defenderDisplay = textCreateDisplay()
   
    team1Display = textCreateDisplay()
    team2Display = textCreateDisplay()
   
   
    --nextObjectiveText = textCreateTextItem("Next Objective: ", 0.5, 0.94, "low", 255,255,255,255, 1.2, "center")
    --textDisplayAddText( attackerDisplay, nextObjectiveText )
   
   
    --defenderText = textCreateTextItem("Prevent the attackers from reaching their objectives",0.5,0.94,"low",255,255,255,255,1.2,"center")
    --textDisplayAddText( defenderDisplay, defenderText )
   
    team1Text = textCreateTextItem("You are on: Red", 0.04, 0.24, "low", 255,0,0,255, 1.2, "left")
    team2Text = textCreateTextItem("You are on: Blue", 0.04, 0.24, "low", 0,0,255,255, 1.2, "left")
    textDisplayAddText( team1Display, team1Text )
    textDisplayAddText( team2Display, team2Text )
   
    roundText = textCreateTextItem( "Round 1/2", 0.5, 0.048, "low", 255,255,255,255,1.2, "center" )
    textDisplayAddText( statusDisplay, roundText )
   
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "score")
   
    --startAssaultMap(resource)
end
 
-- function updateTimeLeft()
    -- timeLeft = timeLeft - 1
    -- textItemSetText(timeLeftTextItem,calcTime(timeLeft))
    -- if (timeLeft <= 0) then
        -- killTimer(assaultTimers.updateTimeLeft)
        -- endRound()
    -- end
-- end
 
--[[
Prepares the round to be started
]]
function startRound()
    for k,v in ipairs(objectives) do
        textItemSetColor(objectiveTextItem[k],255,255,255,255)
    end
    clearAllObjectives()
    respawnAllVehicles()
    progress = 1
    waiting = true
   
    if (attacker == team1) then
        attacker = team2
        timeLimit = timeReachedBefore
        textItemSetText(roundText,"Round 2/2")
    elseif (attacker == team2) then
        attacker = team1
        timeLimit = options.timelimit
        textItemSetText(roundText,"Round 1/2")
    end
   
    createObjectives()
   
    local players = getElementsByType("player")
    for k,v in ipairs(players) do
        triggerClientEvent2(v,"assaultNextRound",attacker)
        if (getPlayerTeam(v)) then
            waitForStart(v)
            textDisplayRemoveObserver( waitingDisplay2, v )
        end
    end
    assaultTimers.startRoundNow = setTimer( startRoundNow, 4000, 1 )
end
--[[
Actually starts the round and spawns the players
]]
function startRoundNow()
    triggerEvent("onAssaultStartRound",getRootElement(),attacker)
    if (options.time ~= false) then setTime(gettok(options.time,1,58),gettok(options.time,2,58)) end
    waiting = false
    timeLeft = timeLimit
    -- if (isTimer(assaultTimers.updateTimeLeft)) then killTimer(assaultTimers.updateTimeLeft) end
    -- assaultTimers.updateTimeLeft = setTimer(updateTimeLeft,1000,timeLimit)
    g_missionTimer = exports.missiontimer:createMissionTimer (timeLimit*1000,true,false,0.5,20,true,"default-bold",1)
    addEventHandler ( "onMissionTimerElapsed", g_missionTimer, function() endRound(false) end )
    local players = getElementsByType("player")
    for k,v in ipairs(players) do
        if (getPlayerTeam(v)) then
            spawnPlayerTeam( v )
        end
        toggleAllControls( v, true )
        setElementData(v,"score",0)
    end
end
 
function waitForStart( player )
    if (isPedInVehicle( player )) then
        removePedFromVehicle( player ) end
   
   
Link to comment

Client Side:

  
 
function createGui(options)
   
    if (logo == nil) then
        -- Create logo
       
        local screenWidth, screenHeight = guiGetScreenSize()
        local sizeX = screenWidth/1280
        local sizeY = screenHeight/1024
        local width = 420*sizeX
        local height = 300*sizeY
        outputConsole("Creating image: "..width.."x"..height)
        logo = guiCreateStaticImage ( screenWidth/2-width/2, screenHeight/2-height/1.5, width, height, "logo.png", false, nil )
    end
   
    if (options == nil) then return end
    local justCreated = false
   
    if (assaultGui == nil) then
        --outputDebugString("Creating/updating assault gui")
        -- Get GUI from helpmanager
        assaultGui = call(getResourceFromName("helpmanager"), "addHelpTab", getThisResource(), true)
 
        -- Create tabs
        assaultGuiTabPanel = guiCreateTabPanel( 0, 0.04, 1, 1, true, assaultGui )
 
        tabMap = guiCreateTab( "Map Information", assaultGuiTabPanel )
        tabHelp = guiCreateTab( "Help", assaultGuiTabPanel )
       
        local version = guiCreateLabel(0.72,0.048,0.4,0.1,"Assault v1.0 by driver2",true,assaultGui)
        guiSetAlpha(version,0.4)
       
        justCreated = true
    end
   
    if (assaultGui == nil) then
        --outputDebugString("test")
    end
   
    -- TAB: Map Information
   
    if (justCreated) then
        text = "This page displays information about the map and it's objectives. To get general help, click on 'Help'."
        guiCreateLabel(0.02,0.04,0.94,0.2,text,true,tabMap)
    end
   
    -- General Map Information
    if (justCreated) then
        assaultGuiGrid2 = guiCreateGridList(0.02,0.1,0.96,0.3,true,tabMap)
        guiGridListAddColumn(assaultGuiGrid2,"Option",0.2)
        guiGridListAddColumn(assaultGuiGrid2,"Value",0.-- s8) -->
    else
        guiGridListClear(assaultGuiGrid2)
    end
    guiGridListAddRow( assaultGuiGrid2 )
    guiGridListSetItemText( assaultGuiGrid2, 0, 1, "Map", false, false )
    guiGridListSetItemText( assaultGuiGrid2, 0, 2, options.name, false, false )
    guiGridListAddRow( assaultGuiGrid2 )
    guiGridListSetItemText( assaultGuiGrid2, 1, 1, "Timelimit", false, false )
    guiGridListSetItemText( assaultGuiGrid2, 1, 2, calcTime(options.timelimit), false, false )
    guiGridListAddRow( assaultGuiGrid2 )
    guiGridListSetItemText( assaultGuiGrid2, 2, 1, "Finish Type", false, false )
    guiGridListSetItemText( assaultGuiGrid2, 2, 2, options.finishType, false, false )
    guiGridListAddRow( assaultGuiGrid2 )
    guiGridListSetItemText( assaultGuiGrid2, 3, 1, "Author", false, false )
    guiGridListSetItemText( assaultGuiGrid2, 3, 2, options.author, false, false )
    guiGridListAddRow( assaultGuiGrid2 )
    guiGridListSetItemText( assaultGuiGrid2, 4, 1, "Description", false, false )
    guiGridListSetItemText( assaultGuiGrid2, 4, 2, options.description, false, false )
   
    --guiGridListAutoSizeColumn(assaultGuiGrid2,1)
    guiGridListAutoSizeColumn(assaultGuiGrid2,2)
   
    -- Objective Information
    local objectivesTable = {}
    if (justCreated) then
        guiCreateLabel(0.02,0.42,0.92,0.1,"These are the attackers objectives:",true,tabMap)
        assaultGuiGrid = guiCreateGridList(0.02,0.48,0.96,0.44,true,tabMap)
        guiGridListAddColumn(assaultGuiGrid,"Objective",0.2)
        guiGridListAddColumn(assaultGuiGrid,"Description",0.-- s8) -->
    else
        guiGridListClear(assaultGuiGrid)
    end
   
    for k,v in ipairs(options.objective) do
        guiGridListAddRow( assaultGuiGrid )
        guiGridListSetItemText (assaultGuiGrid, k-1, 1, v.name, false, false)
        guiGridListSetItemText (assaultGuiGrid, k-1, 2, v.description, false, false)
    end
    --guiGridListAutoSizeColumn(assaultGuiGrid,1)
    guiGridListAutoSizeColumn(assaultGuiGrid,2)
   
   
    -- TAB: Help
   
    if (justCreated) then
        local text = "What to do:\n\n"
        text = text.."You need to reach objectives. These are usually checkpoints you need to enter, but it can also be "
        text = text.."something else. Click on 'Map Information' for details.\n\n"
        text = text.."When the attacking team reached the final objective, sides will be switched and the attacking team will "
        text = text.."defend, while the previously defending team will attack. The team that finishes faster wins the map. If "
        text = text.."neither team manages to finish within the timelimit, the map will end tied.\n\n"
        text = text.."The objectives are listed on the screen. Green color means they are next to be done by the attackers, "
        text = text.."red color indicates they are already done and white color means they have yet to be done, but others "
        text = text.."have to be done first. "
        text = text.."At the bottom of the screen, the current tasks for your team are displayed. You can cycle through them "
        text = text.."using F4, if necessary."
        text = text.."\n\n\n"
       
        text = text.."General Information:\n\n"
        text = text.."This gamemode is roughly based on UnrealTournament's Assault."
       
        local helpLabel = guiCreateLabel(0.02,0.04,0.94,0.92,text,true,tabHelp)
        guiLabelSetHorizontalAlign ( helpLabel, "left", true )
    end
   
   
   
end
 
function nextObjectivesText( objectives )
 
    currentObjectives = objectives
   
    --outputConsole(tostring(getElementData("assaultAttackingTeam")))
    --outputConsole("client next objectives "..tostring(getElementData(getLocalPlayer(),"assaultAttacker")))
   
    if (nextObjectivesLabel == nil) then
        --outputConsole("Creating next objectives text label")
        local screenWidth, screenHeight = guiGetScreenSize()
       
        -- background
        local background = guiCreateStaticImage ( 0, screenHeight - 22, screenWidth, 22, "blackpixel.png", false, nil )
        guiSetAlpha(background,0.5)
       
        nextObjectivesLabel = guiCreateLabel(0.1,screenHeight,screenWidth,10,"" ,false)
        local fontHeight = guiLabelGetFontHeight(nextObjectivesLabel)
        guiSetSize(nextObjectivesLabel,screenWidth,fontHeight,false)
        guiSetPosition(nextObjectivesLabel,10,screenHeight - fontHeight - 4,false)
        guiLabelSetColor(nextObjectivesLabel,255,255,255)
        --outputChatBox(tostring(guiBringToFront(nextObjectivesLabel)))
       
    end
   
    currentObjectiveShowing = 1
    currentObjectiveCount = #currentObjectives
    --outputChatBox(tostring(currentObjectiveCount))
    if (currentObjectiveCount > 0) then
        setCurrentObjectiveText(1)
        --guiSetText(nextObjectivesLabel,"Next objectives [1/"..currentObjectiveCount.."]: "..currentObjectives[1].text)
    end
end
function switchObjectivesText()
    if (currentObjectiveShowing == currentObjectiveCount) then
        currentObjectiveShowing = 1
    else
        currentObjectiveShowing = currentObjectiveShowing + 1
    end
    setCurrentObjectiveText(currentObjectiveShowing)
end
 
addCommandHandler( "Switch objective text", switchObjectivesText )
 
bindKey( "F4", "down", "Switch objective text" )
 
function setCurrentObjectiveText(number)
    local team = getPlayerTeam(getLocalPlayer())
    --outputChatBox("moo?"..tostring(team))
    if (team == false) then
        guiSetText(nextObjectivesLabel,"Choose a team..")
    else
        local description
        if (getPlayerTeam(getLocalPlayer()) == attacker) then
            description = currentObjectives[number].attackerText
        else
            description = currentObjectives[number].defenderText
        end
        local text
        if (currentObjectiveCount == 1) then
            text = "Next objective: "..description
        else
            text = "Next objectives ["..number.."/"..currentObjectiveCount.."]: "..description.." [F4 for next]"
        end
        guiSetText(nextObjectivesLabel,text)
    end
end
 
addEventHandler("onClientPlayerSpawn", getLocalPlayer(),
    function()
        setCurrentObjectiveText(currentObjectiveShowing)
    end
)
 
-- stolen from mission_timer.lua
function calcTime ( timeLeft )
    local calcString = ""
    local timeHours = 0
    local timeMins = 0
    local timeSecs = 0
   
    timeLeft = tonumber(timeLeft)
    timeSecs = math.mod(timeLeft, 60)
    timeMins = math.mod((timeLeft / 60), 60)
    timeHours = (timeLeft / 3600)
   
    if ( timeHours >= 1 ) then
        calcString = formatStr(tostring(timeHours)) .. ":"
    end
    calcString = calcString .. formatStr(string.format("%.0d", tostring(timeMins))) .. ":" .. formatStr(tostring(timeSecs))
   
    return calcString
end
 
function formatStr ( formatString )
    local aString = tostring(formatString)
   
    if ( #aString == 1 ) then
        aString = "0" .. aString
    end
   
    if ( #aString == 0 ) then
        aString = "00"
    end
 
    return aString
end
 
function showProgress(objectiveId, bool, progress, total, stayText)
    if (progressBar == nil) then progressBar = {} end
    if (progressBarText == nil) then progressBarText = {} end
 
    if (progressBar[objectiveId] == nil and bool == true) then
        local x, y = guiGetScreenSize()
        x = ( x / 2 ) - 100
        y = y * 0.6
        progressBar[objectiveId] = guiCreateProgressBar ( x, y, 200, 20, false )
        progressBarText[objectiveId] = guiCreateLabel ( x, y - 30, 100, 25, stayText, false )
        guiSetSize ( progressBarText[objectiveId], guiLabelGetTextExtent ( progressBarText[objectiveId] ), guiLabelGetFontHeight ( progressBarText[objectiveId] ), false )
        guiLabelSetColor ( progressBarText[objectiveId], 255, 255, 255, 255 )
    end
   
    if (progressBar[objectiveId] == nil) then return end
    guiSetVisible(progressBar[objectiveId],bool)
    guiSetVisible(progressBarText[objectiveId],bool)
    if (progress ~= nil and total ~= nil) then
        local p = math.ceil(progress / total * 100)
        guiProgressBarSetProgress(progressBar[objectiveId],p)
        guiSetText ( progressBarText[objectiveId], ("%s %d%%"):format(stayText, p) )
        guiSetSize ( progressBarText[objectiveId], guiLabelGetTextExtent ( progressBarText[objectiveId] ), guiLabelGetFontHeight ( progressBarText[objectiveId] ), false )
    end
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...