Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfachMaxPC committed Apr 5, 2021
1 parent a2e8ecd commit 3356f79
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 59 deletions.
12 changes: 8 additions & 4 deletions Server/Helpers/Commands.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
RegisterServerCommand("alivetraitors", function(players, args)
Game:SendNotification("Alive traitors: ".. Game:GetAliveTraitors(), "error")
end)

RegisterServerCommand("stopround", function(player, args)
print("[Console] Round stopped by ".. player:GetName())

Server:SendNotification("The round was stopped by admin", "error")
Game:SendNotification("The round was stopped by admin", "error")

TTT:StopRound()
Game:StopRound()
end)

RegisterServerCommand("startround", function(player, args)
print("[Console] Round started by ".. player:GetName())

TTT:StartRound()
Game:StartRound()
end)

RegisterServerCommand("kill", function(player, args)
Expand Down Expand Up @@ -93,7 +97,7 @@ RegisterServerCommand("pos", function(player, args)

print("[POSITION] Saved Position: ".. dump(character:GetLocation()))

Server:SendChatMessage(player, "[POSITION] Saved Position: ".. dump(character:GetLocation()))
Game:SendChatMessage(player, "[POSITION] Saved Position: ".. dump(character:GetLocation()))
end)

RegisterServerCommand("teleport", function(player, args)
Expand Down
18 changes: 6 additions & 12 deletions Server/Helpers/ExternalFunctions.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
--
NanosServer = Server
Server = inherit(DataObject)
registerElementClass("Server", Server)
--

function table.Count( t )
local i = 0
for k in pairs( t ) do i = i + 1 end
Expand Down Expand Up @@ -43,7 +37,7 @@ function math.randomchoice(t)
return table[index]
end

function Server:GetAlivePlayers()
function Game:GetAlivePlayers()
local alivePlayers = 0
for i,player in pairs(NanosPlayer) do
if(player:GetData("playerAlive") ~= nil) then
Expand All @@ -56,13 +50,13 @@ function Server:GetAlivePlayers()
return alivePlayers
end

function Server:SendNotification(message, type)
function Game:SendNotification(message, type)
type = type or "info"
Events:BroadcastRemote("SendNoti", { message, type })
Events:BroadcastRemote("PlaySound", { "PolygonWorld::ClickSound" })
end

function Server:GetAliveTraitors()
function Game:GetAliveTraitors()
local alivePlayers = 0
for i,player in pairs(NanosPlayer) do
if(player:GetAlive() == true) then
Expand All @@ -75,7 +69,7 @@ function Server:GetAliveTraitors()
return alivePlayers
end

function Server:GetAliveInnocents() -- Detektive ist auch irgendwie Innocent
function Game:GetAliveInnocents() -- Detektive ist auch irgendwie Innocent
local alivePlayers = 0
for i,player in pairs(NanosPlayer) do
if(player:GetAlive() == true) then
Expand All @@ -88,15 +82,15 @@ function Server:GetAliveInnocents() -- Detektive ist auch irgendwie Innocent
return alivePlayers
end

function Server:GiveRoleKarma(role, karma)
function Game:GiveRoleKarma(role, karma)
for i,player in pairs(NanosPlayer) do
if(player:GetRole() == role) then
player:GiveKarma(karma)
end
end
end

function Server:RemoveRoleKarma(role, karma)
function Game:RemoveRoleKarma(role, karma)
for i,player in pairs(NanosPlayer) do
if(player:GetRole() == role) then
player:RemoveKarma(karma)
Expand Down
13 changes: 3 additions & 10 deletions Server/Helpers/PlayerFunctions.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--
NanosPlayer = Player
Player = inherit(DataObject)
registerElementClass("Player", Player)
--


function Player:SetGodmode(state)
local char = self:GetControlledCharacter()
if(char == nil) then
Expand Down Expand Up @@ -36,7 +29,7 @@ function Player:SetRole(role)

if (role == ROLES.TRAITOR) then

Server:SendChatMessage(self, "You are now the TRAITOR!")
self:SendNotification("You are now the TRAITOR!")
print("TRAITOR")

for i,player in pairs(NanosPlayer) do
Expand All @@ -50,12 +43,12 @@ function Player:SetRole(role)

elseif (role == ROLES.DETECTIVE) then

Server:SendChatMessage(self, "You are now the DETECTIVE!")
self:SendNotification("You are now the DETECTIVE!")
print("DETECTIVE")

elseif (role == ROLES.INNOCENT) then

Server:SendChatMessage(self, "You are now the INNOCENT!")
self:SendNotification("You are now the INNOCENT!")
print("INNOCENT")

end
Expand Down
31 changes: 22 additions & 9 deletions Server/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ TTTSettings = {
min_players_detectives = 10,
}

Game = inherit(Singleton) -- new
Game:New()

function Game:constructor()

end

--
NanosPlayer = Player
Player = inherit(DataObject)
registerElementClass("Player", Player)
--

-- Importieren der unterschiedlichen Dateien
Package:Require("Helpers/PlayerFunctions.lua")
Package:Require("Helpers/ExternalFunctions.lua")
Expand Down Expand Up @@ -56,27 +69,27 @@ end)

-- Wenn ein Spieler nicht mehr auf dem Server ist
NanosPlayer:Subscribe("Destroy", function(player)
NanosServer:BroadcastChatMessage("<red>".. player:GetName() .."</> has left the server!")
player:SendPlayerMessage(player:GetName() .." has left the server!")

if(TTT.match_state == MATCH_STATES.IN_PROGRESS) then

-- Wenn Terrorist das Match verlässt
if(player:GetRole() == ROLES.TRAITOR) then
TTT:StopRound()
NanosServer:SendNotification("The round aborted because the traitor left the game", "error")
Game:StopRound()
Game:SendNotification("The round aborted because the traitor left the game", "error")
return
end

-- Runde wird beendet wenn weniger wie zwei Spieler noch dabei sind
if(NanosServer:GetAlivePlayers() < 2) then
TTT:StopRound()
NanosServer:SendNotification("The round was cancelled because there are not enough players left", "error")
if(Game:GetAlivePlayers() < 2) then
Game:StopRound()
Game:SendNotification("The round was cancelled because there are not enough players left", "error")
end

end
end)

function TTT:StartRound()
function Game:StartRound()
if(TTT.match_state == MATCH_STATES.IN_PROGRESS) then return end

TTT.match_state = MATCH_STATES.PREPAIRING
Expand All @@ -95,10 +108,10 @@ function TTT:StartRound()
end
end

function TTT:StopRound()
function Game:StopRound()
if(TTT.match_state ~= MATCH_STATES.IN_PROGRESS) then return end

NanosServer:SendNotification("The round is started manually, wait for the round begin.")
Game:SendNotification("The round is started manually, wait for the round begin.")

-- HUD wird angepasst
Events:BroadcastRemote("UpdatePlayerFraction", { -1 }) -- Rolle wird auf "MATCH OVER" geändert
Expand Down
20 changes: 10 additions & 10 deletions Server/Player/DeathHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@ Character:Subscribe("Death", function(character)
if(TTT.match_state == MATCH_STATES.IN_PROGRESS) then

-- INNO WIN
if(Server:GetAliveTraitors() <= 0 and progressRoundEnd == false) then
if(Game:GetAliveTraitors() <= 0 and progressRoundEnd == false) then
-- Innocents haben alle Traitor getötet

Events:BroadcastRemote("UpdatePlayerFraction", { -1 })
Events:BroadcastRemote("TTT_InnoWonScreen", { true })

Server:SendNotification("Innocent won the round")
Game:SendNotification("Innocent won the round")

Server:GiveRoleKarma(ROLES.INNOCENT, 30)
Server:RemoveRoleKarma(ROLES.TRAITOR, 30)
Game:GiveRoleKarma(ROLES.INNOCENT, 30)
Game:RemoveRoleKarma(ROLES.TRAITOR, 30)

progressRoundEnd = true

local StopRoundTimer = Timer:SetTimeout(5000, function()
Events:BroadcastRemote("TTT_InnoWonScreen", { false }) -- WIN wird wieder ausgeblendet
progressRoundEnd = false
TTT:StopRound()
Game:StopRound()
return false
end)

return
end

-- TRAITOR WIN
if(player:GetRole() == ROLES.INNOCENT and progressRoundEnd == false and Server:GetAliveInnocents() <= 0) then
if(player:GetRole() == ROLES.INNOCENT and progressRoundEnd == false and Game:GetAliveInnocents() <= 0) then

Events:BroadcastRemote("UpdatePlayerFraction", { -1 })
Events:BroadcastRemote("TTT_TerrorWonScreen", { true })

Server:SendNotification("Traitors won the round")
Game:SendNotification("Traitors won the round")

Server:GiveRoleKarma(ROLES.TRAITOR, 30)
Server:RemoveRoleKarma(ROLES.INNOCENT, 30)
Game:GiveRoleKarma(ROLES.TRAITOR, 30)
Game:RemoveRoleKarma(ROLES.INNOCENT, 30)

progressRoundEnd = true

local StopRoundTimer = Timer:SetTimeout(5000, function()
Events:BroadcastRemote("TTT_TerrorWonScreen", { false }) -- Win wird wieder ausgeblendet
progressRoundEnd = false
TTT:StopRound()
Game:StopRound()
return false
end)

Expand Down
2 changes: 0 additions & 2 deletions Server/Player/SpawnHandler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ character_meshes = {
}
-- Spawn System
NanosPlayer:Subscribe("Spawn", function(player)
NanosServer:BroadcastChatMessage("<blue>".. player:GetName() .."</> now wait for the start of the game!")

-- Spieler wird gehalten solang eine Runde läuft
if(TTT.match_state == MATCH_STATES.IN_PROGRESS) then
-- Runde läuft bereits
Expand Down
4 changes: 2 additions & 2 deletions Server/Timers/RoundTimer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Timer:SetTimeout(1000, function()
Events:BroadcastRemote("UpdatePlayerFraction", { -1 })
Events:BroadcastRemote("TTT_InnoWonScreen", { true })

Server:SendNotification("Innocent have won the round, the time is over.", "success")
Game:SendNotification("Innocent have won the round, the time is over.", "success")

Timer:SetTimeout(5000, function()
Events:BroadcastRemote("TTT_InnoWonScreen", { false }) -- WIN wird wieder ausgeblendet
Expand All @@ -38,7 +38,7 @@ Timer:SetTimeout(1000, function()

if(player_count < 2) then
TTT.match_state = WARM_UP
Server:SendNotification("Not enough players to start a round", "error")
Game:SendNotification("Not enough players to start a round", "error")
return
end

Expand Down
26 changes: 26 additions & 0 deletions Shared/Classes/Singleton.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Singleton = {}

function Singleton:GetSingleton(...)
if not self.ms_Instance then
self.ms_Instance = self:New(...)
end
return self.ms_Instance
end

function Singleton:New(...)
self.New = function() end
local inst = new(self, ...)
self.ms_Instance = inst
return inst
end

function Singleton:IsInstantiated()
return self.ms_Instance ~= nil
end

function Singleton:virtual_destructor()
for k, v in pairs(super(self)) do
v.ms_Instance = nil
v.New = Singleton.New
end
end
Loading

0 comments on commit 3356f79

Please sign in to comment.