Jump to content

Fixing the Stuck Times Up in Race. need Help.


DazzaJay

Recommended Posts

me and Winky have been working on this for a while for PS Race Server, but we havnt got it working.

iil show you what we have.... this is another LUA that will be added into our Race Resource.

this may not appear correctly because of the Stupid Swear Filter. but you will still be able to get the idea.

function clearStuckShit() 
    local players = getElementsByType("player") 
        for k,v in ipairs(players) do 
        destroyMessage(v) 
    end 
end 
  
addEventHandler("onGamemodeMapStart", getRootElement(), clearStuckShit) 

Now, we are expecting that to trigger an already coded function built into race....

we do get an error, which points to the First line of the function destroyMessage.

(attempt to index field '?' (a nil value))

i know the problem is with the Above script, as that function is used on a Timer to remove "Times Up" by the gamemode, but that timer often fails to do its job if the map changes before it can remove the "Times Up" which is why ive been working on this script, so if it fails to remove, the script will force it on map Change.

but as i listed above, it dosent work

any ideas?

---------------------------------------------------------------------------------------------

This is the section in util_server.lua

(The following is just for reference so people can check to see why the script isnt triggering it properly)

g_Messages = {}     -- { player =  { display = display, textitem = textitem, timer = timer } } 
function showMessage(text, r, g, b, player) 
    if not player then 
        player = g_Root 
    end 
     
    if g_Messages[player] then 
        killTimer(g_Messages[player].timer) 
    else 
        g_Messages[player] = { 
            display = textCreateDisplay(), 
            textitem = textCreateTextItem('', 0.5, 0.5, 'medium', 255, 0, 0, 255, 2, 'center', 'center') 
        } 
    end 
     
    local display = g_Messages[player].display 
    local textitem = g_Messages[player].textitem 
    textDisplayAddText(display, textitem) 
    textItemSetText(textitem, text) 
    textItemSetColor(textitem, r or 255, g or 0, b or 0, 255) 
    if player == g_Root then 
        for i,player in ipairs(getElementsByType('player')) do 
            textDisplayAddObserver(display, player) 
        end 
    else 
        textDisplayAddObserver(display, player) 
    end 
    g_Messages[player].timer = setTimer(destroyMessage, 8000, 1, player) 
end 
  
function destroyMessage(player) 
    textDestroyDisplay(g_Messages[player].display) 
    textDestroyTextItem(g_Messages[player].textitem) 
    g_Messages[player] = nil 
end 

As you can see, our first script is tryig to trigger the destroyMessage function near the bottom.

This is the original function in race_server.lua that triggers the "Times Up" message.

function raceTimeout() 
    for i,player in pairs(g_Players) do 
        if not isPlayerFinished(player) then 
            showMessage('Time\'s up!') 
        end 
    end 
    clientCall(g_Root, 'raceTimeout') 
    g_RaceEndTimer = nil 
    setTimer(votemanager.voteMap, 10000, 1, getThisResource()) 
end 

  • Like 1
Link to comment

Hi,

I fear that this is an MTA bug rather than a race bug. As you see, destroyMessage sets g_Messages[player] to nil after having destroyed both the text item and the text display. So, if g_Messages[player] is nil as is the case for you, there are two possibilities: 1) the player has never had a message since the race resource started, 2) he has seen one or more, and destroyMessage was called afterwards. You will also notice that showMessage reuses the text display/item if it is called while a message is already being displayed, instead of creating a new one and leaving the old one on screen.

Link to comment

If the timer never triggers, it was either killed by script, or the resource was restarted (which I believe is the case with map changes in DP2). The first case can be ruled out as the only location where killTimer(messagetimer) is called is in showMessage. And if a resource stops or restarts, all the things it created (including text displays/items) are (or should be) destroyed by MTA.

Link to comment
  • 2 weeks later...

I fixed it for DazzaJay.

To clarify, the gamemode resource wouldn't be restarting as it's only a mapchange. While that would destroy the message, that's not the bug.

The problem was caused here, in race_server.lua:

function unloadAll() 
    clientCall(g_Root, 'unloadAll') 
    if g_RaceEndTimer then 
        killTimer(g_RaceEndTimer) 
        g_RaceEndTimer = nil 
    end 
    if g_RankTimer then 
        killTimer(g_RankTimer) 
        g_RankTimer = nil 
    end 
    local timers = getTimers() 
    for timerKey, timerValue in ipairs(timers) do 
      killTimer ( timerValue ) 
    end 
    Countdown.destroyAll() 
... 

Note the getTimers() that then all get Killed.

I fixed by these additions in race_server.lua:

function unloadAll() 
...{same code as above} 
    for i,player in pairs(g_Players) do 
        setPlayerFinished(player, false) 
        destroyMessage(player)  --To destroy any stuck "You have won/You have come xth place" msgs. 
    end 
    destroyMessage(g_Root) --As the Time's Up msg is not stored per-player, but as part of the root element. 
... 

and this edit to util_server.lua:

function destroyMessage(player) 
    if g_Messages[player] then  --New check as a message may not actually exist. 
        textDestroyDisplay(g_Messages[player].display) 
        textDestroyTextItem(g_Messages[player].textitem) 
        g_Messages[player] = nil 
    end 
end 

This put an end to the bug nicely.

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...