Skip to content

Commit

Permalink
Added spawn protection. quick and dirty. probably needs refined. #27
Browse files Browse the repository at this point in the history
  • Loading branch information
kythre committed Feb 18, 2019
1 parent d1dfceb commit 03ebaab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
33 changes: 32 additions & 1 deletion lua/ulx/modules/sh/sh_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ local function _kyle_Buildmode_Enable(z)
end

local function _kyle_Buildmode_Disable(z)
local timername = "_Kyle_Buildmode_spawnprotection_" .. z:GetName()
if timer.Exists(timername) then
timer.Destroy(timername)
end

z.buildmode = false

--second buildmode variable for halos and status text on hover
Expand Down Expand Up @@ -475,6 +480,26 @@ hook.Add("PlayerSpawn", "kyleBuildmodePlayerSpawn", function(z)
--z:GetNWBool("_kyle_died") makes sure that the player is spawning after an actual death and not the ulib respawn function
if ((_Kyle_Buildmode["spawnwithbuildmode"]=="1" and not z:GetNWBool("_Kyle_pvpoverride")) or z:GetNWBool("_Kyle_Buildmode")) and z:GetNWBool("_kyle_died") then
_kyle_Buildmode_Enable(z)
elseif (not z:GetNWBool("_Kyle_Buildmode")) and z:GetNWBool("_kyle_died") then
if tonumber(_Kyle_Buildmode["spawnprotection"])>0 then
z:SendLua("GAMEMODE:AddNotify(\"".._Kyle_Buildmode["spawnprotection"].." seconds of Spawn Protection enabled. Type !pvp to disable\",NOTIFY_GENERIC, 5)")
z.buildmode = true
z:SetNWBool("_Kyle_Buildmode", true)
local timername = "_Kyle_Buildmode_spawnprotection_" .. z:GetName()
if timer.Exists(timername) then
timer.Destroy(timername)
end
timer.Create(timername, _Kyle_Buildmode["spawnprotection"], 1, function()
z:SetNWBool("_Kyle_Buildmode", false)
z.buildmode = false
if _Kyle_Buildmode["restrictweapons"]=="1" then
z:ConCommand("kylebuildmode defaultloadout")
end
z:SendLua("GAMEMODE:AddNotify(\"Spawn protection ended\",NOTIFY_GENERIC, 5)")
end)
else

end
end
z:SetNWBool("_kyle_died", false)

Expand All @@ -488,6 +513,12 @@ end )

hook.Add("PostPlayerDeath", "kyleBuildmodePostPlayerDeath", function(z)
z:SetNWBool("_kyle_died", true)
local timername = "_Kyle_Buildmode_spawnprotection_" .. z:GetName()
if timer.Exists(timername) then
z:SetNWBool("_Kyle_Buildmode", false)
z.buildmode = false
timer.Destroy(timername)
end
end, HOOK_HIGH )

hook.Add("PlayerGiveSWEP", "kylebuildmoderestrictswep", function(y, z)
Expand All @@ -508,7 +539,7 @@ end)

hook.Add("PlayerCanPickupWeapon", "kylebuildmoderestrictswep", function(y, z)
if not _kyle_builder_spawn_weapon(y, string.Split(string.Split(tostring(z),"][", true)[2],"]", true)[1]) then
return false
return false
end
end)

Expand Down
2 changes: 1 addition & 1 deletion lua/ulx/xgui/server/sv_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ xgui.addSVModule( "kylebuildmode_load", function()
xgui.addDataType( "_Kyle_Buildmode", function() end, "kylebuildmodesettings", 0, -10 )

--Load defaults in to settings table
_Kyle_Buildmode["spawnprotection"] = 0
_Kyle_Buildmode["restrictweapons"] = 0
_Kyle_Buildmode["restrictsents"] = 0
_Kyle_Buildmode["restrictvehicles"] = 0
Expand All @@ -37,7 +38,6 @@ xgui.addSVModule( "kylebuildmode_load", function()
_Kyle_Buildmode["weaponlistmode"] = 0
_Kyle_Buildmode["entitylistmode"] = 1
_Kyle_Buildmode["vehiclelistmode"] = 1
_Kyle_Buildmode["test"] = 1
_Kyle_Buildmode["highlightbuilderscolor"]= "0,128,255"
_Kyle_Buildmode["highlightpvperscolor"]= "255,0,0"
_Kyle_Buildmode["builddelay"] = 0
Expand Down
10 changes: 10 additions & 0 deletions lua/ulx/xgui/settings/cl_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ number_buildmodedelay.OnValueChanged = function(y, z)
RunConsoleCommand("kylebuildmode", "set", "builddelay", z)
end
end
local number_spawnprotection = xlib.makenumberwang {x=5, y=70, w=35, parent=panel_entering }
local label_spawnprotection = xlib.makelabel{ x=number_spawnprotection.x+40, y=number_spawnprotection.y+2, w=500, h=15, parent=panel_entering, label="Spawn Protection" }
number_spawnprotection.OnValueChanged = function(y, z)
if _Kyle_Buildmode["spawnprotection"] != z then
RunConsoleCommand("kylebuildmode", "set", "spawnprotection", z)
end
end



--"While IN Buildmdode" Panel
local panel_whilein = xlib.makepanel{ x=160, y=5, w=425, h=322, parent=b}
local check_restrictweapons = xlib.makecheckbox{ x=5, y=5, label="Restrict weapons with 'Builder Weapons'", parent=panel_whilein, repconvar="rep_kylebuildmode_restrictweapons"}
Expand Down

0 comments on commit 03ebaab

Please sign in to comment.