Nahar Posted March 3, 2014 Share Posted March 3, 2014 Hey guys, Here is an auto-b system, sometime it work and sometime not, I don't where is the problem. DestructionDerby = setmetatable({}, RaceMode) DestructionDerby.__index = DestructionDerby DestructionDerby:register('Destruction derby') winprice = nil winplayer = nil dead = 0 function DestructionDerby:isApplicable() return not RaceMode.checkpointsExist() and RaceMode.getMapOption('respawn') == 'none' end function DestructionDerby:getPlayerRank(player) return #getActivePlayers() end -- Copy of old updateRank function DestructionDerby:updateRanks() for i,player in ipairs(g_Players) do if not isPlayerFinished(player) then local rank = self:getPlayerRank(player) if not rank or rank > 0 then setElementData(player, 'race rank', rank) end end end -- Make text look good at the start if not self.running then for i,player in ipairs(g_Players) do setElementData(player, 'race rank', '' ) setElementData(player, 'checkpoint', '' ) end end end function DestructionDerby:onPlayerWasted(player) if isActivePlayer(player) then self:handleFinishActivePlayer(player) if getActivePlayerCount() <= 1 then local activePlayers = getActivePlayers() if #activePlayers == 1 then if getElementData(activePlayers[1], "isDonator") ~= true or string.find(g_MapName, "[sHOOTER]", 1, true) or string.find(g_MapName, "[FUN]", 1, true) or string.find(g_MapName, "[DD]", 1, true) or getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then RaceMode.endMap() else TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') end else RaceMode.endMap() end else TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') end local pvpElements = getElementsByType ( "pvpElement" ) for theKey,pvpElement in ipairs(pvpElements) do if (getElementData(pvpElement, "player1") == player or getElementData(pvpElement, "player2") == player) and getElementData(pvpElement, "accepted") == true then local player1 = getElementData(pvpElement, "player1") local player2 = getElementData(pvpElement, "player2") if player1 == player then addPlayerArchivement( player2, 44 ) outputChatBox("#256484:PVP: #FFFFFF"..getPlayerName(player2).." has won a PVP war against "..getPlayerName(player1).." and receives "..tostring(getElementData(pvpElement, "money")).." VIP.",getRootElement(),255,0,0, true) setPlayerMoney(player2, getPlayerMoney(player2)+getElementData(pvpElement, "money")*2) elseif player2 == player then addPlayerArchivement( player1, 44 ) outputChatBox("#256484:PVP: #FFFFFF"..getPlayerName(player1).." has won a PVP war against "..getPlayerName(player2).." and receives "..tostring(getElementData(pvpElement, "money")).." VIP.",getRootElement(),255,0,0, true) setPlayerMoney(player1, getPlayerMoney(player1)+getElementData(pvpElement, "money")*2) end destroyElement(pvpElement) break end end if getActivePlayerCount() ~= 0 then if isLoggedIn(player) == true and getElementData(player, "AFK") == false then local onlinePlayers = 0 local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do onlinePlayers = onlinePlayers + 1 end local endPoints = math.floor(onlinePlayers*(8.5+(onlinePlayers/100))/(getActivePlayerCount()+1)) local endMoney = math.floor(onlinePlayers*(65+(onlinePlayers/100))/(getActivePlayerCount()+1)) if g_eventInProgress == 1 or g_eventInProgress == 2 or g_eventInProgress == 3 then endPoints = endPoints*2 end outputChatBox("#00aa46:Points: #ffffff You received "..tostring(endPoints).." points and "..tostring(endMoney).." VIP for playing this map.", player, 255, 255, 255, true) setElementData(player, "Points", getElementData(player, "Points") + endPoints) setElementData(player, "Money", getElementData(player, "Money") + endMoney) if isTimer ( WinTimer ) then killTimer ( WinTimer ) end end end end RaceMode.setPlayerIsFinished(player) showBlipsAttachedTo(player, false) end function DestructionDerby:onPlayerQuit(player) if isActivePlayer(player) then self:handleFinishActivePlayer(player) if getActivePlayerCount() <= 1 then local activePlayers = getActivePlayers() if #activePlayers == 1 then if getElementData(activePlayers[1], "isDonator") ~= true then RaceMode.endMap() end else RaceMode.endMap() end end end end function DestructionDerby:handleFinishActivePlayer(player) -- Update ranking board for player being removed if not self.rankingBoard then self.rankingBoard = RankingBoard:create() self.rankingBoard:setDirection( 'up', getActivePlayerCount() ) end local timePassed = self:getTimePassed() self.rankingBoard:add(player, timePassed) -- Do remove finishActivePlayer(player) -- Update ranking board if one player left local activePlayers = getActivePlayers() if #activePlayers == 1 then givePlayerBetWinning (activePlayers[1]) self.rankingBoard:add(activePlayers[1], timePassed) setElementData(activePlayers[1], "winningCounter", getElementData(activePlayers[1], "winningCounter") + 1) if getElementData(activePlayers[1], "winningCounter") == 5 then addPlayerArchivement(activePlayers[1], 12) elseif getElementData(activePlayers[1], "winningCounter") == 7 then addPlayerArchivement(activePlayers[1], 13) elseif getElementData(activePlayers[1], "winningCounter") == 11 then addPlayerArchivement(activePlayers[1], 14) end if tonumber(getElementData(activePlayers[1], "winningCounter")) >= tonumber(getElementData(activePlayers[1], "WinningStreak")) then setElementData(activePlayers[1], "WinningStreak", getElementData(activePlayers[1], "winningCounter")) end if isTimer ( WinTimer ) then killTimer ( WinTimer ) end local onlinePlayers = 0 local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do onlinePlayers = onlinePlayers + 1 if activePlayers[1] ~= thePlayer then if isLoggedIn(thePlayer) == true then setElementData(thePlayer, "winningCounter", 0) end end end local endPoints = math.floor(onlinePlayers*(8.5+(onlinePlayers/100))) local endMoney = math.floor(onlinePlayers*(65+(onlinePlayers/100))) if g_eventInProgress == 1 or g_eventInProgress == 2 or g_eventInProgress == 3 then endPoints = endPoints*2 end if isLoggedIn(activePlayers[1]) == true and getElementData(activePlayers[1], "AFK") == false then outputChatBox("#00aa46:Points: #ffffff You received "..tostring(endPoints).." points and "..tostring(endMoney).." VIP for winning this map.", activePlayers[1], 255, 255, 255, true) setElementData(activePlayers[1], "WonMaps", getElementData(activePlayers[1], "WonMaps")+1) --triggerClientEvent ( activePlayers[1], "onRefreshGui" ) setElementData(activePlayers[1], "Points", getElementData(activePlayers[1], "Points")+ endPoints) setElementData(activePlayers[1], "Money", getElementData(activePlayers[1], "Money")+ endMoney) if onlinePlayers >= 10 then addPlayerArchivement( activePlayers[1], 8 ) end if string.find(g_MapInfo.name, "[DM]", 1, true) then setElementData(activePlayers[1], "DMWon", getElementData(activePlayers[1], "DMWon")+1) end if getElementData(activePlayers[1], "DMWon") == 100 then addPlayerArchivement( activePlayers[1], 19 ) end if getElementData(activePlayers[1], "DMWon") == 1000 then addPlayerArchivement( activePlayers[1], 21 ) end if string.find(g_MapInfo.name, "[DD]", 1, true) then setElementData(activePlayers[1], "DDWon", getElementData(activePlayers[1], "DDWon")+1) end if getElementData(activePlayers[1], "DDWon") == 100 then addPlayerArchivement( activePlayers[1], 20 ) end if getElementData(activePlayers[1], "DDWon") == 1000 then addPlayerArchivement( activePlayers[1], 22 ) end end local ran_win_mesage = { [1] = "He won "..tostring(getElementData(activePlayers[1], "DMWon")).." DM maps", [2] = "He won "..tostring(getElementData(activePlayers[1], "DDWon")).." DD maps", [3] = "He drove "..tostring(math.floor(getElementData(activePlayers[1], "KM"))).." KM in this server!", [4] = "He did "..tostring(getElementData(activePlayers[1], "TopTimes")).." toptimes!", [5] = "He is Level "..tostring(getElementData(activePlayers[1], "Rank")).."!", [6] = "He got "..tostring(getElementData(activePlayers[1], "Money")).." Vero", [7] = "He played "..tostring(getElementData(activePlayers[1], "PlayedMaps")).." maps!", [8] = "He got "..tostring(getElementData(activePlayers[1], "Points")).." points!", [9] = "His winning streak is x"..tostring(getElementData(activePlayers[1], "winningCounter")).."!", [10] = "He is already for "..tostring(math.floor(getElementData(activePlayers[1], "TimeOnServer")/60)).." minutes on the Server!" } local hasCustomText = false if getElementData(activePlayers[1], "isDonator") == true then if getElementData(activePlayers[1], "useWinsound") ~= 0 then local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do if getElementData(thePlayer, "toggleWinsounds") == 1 then callClientFunction(thePlayer, "playSound", "audio/winsounds/"..tostring(getElementData(activePlayers[1], "useWinsound"))..".mp3") end end end if getElementData(activePlayers[1], "customWintext") ~= "none" then showWinMessage("#FFFFFF"..tostring(getElementData(activePlayers[1], "customWintext")), "#00aa46"..tostring(ran_win_mesage[math.random(1,10)]), 0, 170, 77) hasCustomText = true end end if hasCustomText == false then showWinMessage("#FFFFFF".._getPlayerName(activePlayers[1]) .. '#00aa46 has won the map!', "#FFFFFF"..tostring(ran_win_mesage[math.random(1,10)]), 0, 170, 77) end end end ------------------------------------------------------------ -- activePlayerList stuff -- function isActivePlayer( player ) return table.find( g_CurrentRaceMode.activePlayerList, player ) end function addActivePlayer( player ) table.insertUnique( g_CurrentRaceMode.activePlayerList, player ) end function removeActivePlayer( player ) table.removevalue( g_CurrentRaceMode.activePlayerList, player ) end function finishActivePlayer( player ) Link to comment
Moderators Citizen Posted March 3, 2014 Moderators Share Posted March 3, 2014 Hey guys, Here is an auto-b system, sometime it work and sometime not, I don't where is the problem. What doest "auto-b" means ? what should it do and what are the errors using /debugscript 3 (need to be logged as admin) ? We just can't help you if you aren't giving us all the informations we could need. Link to comment
novo Posted March 3, 2014 Share Posted March 3, 2014 He wants that when a player wins, nextmap doesn't start automatically until this player dies or reaches hunter. Link to comment
Nahar Posted March 3, 2014 Author Share Posted March 3, 2014 He wants that when a player wins, nextmap doesn't start automatically until this player dies or reaches hunter. Yes, but it don't work and it don't show any error on debugscript. Link to comment
Thorxx Posted March 3, 2014 Share Posted March 3, 2014 Try this mode=0 DestructionDerby = setmetatable({}, RaceMode) DestructionDerby.__index = DestructionDerby DestructionDerby:register('Destruction derby') winprice = nil winplayer = nil dead = 0 function DestructionDerby:isApplicable() return not RaceMode.checkpointsExist() and RaceMode.getMapOption('respawn') == 'none' end function DestructionDerby:getPlayerRank(player) return #getActivePlayers() end -- Copy of old updateRank function DestructionDerby:updateRanks() for i,player in ipairs(g_Players) do if not isPlayerFinished(player) then local rank = self:getPlayerRank(player) if not rank or rank > 0 then setElementData(player, 'race rank', rank) end end end -- Make text look good at the start if not self.running then for i,player in ipairs(g_Players) do setElementData(player, 'race rank', '' ) setElementData(player, 'checkpoint', '' ) end end end function DestructionDerby:onPlayerWasted(player) if isActivePlayer(player) then self:handleFinishActivePlayer(player) if getActivePlayerCount() <= mode then local activePlayers = getActivePlayers() if #activePlayers == 1 then if getElementData(activePlayers[1], "isDonator") ~= true or string.find(g_MapName, "[sHOOTER]", 1, true) or string.find(g_MapName, "[FUN]", 1, true) or string.find(g_MapName, "[DD]", 1, true) or getElementModel(getPedOccupiedVehicle(activePlayers[1])) == 425 then RaceMode.endMap() else TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') end else RaceMode.endMap() end else TimerManager.createTimerFor("map",player):setTimer(clientCall, 2000, 1, player, 'Spectate.start', 'auto') end local pvpElements = getElementsByType ( "pvpElement" ) for theKey,pvpElement in ipairs(pvpElements) do if (getElementData(pvpElement, "player1") == player or getElementData(pvpElement, "player2") == player) and getElementData(pvpElement, "accepted") == true then local player1 = getElementData(pvpElement, "player1") local player2 = getElementData(pvpElement, "player2") if player1 == player then addPlayerArchivement( player2, 44 ) outputChatBox("#256484:PVP: #FFFFFF"..getPlayerName(player2).." has won a PVP war against "..getPlayerName(player1).." and receives "..tostring(getElementData(pvpElement, "money")).." VIP.",getRootElement(),255,0,0, true) setPlayerMoney(player2, getPlayerMoney(player2)+getElementData(pvpElement, "money")*2) elseif player2 == player then addPlayerArchivement( player1, 44 ) outputChatBox("#256484:PVP: #FFFFFF"..getPlayerName(player1).." has won a PVP war against "..getPlayerName(player2).." and receives "..tostring(getElementData(pvpElement, "money")).." VIP.",getRootElement(),255,0,0, true) setPlayerMoney(player1, getPlayerMoney(player1)+getElementData(pvpElement, "money")*2) end destroyElement(pvpElement) break end end if getActivePlayerCount() ~= 0 then if isLoggedIn(player) == true and getElementData(player, "AFK") == false then local onlinePlayers = 0 local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do onlinePlayers = onlinePlayers + 1 end local endPoints = math.floor(onlinePlayers*(8.5+(onlinePlayers/100))/(getActivePlayerCount()+1)) local endMoney = math.floor(onlinePlayers*(65+(onlinePlayers/100))/(getActivePlayerCount()+1)) if g_eventInProgress == 1 or g_eventInProgress == 2 or g_eventInProgress == 3 then endPoints = endPoints*2 end outputChatBox("#00aa46:Points: #ffffff You received "..tostring(endPoints).." points and "..tostring(endMoney).." VIP for playing this map.", player, 255, 255, 255, true) setElementData(player, "Points", getElementData(player, "Points") + endPoints) setElementData(player, "Money", getElementData(player, "Money") + endMoney) if isTimer ( WinTimer ) then killTimer ( WinTimer ) end end end end RaceMode.setPlayerIsFinished(player) showBlipsAttachedTo(player, false) end function DestructionDerby:onPlayerQuit(player) if isActivePlayer(player) then self:handleFinishActivePlayer(player) if getActivePlayerCount() <= 1 then local activePlayers = getActivePlayers() if #activePlayers == 1 then if getElementData(activePlayers[1], "isDonator") ~= true then RaceMode.endMap() end else RaceMode.endMap() end end end end function DestructionDerby:handleFinishActivePlayer(player) -- Update ranking board for player being removed if not self.rankingBoard then self.rankingBoard = RankingBoard:create() self.rankingBoard:setDirection( 'up', getActivePlayerCount() ) end local timePassed = self:getTimePassed() self.rankingBoard:add(player, timePassed) -- Do remove finishActivePlayer(player) -- Update ranking board if one player left local activePlayers = getActivePlayers() if #activePlayers == 1 then givePlayerBetWinning (activePlayers[1]) self.rankingBoard:add(activePlayers[1], timePassed) setElementData(activePlayers[1], "winningCounter", getElementData(activePlayers[1], "winningCounter") + 1) if getElementData(activePlayers[1], "winningCounter") == 5 then addPlayerArchivement(activePlayers[1], 12) elseif getElementData(activePlayers[1], "winningCounter") == 7 then addPlayerArchivement(activePlayers[1], 13) elseif getElementData(activePlayers[1], "winningCounter") == 11 then addPlayerArchivement(activePlayers[1], 14) end if tonumber(getElementData(activePlayers[1], "winningCounter")) >= tonumber(getElementData(activePlayers[1], "WinningStreak")) then setElementData(activePlayers[1], "WinningStreak", getElementData(activePlayers[1], "winningCounter")) end if isTimer ( WinTimer ) then killTimer ( WinTimer ) end local onlinePlayers = 0 local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do onlinePlayers = onlinePlayers + 1 if activePlayers[1] ~= thePlayer then if isLoggedIn(thePlayer) == true then setElementData(thePlayer, "winningCounter", 0) end end end local endPoints = math.floor(onlinePlayers*(8.5+(onlinePlayers/100))) local endMoney = math.floor(onlinePlayers*(65+(onlinePlayers/100))) if g_eventInProgress == 1 or g_eventInProgress == 2 or g_eventInProgress == 3 then endPoints = endPoints*2 end if isLoggedIn(activePlayers[1]) == true and getElementData(activePlayers[1], "AFK") == false then outputChatBox("#00aa46:Points: #ffffff You received "..tostring(endPoints).." points and "..tostring(endMoney).." VIP for winning this map.", activePlayers[1], 255, 255, 255, true) setElementData(activePlayers[1], "WonMaps", getElementData(activePlayers[1], "WonMaps")+1) --triggerClientEvent ( activePlayers[1], "onRefreshGui" ) setElementData(activePlayers[1], "Points", getElementData(activePlayers[1], "Points")+ endPoints) setElementData(activePlayers[1], "Money", getElementData(activePlayers[1], "Money")+ endMoney) if onlinePlayers >= 10 then addPlayerArchivement( activePlayers[1], 8 ) end if string.find(g_MapInfo.name, "[DM]", 1, true) then setElementData(activePlayers[1], "DMWon", getElementData(activePlayers[1], "DMWon")+1) end if getElementData(activePlayers[1], "DMWon") == 100 then addPlayerArchivement( activePlayers[1], 19 ) end if getElementData(activePlayers[1], "DMWon") == 1000 then addPlayerArchivement( activePlayers[1], 21 ) end if string.find(g_MapInfo.name, "[DD]", 1, true) then setElementData(activePlayers[1], "DDWon", getElementData(activePlayers[1], "DDWon")+1) end if getElementData(activePlayers[1], "DDWon") == 100 then addPlayerArchivement( activePlayers[1], 20 ) end if getElementData(activePlayers[1], "DDWon") == 1000 then addPlayerArchivement( activePlayers[1], 22 ) end end local ran_win_mesage = { [1] = "He won "..tostring(getElementData(activePlayers[1], "DMWon")).." DM maps", [2] = "He won "..tostring(getElementData(activePlayers[1], "DDWon")).." DD maps", [3] = "He drove "..tostring(math.floor(getElementData(activePlayers[1], "KM"))).." KM in this server!", [4] = "He did "..tostring(getElementData(activePlayers[1], "TopTimes")).." toptimes!", [5] = "He is Level "..tostring(getElementData(activePlayers[1], "Rank")).."!", [6] = "He got "..tostring(getElementData(activePlayers[1], "Money")).." Vero", [7] = "He played "..tostring(getElementData(activePlayers[1], "PlayedMaps")).." maps!", [8] = "He got "..tostring(getElementData(activePlayers[1], "Points")).." points!", [9] = "His winning streak is x"..tostring(getElementData(activePlayers[1], "winningCounter")).."!", [10] = "He is already for "..tostring(math.floor(getElementData(activePlayers[1], "TimeOnServer")/60)).." minutes on the Server!" } local hasCustomText = false if getElementData(activePlayers[1], "isDonator") == true then if getElementData(activePlayers[1], "useWinsound") ~= 0 then local players = getElementsByType ( "player" ) for theKey,thePlayer in ipairs(players) do if getElementData(thePlayer, "toggleWinsounds") == 1 then callClientFunction(thePlayer, "playSound", "audio/winsounds/"..tostring(getElementData(activePlayers[1], "useWinsound"))..".mp3") end end end if getElementData(activePlayers[1], "customWintext") ~= "none" then showWinMessage("#FFFFFF"..tostring(getElementData(activePlayers[1], "customWintext")), "#00aa46"..tostring(ran_win_mesage[math.random(1,10)]), 0, 170, 77) hasCustomText = true end end if hasCustomText == false then showWinMessage("#FFFFFF".._getPlayerName(activePlayers[1]) .. '#00aa46 has won the map!', "#FFFFFF"..tostring(ran_win_mesage[math.random(1,10)]), 0, 170, 77) end end end ------------------------------------------------------------ -- activePlayerList stuff -- function isActivePlayer( player ) return table.find( g_CurrentRaceMode.activePlayerList, player ) end function addActivePlayer( player ) table.insertUnique( g_CurrentRaceMode.activePlayerList, player ) end function removeActivePlayer( player ) table.removevalue( g_CurrentRaceMode.activePlayerList, player ) end 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