Jump to content

pobrema respawn race


Recommended Posts

bom eu editei o base.lua da race para tirar respawns dos maps deu certo mais a death list nao pega porque as configuraçao do mas é "none" tipo o respawn eu tirei mais como ponho para a death list aparecer nesses maps que esta "none" a configuraçao

RaceMode = {} 
RaceMode.__index = RaceMode
 
RaceMode.registeredModes = {}
RaceMode.instances = {}
 
function RaceMode:register(name)
    RaceMode.registeredModes[name] = self
    self.name = name
end
 
function RaceMode.getApplicableMode()
    for modeName,mode in pairs(RaceMode.registeredModes) do
        if mode:isApplicable() then
            return mode
        end
    end
    return RaceMode
end
 
function RaceMode:getName()
    return self.name
end
 
function RaceMode.getCheckpoints()
    return g_Checkpoints
end
 
function RaceMode.getCheckpoint(i)
    return g_Checkpoints[i]
end
 
function RaceMode.getNumberOfCheckpoints()
    return #g_Checkpoints
end
 
function RaceMode.checkpointsExist()
    return #g_Checkpoints > 0
end
 
function RaceMode.getSpawnpoints()
    return g_Spawnpoints
end
 
function RaceMode.getNumberOfSpawnpoints()
    return #g_Spawnpoints
end
 
function RaceMode.getSpawnpoint(i)
    return g_Spawnpoints[i]
end
 
function RaceMode.getMapOption(option)
    return g_MapOptions[option]
end
 
function RaceMode.isMapRespawn()
    return RaceMode.getMapOption('respawn') == 'timelimit'
end
 
function RaceMode.getPlayers()
    return g_Players
end
 
function RaceMode.setPlayerIsFinished(player)
    setPlayerFinished(player, true)
end
 
function RaceMode.isPlayerFinished(player)
    return isPlayerFinished(player)
end
 
function RaceMode.getPlayerVehicle(player)
    return g_Vehicles[player]
end
 
function RaceMode:setTimeLeft(timeLeft)
    if g_MapOptions.duration - self:getTimePassed() > timeLeft then
        g_MapOptions.duration = self:getTimePassed() + timeLeft
        TimerManager.destroyTimersFor("raceend")
        TimerManager.createTimerFor("map","raceend"):setTimer(raceTimeout, timeLeft, 1)
        clientCall(g_Root, 'setTimeLeft', timeLeft)
    end
end
 
function RaceMode.endMap()
    if stateAllowsPostFinish() then
        gotoState('PostFinish')
      local text = g_GameOptions.randommaps and 'Next map starts in:' or 'Next map starts in:'
        Countdown.create(5, RaceMode.startNextMapSelect, text, 255, 255, 255, 0.9, 2 ):start()
        triggerEvent('onPostFinish', g_Root)
    end
end
 
function RaceMode.startNextMapSelect()
    if stateAllowsNextMapSelect() then
        gotoState('NextMapSelect')
        Countdown.destroyAll()
        destroyAllMessages()
        if g_GameOptions.randommaps then
            startRandomMap()
        else
            startNextMapVote()
        end
    end
end
 
-- Default functions
 
function RaceMode.isApplicable()
    return false
end
 
function RaceMode:create()
    local id = #RaceMode.instances + 1
    RaceMode.instances[id] = setmetatable(
        {
            id = id,
            checkpointBackups = {},  -- { player = { goingback = true/false, i = { vehicle = id, position = {x, y, z}, rotation = {x, y, z}, velocity = {x, y, z} } } }
            activePlayerList = {},
            finishedPlayerList = {},
        },
        self
    )
    return RaceMode.instances[id]
end
 
function RaceMode:launch()
    self.startTick = getTickCount()
    for _,spawnpoint in ipairs(RaceMode.getSpawnpoints()) do
        spawnpoint.used = nil
    end
    -- Put all relevant players into the active player list
    for _,player in ipairs(getElementsByType("player")) do
        if not isPlayerFinished(player) then
            addActivePlayer( player )
        end
    end
end
 
function RaceMode:getTimePassed()
    if self.startTick then
        return getTickCount() - self.startTick
    else
        return 0
    end
end
 
function RaceMode:getTimeRemaining()
    if self.startTick then
        return self.startTick + g_MapOptions.duration - getTickCount()
    else
        return 0
    end
