diff --git a/__init__.lua b/__init__.lua index bcf1d13..8b2de46 100644 --- a/__init__.lua +++ b/__init__.lua @@ -50,6 +50,7 @@ require("events/check_flag_tp") require("events/check_below_map_tp") require("events/check_zipline") require("events/player_connect") +require("events/player_disconnect") require("events/game_logic") require("events/broadcaster") require("events/player_killed") @@ -60,7 +61,7 @@ build.main() -- [[ Settings ]]-- game:executecommand("set sv_cheats 1") -game:executecommand("set team_rebalance 1") +game:executecommand("set team_rebalance 0") game:executecommand("set jump_height 60") game:executecommand("set jump_slowdownEnable 0") game:executecommand("set pm_bouncing 1") diff --git a/events/game_logic.lua b/events/game_logic.lua index ecea4ea..e0ccd2f 100644 --- a/events/game_logic.lua +++ b/events/game_logic.lua @@ -10,8 +10,8 @@ function chose_zombies() zombie2 = nil while(zombie1 == zombie2) do - zombie1 = players[math.random(1, #players)] - zombie2 = players[math.random(1, #players)] + zombie1 = survivors[math.random(1, #survivors)] + zombie2 = survivors[math.random(1, #survivors)] zombie1:ChangeTeam("axis") zombie2:ChangeTeam("axis") end @@ -19,12 +19,15 @@ function chose_zombies() end -- Chose only one infected - zombie1 = players[math.random(1, #players)] + zombie1 = survivors[math.random(1, #survivors)] zombie1:ChangeTeam("axis") end -- [[ Start the gamemode [show start message, countdown, chose infected] ]]-- function start_zombieland(start_zombieland_timer) + -- SET enough people (prevents for double start_zombieland) + config.enough_people = true + game:ontimeout(function() -- Start countdown message diff --git a/events/player_connect.lua b/events/player_connect.lua index 8d3eaa0..7acdd00 100644 --- a/events/player_connect.lua +++ b/events/player_connect.lua @@ -1,104 +1,72 @@ -- [[ PLAYER CONNECTED ONCE ]] -- function PlayerConnectedOnce(player) - -- Insert player to player lists + -- INSERT player to player lists table.insert(players, player) player.use_of_booster = 0 player.use_of_zipline = 0 + player.spawned = 0 + player.money = 0 - -- If the game has started, set the type of player to zombie - if config.started == true then - table.insert(zombies, player) - player.type = "zombie" - player.money = 50 - end + -- MENU + HandleMenu(player) - -- First time player message + -- FIRST time spawn logic player:onnotify("spawned_player", function() - player:PlayerMessage("^4Welcome to ^1RooieRonnie's ^6Zombieland!") - player:PlayerMessage("^5Creaded by ^2Joost de Niet!") - end) -end + if player.spawned == 0 then + -- ONE time message + player:PlayerMessage("^4Welcome to ^1RooieRonnie's ^6Zombieland!") + player:PlayerMessage("^5Creaded by ^2Joost de Niet!") + + -- If the game has started, set the type of player to zombie + game:ontimeout(function() + if config.started == true then + table.insert(zombies, player) + player:CreateTopMessage("You are now a zombie!", vector:new(1, 0, 0)) + ZombieSpawnLogic(player) + player:ChangeTeam("axis") + else -function has_value (tab, val) - for index, value in ipairs(tab) do - if value == val then - return true + table.insert(survivors, player) + player:CreateTopMessage("Welcome to RooieRonnie's ZombieLand", vector:new(0, 1, 0)) + SurvivorSpawnLogic(player) + + game:ontimeout(function() + player:CreateTopMessage("Survive as long as possible to win!", vector:new(0, 0, 1)) + game:ontimeout(function() + player:CreateTopMessage("Press [{+actionslot 2}] to open the shop!", vector:new(0.86, 0.81, 0.34)) + end, 9000) + end, 10000) + end + end, 500) + + -- Set spawned player to YES + player.spawned = 1 end - end - return false + end) end + -- [[ PLAYER CONNECTED ]] -- function PlayerConnected(player) - -- Default money if there is a error. - player.money = 50 - - HandleMenu(player) - -- Check if the game can start if config.started == false and config.enough_people == false then start_zombieland() - config.enough_people = true end - -- Handle spawn player + -- HANDLE spawn after DEAD player:onnotify("spawned_player", function() if player.type == "zombie" then - player:CreateTopMessage("You are now a zombie!", vector:new(1, 0, 0)) - player:GiveZombieClass() + ZombieSpawnLogic(player) if player.savedPosistion ~= nil then player:setplayerangles(player.savedAngle) player:setorigin(player.savedPosistion) player:iprintlnbold("^2You spawned at your tactical insertion") player.savedAngle = nil player.savedPosistion = nil + player.tactical:delete() end - return elseif player.type == nil then - table.insert(survivors, player) - player:CreateTopMessage("Welcome to RooieRonnie's ZombieLand", vector:new(0, 1, 0)) - player.type = "survivor" - player.money = 500 - - -- Survivor spawn message - game:ontimeout(function() - player:CreateTopMessage("Survive as long as possible to win!", vector:new(0, 0, 1)) - game:ontimeout(function() - player:CreateTopMessage("Press [{+actionslot 2}] to open the shop!", vector:new(0.86, 0.81, 0.34)) - end, 9000) - end, 10000) + SurvivorSpawnLogic(player) end - - -- standard surivivor script - player:freezecontrols(false) - player:GivePlayerClass() - - -- Temporary fix for tables - if player.team == "allies" then - player:RemovePlayerFromTable(zombies) - table.insert(survivors, player) - else - player:RemovePlayerFromTable(survivors) - table.insert(zombies, player) - end - end) -end - --- [[ HANDLE MENU ]] -- -function HandleMenu(player) - if config.started then - player:scriptcall("maps/mp/gametypes/_menus", "setteam", "axis") - else - player:scriptcall("maps/mp/gametypes/_menus", "setteam", "allies") - end -end - --- [[ PLAYER DISCONNECT ]] -- -function PlyerDisconnected(player) - player:onnotifyonce("disconnect", function () - CheckForPlayers() - player:RemovePlayerFromTable(players) - player:RemovePlayerFromTable(survivors) - player:RemovePlayerFromTable(zombies) end) end \ No newline at end of file diff --git a/events/player_connected_watch_events.lua b/events/player_connected_watch_events.lua index faf58b9..72df57d 100644 --- a/events/player_connected_watch_events.lua +++ b/events/player_connected_watch_events.lua @@ -36,6 +36,7 @@ function entity:SpawnClaymore() tactical:show() tactical:makeusable() tactical:sethintstring("Press ^3[{+activate}]^7 to ^1destroy ^7the tactical insertion") + self.tactical = tactical --local tacticalEffect = game:loadfx("vfx/unique/vfx_marker_dom") --local playtacticalEffect = game:playfx(tacticalEffect, self.origin) diff --git a/events/player_disconnect.lua b/events/player_disconnect.lua new file mode 100644 index 0000000..12be5fb --- /dev/null +++ b/events/player_disconnect.lua @@ -0,0 +1,9 @@ +-- [[ PLAYER DISCONNECT ]] -- +function PlyerDisconnected(player) + player:onnotifyonce("disconnect", function () + CheckForPlayers() + player:RemovePlayerFromTable(players) + player:RemovePlayerFromTable(survivors) + player:RemovePlayerFromTable(zombies) + end) +end \ No newline at end of file diff --git a/utils/player/player_function.lua b/utils/player/player_function.lua index 321ad3b..1b67d92 100644 --- a/utils/player/player_function.lua +++ b/utils/player/player_function.lua @@ -17,6 +17,21 @@ function entity:ChangeTeam(team) self:notify( "end_respawn" ) end +-- [[ ZOMBIE FIRST LOGIC ]] -- +function ZombieSpawnLogic(player) + player.type = "zombie" + player.money = 50 + player:GiveZombieClass() +end + +-- [[ SURVIVOR FIRST LOGIC ]] -- +function SurvivorSpawnLogic(player) + player.type = "survivor" + player.money = 500 + player:freezecontrols(false) + player:GivePlayerClass() + player:GivePlayerClass() +end function entity:is_bot() if (starts_with(self:getguid(), "bot")) then diff --git a/utils/utils.lua b/utils/utils.lua index a2989d2..d443d5c 100644 --- a/utils/utils.lua +++ b/utils/utils.lua @@ -1,4 +1,13 @@ -- [[ Convert seconds to ms ]] -- function ms(secs) return math.floor(secs * 1000) +end + +-- [[ HANDLE MENU ]] -- +function HandleMenu(player) + if config.started == true then + player:scriptcall("maps/mp/gametypes/_menus", "setteam", "axis") + else + player:scriptcall("maps/mp/gametypes/_menus", "setteam", "allies") + end end \ No newline at end of file