DazzaJay Posted December 23, 2008 Share Posted December 23, 2008 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 1 Link to comment
arc_ Posted December 23, 2008 Share Posted December 23, 2008 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
DazzaJay Posted December 23, 2008 Author Share Posted December 23, 2008 From what we have been able to tell by adding in a few Debug lines, the Default timer does not go off ( g_Messages[player].timer = setTimer(destroyMessage, 8000, 1, player) ), if the map changes before it can trigger. Which is why im trying to trigger it another way. Link to comment
arc_ Posted December 23, 2008 Share Posted December 23, 2008 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
subenji99 Posted January 4, 2009 Share Posted January 4, 2009 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
arc_ Posted January 4, 2009 Share Posted January 4, 2009 Ah, I hadn't thought of that. Thanks for pointing it out subenji99, and apologies to DazzaJay for denying that the bug could be in race . I will be including the fix in the MTA 1.0 version of race. Link to comment
DazzaJay Posted January 4, 2009 Author Share Posted January 4, 2009 Ah, excelent, iil put it up when the servers are uploaded to the freshly formatted box 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