end
 
function RaceMode:isRanked()
    return true
end
 
function RaceMode:getPlayerRank(queryPlayer)
    local rank = 1
    local queryCheckpoint = getPlayerCurrentCheckpoint(queryPlayer)
    local checkpoint
 
    -- Figure out rank amoung the active players
    for i,player in ipairs(getActivePlayers()) do
        if player ~= queryPlayer then
            checkpoint = getPlayerCurrentCheckpoint(player)
            if RaceMode.isPlayerFinished(player) or checkpoint > queryCheckpoint then
                rank = rank + 1
            elseif checkpoint == queryCheckpoint then
                if distanceFromPlayerToCheckpoint(player, checkpoint) < distanceFromPlayerToCheckpoint(queryPlayer, checkpoint) then
                    rank = rank + 1
                end
            end
        end
    end
 
    -- Then add on the players that have finished
    rank = rank + getFinishedPlayerCount()
    return rank
end
 
-- Faster version of old updateRank
function RaceMode:updateRanks()
    -- Make a table with the active players
    local sortinfo = {}
    for i,player in ipairs(getActivePlayers()) do
        sortinfo[i] = {}
        sortinfo[i].player = player
        sortinfo[i].checkpoint = getPlayerCurrentCheckpoint(player)
        sortinfo[i].cpdist = distanceFromPlayerToCheckpoint(player, sortinfo[i].checkpoint )
    end
    -- Order by cp
    table.sort( sortinfo, function(a,b)
                        return a.checkpoint > b.checkpoint or
                               ( a.checkpoint == b.checkpoint and a.cpdist < b.cpdist )
                      end )
    -- Copy back into active players list to speed up sort next time
    for i,info in ipairs(sortinfo) do
        g_CurrentRaceMode.activePlayerList[i] = info.player
    end
    -- Update data
    local rankOffset = getFinishedPlayerCount()
    for i,info in ipairs(sortinfo) do
        setElementData(info.player, 'race rank', i + rankOffset )
        setElementData(info.player, 'checkpoint', info.checkpoint-1 .. '/' .. #g_Checkpoints )
    end
    -- Make sure cp text looks good for finished players
    for i,player in ipairs(g_Players) do
        if isPlayerFinished(player) then
            setElementData(player, 'checkpoint', #g_Checkpoints .. '/' .. #g_Checkpoints )
        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', 1 )
            setElementData(player, 'checkpoint', '0/' .. #g_Checkpoints )
        end
    end
end
 
function RaceMode:onPlayerJoin(player, spawnpoint)
    self.checkpointBackups[player] = {}
    self.checkpointBackups[player][0] = { vehicle = spawnpoint.vehicle, position = spawnpoint.position, rotation = {0, 0, spawnpoint.rotation}, velocity = {0, 0, 0}, turnvelocity = {0, 0, 0}, geardown = true }
end
 
function RaceMode:onPlayerReachCheckpoint(player, checkpointNum)
    local rank = self:getPlayerRank(player)
    local time = self:getTimePassed()
    if checkpointNum < RaceMode.getNumberOfCheckpoints() then
        -- Regular checkpoint
        local vehicle = RaceMode.getPlayerVehicle(player)
        self.checkpointBackups[player][checkpointNum] = { vehicle = getElementModel(vehicle), position = { getElementPosition(vehicle) }, rotation = { getVehicleRotation(vehicle) }, velocity = { getElementVelocity(vehicle) }, turnvelocity = { getVehicleTurnVelocity(vehicle) }, geardown = getVehicleLandingGearDown(vehicle) or false }     
       
        self.checkpointBackups[player].goingback = true
        TimerManager.destroyTimersFor("checkpointBackup",player)
        TimerManager.createTimerFor("map","checkpointBackup",player):setTimer(lastCheckpointWasSafe, 5000, 1, self.id, player)
    else
        -- Finish reached
        rank = getFinishedPlayerCount() + 1
        RaceMode.setPlayerIsFinished(player)
        finishActivePlayer( player )
        setPlayerStatus( player, nil, "finished" )
        if rank == 1 then
            gotoState('SomeoneWon')
            showMessage('You have won the race!', 0, 255, 0, player)
            if self.rankingBoard then   -- Remove lingering labels
                self.rankingBoard:destroy()
           
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...