Jump to content

Race_ghost on DM


Carlossg

Recommended Posts

Now returns this error:

ERROR: Race_ghost/record_client:149:attemp to compare nil whit number

toptimes_server:

-- 
-- toptimes_server.lua
--
 
SToptimesManager = {}
SToptimesManager.__index = SToptimesManager
SToptimesManager.instances = {}
 
 
---------------------------------------------------------------------------
-- Server
-- Handle events from Race
--
-- This is the 'interface' from Race
--
---------------------------------------------------------------------------
 
addEvent('onMapStarting')
addEventHandler('onMapStarting', g_Root,
    function(mapInfo, mapOptions, gameOptions)
        if g_SToptimesManager then
            g_SToptimesManager:setModeAndMap( mapInfo.modename, mapInfo.name, gameOptions.statsKey )
        end
    end
)
 
addEvent('onPlayerPickUpRacePickup')
addEventHandler('onPlayerPickUpRacePickup', g_Root,
    function(number, sort, model)
        if sort == "vehiclechange" then
            if model == 425 then
                outputChatBox ( getPlayerName(source).. " #FF0000has got the Hunter", getRootElement(), 255, 255, 255, true )
                if g_SToptimesManager then
                    g_SToptimesManager:playerFinished( source, exports.race:getTimePassed())
                end
            end
        end
    end
)
 
addEvent('onPlayerFinish')
addEventHandler('onPlayerFinish', g_Root,
    function(rank, time)
        if g_SToptimesManager then
            g_SToptimesManager:playerFinished( source, time)
        end
    end
)
 
addEventHandler('onResourceStop', g_ResRoot,
    function()
        if g_SToptimesManager then
            g_SToptimesManager:unloadingMap()
        end
    end
)
 
addEventHandler('onPlayerQuit', g_Root,
    function()
        if g_SToptimesManager then
            g_SToptimesManager:removePlayerFromUpdateList(source)
            g_SToptimesManager:unqueueUpdate(source)
        end
    end
)
 
addEventHandler('onResourceStart', g_ResRoot,
    function()
        local raceInfo = getRaceInfo()
        if raceInfo and g_SToptimesManager then
            g_SToptimesManager:setModeAndMap( raceInfo.mapInfo.modename, raceInfo.mapInfo.name, raceInfo.gameOptions.statsKey )
        end
    end
)
 
function getRaceInfo()
    local raceResRoot = getResourceRootElement( getResourceFromName( "race" ) )
    return raceResRoot and getElementData( raceResRoot, "info" )
end
 
---------------------------------------------------------------------------
--
-- Events fired from here
--
---------------------------------------------------------------------------
 
addEvent("onPlayerToptimeImprovement")
 
---------------------------------------------------------------------------
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:create()
--
-- Create a SToptimesManager instance
--
---------------------------------------------------------------------------
function SToptimesManager:create()
    local id = #SToptimesManager.instances + 1
    SToptimesManager.instances[id] = setmetatable(
        {
            id = id,
            playersWhoWantUpdates   = {},
            updateQueue          = {},
            serviceQueueTimer       = nil,
            displayTopCount      = 12,      -- Top number of times to display
            mapTimes                = nil,      -- SMaptimes:create()
            serverRevision          = 0,        -- To prevent redundant updating to clients
        },
        self
    )
    SToptimesManager.instances[id]:postCreate()
    return SToptimesManager.instances[id]
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:destroy()
--
-- Destroy a SToptimesManager instance
--
---------------------------------------------------------------------------
function SToptimesManager:destroy()
    SToptimesManager.instances[self.id] = nil
    self.id = 0
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:postCreate()
--
--
--
---------------------------------------------------------------------------
function SToptimesManager:postCreate()
    cacheSettings()
    self.displayTopCount = g_Settings.numtimes
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:setModeAndMap()
--
-- Called when a new map has been loaded
--
---------------------------------------------------------------------------
function SToptimesManager:setModeAndMap( raceModeName, mapName, statsKey )
    outputDebug( 'TOPTIMES', 'SToptimesManager:setModeAndMap ' .. raceModeName .. '<>' .. mapName )
 
    -- Reset updatings from the previous map
    self.playersWhoWantUpdates = {}
    self.updateQueue = {}
    if self.serviceQueueTimer then
        killTimer(self.serviceQueueTimer)
    end
    self.serviceQueueTimer = nil
 
    -- Remove old map times
    if self.mapTimes then
        self.mapTimes:flush()   -- Ensure last stuff is saved
        self.mapTimes:destroy()
    end
 
    -- Get map times for this map
    self.mapTimes = SMaptimes:create( raceModeName, mapName, statsKey )
    self.mapTimes:load()
 
    -- Get the toptimes data ready to send
    self:updateTopText()
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:unloadingMap()
--
-- Called when unloading
--
---------------------------------------------------------------------------
function SToptimesManager:unloadingMap()
    if self.mapTimes then
        self.mapTimes:flush()   -- Ensure last stuff is saved
    end
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:playerFinished()
--
-- If time is good enough, insert into database
--
---------------------------------------------------------------------------
function SToptimesManager:playerFinished( player, newTime, dateRecorded )
 
    -- Check if top time recording is disabled for this player
    if getElementData ( player, "toptimes" ) == "off" then
        return
    end
 
    if not self.mapTimes then
        outputDebug( 'TOPTIMES', 'SToptimesManager:playerFinished - self.mapTimes == nil' )
        return
    end
 
    dateRecorded = dateRecorded or getRealDateTimeNowString()
 
    local oldTime   = self.mapTimes:getTimeForPlayer( player )  -- Can be false if no previous time
    local newPos    = self.mapTimes:getPositionForTime( newTime, dateRecorded )
 
    -- See if time is an improvement for this player
    if not oldTime or newTime < oldTime then
 
        local oldPos    = self.mapTimes:getIndexForPlayer( player )
        triggerEvent("onPlayerToptimeImprovement", player, newPos, newTime, oldPos, oldTime, self.displayTopCount, self.mapTimes:getValidEntryCount() )
 
        -- See if its in the top display
        if newPos <= self.displayTopCount then
            outputDebug( 'TOPTIMES', getPlayerName(player) .. ' got toptime position ' .. newPos )
        end
 
        if oldTime then
            outputDebug( 'TOPTIMES', getPlayerName(player) .. ' new personal best ' .. newTime .. ' ' .. oldTime - newTime )
        end
 
        self.mapTimes:setTimeForPlayer( player, newTime, dateRecorded )
 
        -- updateTopText if database was changed
        if newPos <= self.displayTopCount then
            self:updateTopText()
        end
    end
 
    outputDebug( 'TOPTIMES', '++ SToptimesManager:playerFinished ' .. tostring(getPlayerName(player)) .. ' time:' .. tostring(newTime) )
    triggerClientEvent( source, "onClientPlayerFinished", source)
end
 
 
---------------------------------------------------------------------------
--
-- SToptimesManager:updateTopText()
--
-- Update the toptimes client data for the current map
--
---------------------------------------------------------------------------
function SToptimesManager:updateTopText()
    if not self.mapTimes then return 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...