Skip to content

Commit

Permalink
Fallout fix and refactor (#503)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
IIYAMA12 authored Jun 19, 2024
1 parent ff80005 commit c733b69
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 306 deletions.
50 changes: 50 additions & 0 deletions [gamemodes]/[fallout]/fallout/board_s.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
local activeBoards = {}

function createBoards()
local rows, columns = config.boardRows, config.boardColumns
--Create boards. Platform #1 is at SW Corner
for i = 1, rows do --Nested to create rows and columns
for j = 1, columns do
activeBoards[#activeBoards + 1] = createObject(1697, 1540.122926 + 4.466064 * j, -1317.568237 + 5.362793 * i, 603.105469, math.deg(0.555), 0, 0)
end
end
setElementDoubleSided(resourceRoot, true)
end

--- Returns active board elements
function getActiveBoardElements()
return activeBoards
end

--- Returns active board element count
function getActiveBoardElementCount()
return #activeBoards
end

function disableBoard(board)
for i = 1, #activeBoards do
if activeBoards[i] == board then
table.remove(activeBoards, i)
break
end
end
end

--- Returns a random board from the activeBoards table
function getRandomActiveBoard ()
return activeBoards[math.random(#activeBoards)]
end

--- Resets the activeBoards table
function resetActiveBoards ()
for i = #activeBoards, 1, -1 do
table.remove(activeBoards, i)
end
end

--- Destroy all board elements
function destroyBoards ()
for k, v in ipairs(getElementsByType("object", resourceRoot)) do
destroyElement(v)
end
end
10 changes: 10 additions & 0 deletions [gamemodes]/[fallout]/fallout/config_s.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config = {
boardRows = get("boardRows"), --Default:10 Number of rows to put on the board
boardColumns = get("boardColumns"), --Default:8 Number of columns to put on the board
winningBoards = get("winningBoards"), --Default:3 Number of boards that will not fall. Must be higher than board count!
scoreLimit = get("scoreLimit"), --Default:10 wins required to win the fallout tournament default is 10
callSpeedA = get("callSpeedA"), --Default:250 Call speed when 30 or more boards exist
callSpeedB = get("callSpeedB"), --Default:500 Call speed when 29 to 15 boards exist
callSpeedC = get("callSpeedC"), --Default:750 Call speed when 14 or less boards exist
peacefulMode = get("peacefulMode") == "true" -- Default:true Disable player melee attack
}
31 changes: 31 additions & 0 deletions [gamemodes]/[fallout]/fallout/displays_s.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
textDisplays = {}
textItems = {}

textDisplays.countDownDisplay = textCreateDisplay()
textItems.countDownText = textCreateTextItem("", 0.5, 0.3, "high", 255, 127, 0, 255, 2, "center")
textDisplayAddText(textDisplays.countDownDisplay, textItems.countDownText)

textDisplays.suicideDisplay = textCreateDisplay()
local suicideText = textCreateTextItem("You lose! Press space for a quick death.", 0.5, 0.5, "low", 255, 127, 0, 255, 2, "center")
textDisplayAddText(textDisplays.suicideDisplay, suicideText)

textDisplays.winnersDisplay = textCreateDisplay()
textItems.winnersText = textCreateTextItem("Winners:", 0.5, 0.35, "low", 255, 127, 0, 255, 2, "center", "center")
textDisplayAddText(textDisplays.winnersDisplay, textItems.winnersText)

textDisplays.spectatorCamDisplay = textCreateDisplay()
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")
textDisplayAddText(textDisplays.spectatorCamDisplay, textItems.specCamText)

textDisplays.podiumDisplay = textCreateDisplay()

textItems.firstText = textCreateTextItem("1st:", 0.45, 0.08, "high", 255, 127, 0, 255, 1.5)
textItems.secondText = textCreateTextItem("2nd:", 0.45, 0.12, "high", 255, 127, 0, 255, 1.5)
textItems.thirdText = textCreateTextItem("3rd:", 0.45, 0.16, "high", 255, 127, 0, 255, 1.5)

-- Tournament text
textDisplayAddText(textDisplays.podiumDisplay, textCreateTextItem("Tournament Leaders", 0.45, 0.04, "high", 255, 127, 0, 255, 1.5))

textDisplayAddText(textDisplays.podiumDisplay, textItems.firstText)
textDisplayAddText(textDisplays.podiumDisplay, textItems.secondText)
textDisplayAddText(textDisplays.podiumDisplay, textItems.thirdText)
79 changes: 27 additions & 52 deletions [gamemodes]/[fallout]/fallout/fallout_c.lua
Original file line number Diff line number Diff line change
@@ -1,59 +1,34 @@
fadeCamera(true)
gameOver = false
local shakeState = false
local shakingPieces = {}

function initGame()
triggerServerEvent("serverClientLoad", root)
end
addEventHandler("onClientResourceStart", resourceRoot, initGame, false)

function shakeOnRender()
if gameOver == false then
local currentTick = getTickCount()
for object, originalTick in pairs(shakingPieces) do
local tickDifference = currentTick - originalTick
if tickDifference > 2400 then
shakingPieces[object] = nil
else
--since newx/newy increases by 1 every 125ms, we can use this ratio to calculate a more accurate time
local newx = tickDifference / 125 * 1
local newy = tickDifference / 125 * 1
if isElement(object) then
setElementRotation(object, math.deg(0.555), 3 * math.cos(newy + 1), 3 * math.sin(newx + 1))
end
end
end
end
end
addEventHandler("onClientRender", root, shakeOnRender)

function ShakePieces(fallingPiece)
--we store the time when the piece was told to shake under a table, so multiple objects can be stored
shakingPieces[fallingPiece] = getTickCount()
local currentTick = getTickCount()
for object, originalTick in pairs(shakingPieces) do
local tickDifference = currentTick - originalTick
if tickDifference > 2400 or not isElement(object) then
shakingPieces[object] = nil
else
--since newx/newy increases by 1 every 125ms, we can use this ratio to calculate a more accurate time
local newx = tickDifference / 125 * 1
local newy = tickDifference / 125 * 1
setElementRotation(object, math.deg(0.555), 3 * math.cos(newy + 1), 3 * math.sin(newx + 1))
end
end
if not next(shakingPieces) and shakeState then
removeEventHandler("onClientRender", root, shakeOnRender)
shakeState = false
end
end
addEvent("clientShakePieces", true)
addEventHandler("clientShakePieces", root, ShakePieces)

function DetectionOff(fallingPiece)
checkStatusTimer = nil
gameOver = true
end
addEvent("lossDetectionOff", true)
addEventHandler("lossDetectionOff", root, DetectionOff)

function checkStatusB()
local x, y, z = getElementPosition(localPlayer)
if z < 595 and (checkStatusTimer) then
triggerServerEvent("serverReportLoss", localPlayer)
playSoundFrontEnd(4)
killTimer(checkStatusTimer)
checkStatusTimer = nil
end
end

function checkStatus()
gameOver = false
checkStatusTimer = setTimer(checkStatusB, 500, 0)
end
addEvent("clientCheckStatus", true)
addEventHandler("clientCheckStatus", root, checkStatus)
addEvent("onClientShakePieces", true)
addEventHandler("onClientShakePieces", resourceRoot,
function ()
-- we store the time when the piece was told to shake under a table, so multiple objects can be stored
shakingPieces[source] = getTickCount()
if not shakeState then
addEventHandler("onClientRender", root, shakeOnRender)
shakeState = true
end
end, true)
Loading

0 comments on commit c733b69

Please sign in to comment.