Skip to content

Commit

Permalink
Fixed tactical delete after spawn, try spawn fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost de Niet committed May 16, 2023
1 parent 631806b commit e1a279d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 76 deletions.
3 changes: 2 additions & 1 deletion __init__.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions events/game_logic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ 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
return
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
Expand Down
112 changes: 40 additions & 72 deletions events/player_connect.lua
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions events/player_connected_watch_events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions events/player_disconnect.lua
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions utils/player/player_function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions utils/utils.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1a279d

Please sign in to comment.