Skip to content

Commit 68b10f2

Browse files
authored
Fix issue with killmessages not working in race (#595)
1 parent 0fb90c0 commit 68b10f2

File tree

2 files changed

+51
-6
lines changed
  • [gamemodes]/[race]/race/modes
  • [gameplay]/killmessages/scripts/client

2 files changed

+51
-6
lines changed

[gamemodes]/[race]/race/modes/base.lua

+43-6
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,37 @@ function RaceMode:onPlayerReachCheckpoint(player, checkpointNum)
244244
RaceMode.setPlayerIsFinished(player)
245245
finishActivePlayer( player )
246246
setPlayerStatus( player, nil, "finished" )
247+
248+
local name = getPlayerName(player)
249+
local message
250+
local killmessage
251+
252+
if rank == 1 then
253+
message = "You have won the race!"
254+
killmessage = string.format("%s won the race!", name)
255+
else
256+
local suffix
257+
local last = rank % 10
258+
local exception = rank % 100 >= 11 and rank % 100 <= 13
259+
260+
if exception then
261+
suffix = "th"
262+
else
263+
if last == 1 then
264+
suffix = "st"
265+
elseif last == 2 then
266+
suffix = "nd"
267+
elseif last == 3 then
268+
suffix = "rd"
269+
else
270+
suffix = "th"
271+
end
272+
end
273+
274+
message = string.format("You finished %s %s.", rank, suffix)
275+
killmessage = string.format("%s finished %s %s.", rank, suffix)
276+
end
277+
247278
if rank == 1 then
248279
gotoState('SomeoneWon')
249280
showMessage('You have won the race!', 0, 255, 0, player)
@@ -255,17 +286,23 @@ function RaceMode:onPlayerReachCheckpoint(player, checkpointNum)
255286
self:setTimeLeft( g_GameOptions.timeafterfirstfinish )
256287
end
257288
else
258-
showMessage('You finished ' .. rank .. ( (rank < 10 or rank > 20) and ({ [1] = 'st', [2] = 'nd', [3] = 'rd' })[rank % 10] or 'th' ) .. '!', 0, 255, 0, player)
289+
showMessage(message, 0, 255, 0, player)
259290
end
260-
--Output a killmessage
291+
261292
exports.killmessages:outputMessage(
262293
{
263-
{"image",path="img/killmessage.png",resource=getThisResource(),width=24},
264-
getPlayerName(player),
294+
victim = {
295+
text = killmessage,
296+
color = {255, 255, 255}
297+
},
298+
icon = {
299+
path = ":race/img/killmessage.png",
300+
width = 24
301+
},
265302
},
266-
root,
267-
255,0,0
303+
root
268304
)
305+
269306
self.rankingBoard:add(player, time)
270307
if getActivePlayerCount() > 0 then
271308
TimerManager.createTimerFor("map",player):setTimer(clientCall, 5000, 1, player, 'Spectate.start', 'auto')

[gameplay]/killmessages/scripts/client/c.ui.lua

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function outputMessage(new)
1313

1414
new.initTick = getTickCount()
1515

16+
if new.icon.path and fileExists(new.icon.path) then
17+
new.icon.texture = dxCreateTexture(new.icon.path)
18+
end
19+
1620
table.insert(messages, new)
1721

1822
local displayLines = tonumber(getSetting('displayLines')) or 5
@@ -103,6 +107,10 @@ function renderMessages()
103107

104108
y = y - lineHeight - padding
105109
else
110+
if v.icon.path and v.icon.texture and isElement(v.icon.texture) then
111+
destroyElement(v.icon.texture)
112+
end
113+
106114
table.remove(messages, k)
107115

108116
if (#messages == 0) then

0 commit comments

Comments
 (0)