Skip to content

Commit c733b69

Browse files
authored
Fallout fix and refactor (#503)
Fallout fixes and refactor - Fixes various issues (memory leak [timers], bugged camera) - Code refactor and splitting the code in a bit more files - Security update - Small player skin update (just to keep it more lively) - Peaceful mode (disables melee attacks, by default enabled) - Admin settings
1 parent ff80005 commit c733b69

File tree

8 files changed

+431
-306
lines changed

8 files changed

+431
-306
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
local activeBoards = {}
2+
3+
function createBoards()
4+
local rows, columns = config.boardRows, config.boardColumns
5+
--Create boards. Platform #1 is at SW Corner
6+
for i = 1, rows do --Nested to create rows and columns
7+
for j = 1, columns do
8+
activeBoards[#activeBoards + 1] = createObject(1697, 1540.122926 + 4.466064 * j, -1317.568237 + 5.362793 * i, 603.105469, math.deg(0.555), 0, 0)
9+
end
10+
end
11+
setElementDoubleSided(resourceRoot, true)
12+
end
13+
14+
--- Returns active board elements
15+
function getActiveBoardElements()
16+
return activeBoards
17+
end
18+
19+
--- Returns active board element count
20+
function getActiveBoardElementCount()
21+
return #activeBoards
22+
end
23+
24+
function disableBoard(board)
25+
for i = 1, #activeBoards do
26+
if activeBoards[i] == board then
27+
table.remove(activeBoards, i)
28+
break
29+
end
30+
end
31+
end
32+
33+
--- Returns a random board from the activeBoards table
34+
function getRandomActiveBoard ()
35+
return activeBoards[math.random(#activeBoards)]
36+
end
37+
38+
--- Resets the activeBoards table
39+
function resetActiveBoards ()
40+
for i = #activeBoards, 1, -1 do
41+
table.remove(activeBoards, i)
42+
end
43+
end
44+
45+
--- Destroy all board elements
46+
function destroyBoards ()
47+
for k, v in ipairs(getElementsByType("object", resourceRoot)) do
48+
destroyElement(v)
49+
end
50+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
config = {
2+
boardRows = get("boardRows"), --Default:10 Number of rows to put on the board
3+
boardColumns = get("boardColumns"), --Default:8 Number of columns to put on the board
4+
winningBoards = get("winningBoards"), --Default:3 Number of boards that will not fall. Must be higher than board count!
5+
scoreLimit = get("scoreLimit"), --Default:10 wins required to win the fallout tournament default is 10
6+
callSpeedA = get("callSpeedA"), --Default:250 Call speed when 30 or more boards exist
7+
callSpeedB = get("callSpeedB"), --Default:500 Call speed when 29 to 15 boards exist
8+
callSpeedC = get("callSpeedC"), --Default:750 Call speed when 14 or less boards exist
9+
peacefulMode = get("peacefulMode") == "true" -- Default:true Disable player melee attack
10+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
textDisplays = {}
2+
textItems = {}
3+
4+
textDisplays.countDownDisplay = textCreateDisplay()
5+
textItems.countDownText = textCreateTextItem("", 0.5, 0.3, "high", 255, 127, 0, 255, 2, "center")
6+
textDisplayAddText(textDisplays.countDownDisplay, textItems.countDownText)
7+
8+
textDisplays.suicideDisplay = textCreateDisplay()
9+
local suicideText = textCreateTextItem("You lose! Press space for a quick death.", 0.5, 0.5, "low", 255, 127, 0, 255, 2, "center")
10+
textDisplayAddText(textDisplays.suicideDisplay, suicideText)
11+
12+
textDisplays.winnersDisplay = textCreateDisplay()
13+
textItems.winnersText = textCreateTextItem("Winners:", 0.5, 0.35, "low", 255, 127, 0, 255, 2, "center", "center")
14+
textDisplayAddText(textDisplays.winnersDisplay, textItems.winnersText)
15+
16+
textDisplays.spectatorCamDisplay = textCreateDisplay()
17+
textItems.specCamText = textCreateTextItem("Use your player movement keys to move the spectator camera.\nUse your sprint key to speed the camera up.", 0.5, 0.22, "low", 255, 127, 0, 255, 1.3, "center")
18+
textDisplayAddText(textDisplays.spectatorCamDisplay, textItems.specCamText)
19+
20+
textDisplays.podiumDisplay = textCreateDisplay()
21+
22+
textItems.firstText = textCreateTextItem("1st:", 0.45, 0.08, "high", 255, 127, 0, 255, 1.5)
23+
textItems.secondText = textCreateTextItem("2nd:", 0.45, 0.12, "high", 255, 127, 0, 255, 1.5)
24+
textItems.thirdText = textCreateTextItem("3rd:", 0.45, 0.16, "high", 255, 127, 0, 255, 1.5)
25+
26+
-- Tournament text
27+
textDisplayAddText(textDisplays.podiumDisplay, textCreateTextItem("Tournament Leaders", 0.45, 0.04, "high", 255, 127, 0, 255, 1.5))
28+
29+
textDisplayAddText(textDisplays.podiumDisplay, textItems.firstText)
30+
textDisplayAddText(textDisplays.podiumDisplay, textItems.secondText)
31+
textDisplayAddText(textDisplays.podiumDisplay, textItems.thirdText)
Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,34 @@
11
fadeCamera(true)
2-
gameOver = false
2+
local shakeState = false
33
local shakingPieces = {}
44

5-
function initGame()
6-
triggerServerEvent("serverClientLoad", root)
7-
end
8-
addEventHandler("onClientResourceStart", resourceRoot, initGame, false)
9-
105
function shakeOnRender()
11-
if gameOver == false then
12-
local currentTick = getTickCount()
13-
for object, originalTick in pairs(shakingPieces) do
14-
local tickDifference = currentTick - originalTick
15-
if tickDifference > 2400 then
16-
shakingPieces[object] = nil
17-
else
18-
--since newx/newy increases by 1 every 125ms, we can use this ratio to calculate a more accurate time
19-
local newx = tickDifference / 125 * 1
20-
local newy = tickDifference / 125 * 1
21-
if isElement(object) then
22-
setElementRotation(object, math.deg(0.555), 3 * math.cos(newy + 1), 3 * math.sin(newx + 1))
23-
end
24-
end
25-
end
26-
end
27-
end
28-
addEventHandler("onClientRender", root, shakeOnRender)
29-
30-
function ShakePieces(fallingPiece)
31-
--we store the time when the piece was told to shake under a table, so multiple objects can be stored
32-
shakingPieces[fallingPiece] = getTickCount()
6+
local currentTick = getTickCount()
7+
for object, originalTick in pairs(shakingPieces) do
8+
local tickDifference = currentTick - originalTick
9+
if tickDifference > 2400 or not isElement(object) then
10+
shakingPieces[object] = nil
11+
else
12+
--since newx/newy increases by 1 every 125ms, we can use this ratio to calculate a more accurate time
13+
local newx = tickDifference / 125 * 1
14+
local newy = tickDifference / 125 * 1
15+
setElementRotation(object, math.deg(0.555), 3 * math.cos(newy + 1), 3 * math.sin(newx + 1))
16+
end
17+
end
18+
if not next(shakingPieces) and shakeState then
19+
removeEventHandler("onClientRender", root, shakeOnRender)
20+
shakeState = false
21+
end
3322
end
34-
addEvent("clientShakePieces", true)
35-
addEventHandler("clientShakePieces", root, ShakePieces)
3623

37-
function DetectionOff(fallingPiece)
38-
checkStatusTimer = nil
39-
gameOver = true
40-
end
41-
addEvent("lossDetectionOff", true)
42-
addEventHandler("lossDetectionOff", root, DetectionOff)
43-
44-
function checkStatusB()
45-
local x, y, z = getElementPosition(localPlayer)
46-
if z < 595 and (checkStatusTimer) then
47-
triggerServerEvent("serverReportLoss", localPlayer)
48-
playSoundFrontEnd(4)
49-
killTimer(checkStatusTimer)
50-
checkStatusTimer = nil
51-
end
52-
end
5324

54-
function checkStatus()
55-
gameOver = false
56-
checkStatusTimer = setTimer(checkStatusB, 500, 0)
57-
end
58-
addEvent("clientCheckStatus", true)
59-
addEventHandler("clientCheckStatus", root, checkStatus)
25+
addEvent("onClientShakePieces", true)
26+
addEventHandler("onClientShakePieces", resourceRoot,
27+
function ()
28+
-- we store the time when the piece was told to shake under a table, so multiple objects can be stored
29+
shakingPieces[source] = getTickCount()
30+
if not shakeState then
31+
addEventHandler("onClientRender", root, shakeOnRender)
32+
shakeState = true
33+
end
34+
end, true)

0 commit comments

Comments
 (0)