Wisam Posted April 17, 2014 Share Posted April 17, 2014 So i got the assault gamemode and i want to add small thing and its when the attacking team finish all the objectives a random sound will play, and if the attacking team didn't finish all the objectives another different sound is played.. 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
Bonsai Posted April 17, 2014 Share Posted April 17, 2014 So i got the assault gamemode and i want to add small thing and its when the attacking team finish all the objectives a random sound will play, and if the attacking team didn't finish all the objectives another different sound is played.. 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 ( Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now