Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cLobbyManager = {};
- function cLobbyManager:constructor()
- -- CLASS VARS --
- self.tblLobbys = {};
- self.tblModesData = false;
- self.tblMinigames = {
- [1] = "cFiveTowers",
- [2] = "cAimArena",
- };
- self.tblPlayerLobbys = {};
- self.tblLobbyMarker = {
- {-2111.07, -444.06, 37.73},
- };
- -- BINDS --
- self.bPlayerQuit = bind(cLobbyManager.onPlayerQuit,self);
- self.bRequestCreate = bind(cLobbyManager.onRequestCreate, self);
- self.bOnNewLobby = bind(cLobbyManager.onRequestNewLobby, self);
- self.bOnJoinLobby = bind(cLobbyManager.onJoinLobby, self);
- self.bOnSpectate = bind(cLobbyManager.onSpeactate, self);
- self.bOnQuitSpectate = bind(cLobbyManager.onQuitSpectate, self);
- -- EVENTS --
- addEventHandler("onPlayerQuit", root, self.bPlayerQuit);
- addEvent("LobbyManager:requestCreate", true);
- addEventHandler("LobbyManager:requestCreate", root, self.bRequestCreate);
- addEvent("LobbyManager:create", true);
- addEventHandler("LobbyManager:create", root, self.bOnNewLobby);
- addEvent("LobbyManager:join", true);
- addEventHandler("LobbyManager:join", root, self.bOnJoinLobby);
- addEvent("LobbyManager:spectate", true);
- addEventHandler("LobbyManager:spectate", root, self.bOnSpectate);
- addEvent("LobbyManager:quitSpectate", true);
- addEventHandler("LobbyManager:quitSpectate", root, self.bOnQuitSpectate);
- -- INIT --
- self:setup();
- end
- function cLobbyManager:setup()
- for iID, strClass in pairs(self.tblMinigames) do
- self.tblMinigames[iID] = nil;
- if (_G[strClass]) then
- self.tblMinigames[iID] = strClass;
- end
- end
- for _, tblPos in pairs(self.tblLobbyMarker) do
- local uMarker = createMarker(tblPos[1], tblPos[2], tblPos[3], "cylinder", 1.5, 237, 207, 75, 200);
- addEventHandler("onMarkerHit", uMarker, function(uPlayer, bDim)
- if (bDim and uPlayer:isLoggedIn()) then
- local tblLobbys = {};
- for i, cLobby in pairs(self.tblLobbys) do
- table.insert(tblLobbys, {
- ID = i,
- Players = cLobby:getPlayerCount(),
- Status = cLobby:getStatus(),
- MaxPlayers = cLobby:getGame():getMaxPlayers(),
- Mode = cLobby:getGame():getName()
- });
- end
- return uPlayer:triggerEvent("LobbyBrowser:enter", uPlayer, tblLobbys);
- end
- end);
- end
- end
- function cLobbyManager:canCreate(uPlayer)
- return uPlayer:isAdmin(4);
- end
- function cLobbyManager:getFreeDimension()
- for i = 100, 9999, 1 do
- local bUsed = false;
- for _, cLobby in pairs(self.tblLobbys) do
- if (cLobby:getDimension() == i) then
- bUsed = true;
- break;
- end
- end
- if (bUsed == false) then
- return i;
- end
- end
- return math.random(100,9999);
- end
- function cLobbyManager:onRequestNewLobby(iMode, tblSettings)
- if (client and client:isLoggedIn()) then
- if (self:canCreate(client)) then
- local cLobby = self:onCreateLobby(client, iMode);
- cLobby:setMinPlayers(tblSettings.MinPlayers);
- cLobby:setMaxPlayers(tblSettings.MaxPlayers);
- cLobby:setRoundMode(tblSettings.RoundMode);
- end
- end
- end
- function cLobbyManager:onCreateLobby(uPlayer, iMode)
- if (uPlayer:isLoggedIn() and self.tblMinigames[iMode]) then
- local iLobby = #self.tblLobbys+1;
- local iDimension = self:getFreeDimension();
- self.tblLobbys[iLobby] = new(cGameLobby, iLobby, uPlayer, self.tblMinigames[iMode], iDimension);
- self:onJoinLobby(iLobby, uPlayer);
- return self.tblLobbys[iLobby];
- end
- return false;
- end
- function cLobbyManager:onPlayerQuit()
- if (self:isInLobby(source)) then
- return self:onLeaveLobby(source);
- end
- end
- function cLobbyManager:onLeaveLobby(uPlayer)
- if (self:isInLobby(uPlayer)) then
- local cLobby = self.tblPlayerLobbys[uPlayer];
- cLobby:removePlayer(uPlayer);
- self.tblPlayerLobbys[uPlayer] = nil;
- if (cLobby:getPlayerCount() <= 0) then
- cLobby:stop();
- end
- end
- end
- function cLobbyManager:isInLobby(uPlayer)
- if (self.tblPlayerLobbys[uPlayer]) then
- return true;
- end
- return false;
- end
- function cLobbyManager:onJoinLobby(iLobby, uPlayer, bSpec)
- local cLobby = self.tblLobbys[iLobby];
- local cInLobby = self.tblPlayerLobbys[uPlayer];
- if (cLobby and uPlayer:isLoggedIn() and (not cInLobby or cInLobby:getID() == iLobby)) then
- if (cLobby:canJoin()) then
- cLobby:addPlayer(uPlayer, bSpec);
- self.tblPlayerLobbys[uPlayer] = cLobby;
- else
- uPlayer:showInfo("Beitritt ist nicht mehr möglich", 3000, "Fehler", "error");
- end
- end
- end
- function cLobbyManager:onSpeactate(iLobby, uPlayer)
- local cLobby = self.tblLobbys[iLobby];
- if (cLobby and uPlayer:isLoggedIn()) then
- if (cLobby:canSpectate()) then
- cLobby:addSpectator(uPlayer);
- self.tblPlayerLobbys[uPlayer] = cLobby;
- else
- uPlayer:showInfo("Zuschauen ist nicht möglich", 3000, "Fehler", "error");
- end
- end
- end
- function cLobbyManager:onQuitSpectate(iLobby, uPlayer)
- if (client and client:isLoggedIn()) then
- if (self:isInLobby(client)) then
- local cLobby = self.tblPlayerLobbys[client];
- if (cLobby) then
- cLobby:removeSpectator(client);
- end
- end
- end
- end
- function cLobbyManager:onRequestCreate()
- if ((client) and (client:isLoggedIn())) then
- if (self:canCreate(client)) then
- if not self.tblModesData then
- self.tblModesData = {};
- for iID, strClass in pairs(self.tblMinigames) do
- local cMode = new(_G[strClass]);
- table.insert(self.tblModesData, {
- ID = iID,
- Name = cMode:getName(),
- MinPlayer = cMode:getMinPlayers(),
- MaxPlayer = cMode:getMaxPlayers(),
- });
- delete(cMode);
- end
- end
- return client:triggerEvent("LobbyBrowser:startCreate", client, self.tblModesData);
- else
- client:showInfo("Du hast keine Rechte dazu", 3000, "Fehler", "error");
- end
- end
- end
- addEventHandler("onResourceStart", resourceRoot, function()
- cInstanceManager:new(cLobbyManager, "LobbyManager");
- end);
- addCommandHandler("exitlobby", function(uPlayer)
- cInstanceManager:get("LobbyManager"):onLeaveLobby(uPlayer);
- end);
- -----------------------
- -- DEV COMMANDS
- -----------------------
- addCommandHandler("tlobby", function(uPlayer)
- local cM = cInstanceManager:get("LobbyManager");
- local iLobby = #cM.tblLobbys+1;
- local iDimension = cM:getFreeDimension();
- cM.tblLobbys[iLobby] = new(cGameLobby,iLobby, uPlayer, cM.tblMinigames[1], iDimension);
- end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement