Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
-renamed killonpvp to returntospawn
-added a way to override spawnonbuild for anyone who wants to stay in pvp
-chaged the way settings load to where saved settings take precedence
  • Loading branch information
kythre committed Mar 20, 2018
1 parent 7bc628f commit 3bb8ce9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
76 changes: 37 additions & 39 deletions lua/ulx/modules/sh/sh_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ end

local function _kyle_Buildmode_Enable(z)
z:SendLua("GAMEMODE:AddNotify(\"Buildmode enabled. Type !pvp to disable\",NOTIFY_GENERIC, 5)")

if z:Alive() then
ULib.getSpawnInfo( z )
ULib.getSpawnInfo(z)
if _Kyle_Buildmode["restrictweapons"]=="1" then
z:StripWeapons()
for x,y in pairs(_Kyle_Buildmode["buildloadout"]) do
Expand All @@ -63,47 +64,48 @@ local function _kyle_Buildmode_Enable(z)
NoCollide(z:GetVehicle())
end
end

--having two buildmode variables seems redundant, however im too lazy to replace one with the other (if possible)
z.buildmode = true
z:SetNWBool("_Kyle_Buildmode",true)
z:SetNWBool("_Kyle_Buildmode", true)

--boolean to say if buildmode was enabled because the player had just spawned
z:SetNWBool("_Kyle_BuildmodeOnSpawn", z:GetNWBool("_kyle_died"))
end

local function _kyle_Buildmode_Disable(z)
z:SetNWBool("_Kyle_Buildmode", false)
z.buildmode = false
z:SendLua("GAMEMODE:AddNotify(\"Buildmode disabled.\",NOTIFY_GENERIC, 5)")

if z:Alive() then
local pos = z:GetPos()

if _Kyle_Buildmode["killonpvp"]=="1" and z:InVehicle() then
z:ExitVehicle()
end

if _Kyle_Buildmode["restrictweapons"]=="1" and not z:GetNWBool("_Kyle_BuildmodeOnSpawn") then
ULib.spawn( z, true ) --Returns the player to spawn with the weapons they had before entering buildmode
end

if _Kyle_Buildmode["killonpvp"]=="1" then
ULib.spawn( z, false) --Returns the player to spawn
end
if z:InVehicle() then
TryUnNoCollide(z:GetVehicle())
if _Kyle_Buildmode["returntospawn"]=="1" then
--eject player from vehicle so they can be returned to spawn
z:ExitVehicle()
end
end

if _Kyle_Buildmode["restrictweapons"]=="1" and z:GetNWBool("_Kyle_BuildmodeOnSpawn") then
z:ConCommand("kylebuildmode defaultloadout") --called when buildmode is disabled after spawning with it enabled
if _Kyle_Buildmode["restrictweapons"]=="1" then
--dont use spawn info that doesnt exist
ULib.spawn( z, not z:GetNWBool("_Kyle_BuildmodeOnSpawn") )
--if there isnt any spawn info, use the default loadout
if z:GetNWBool("_Kyle_BuildmodeOnSpawn") then z:ConCommand("kylebuildmode defaultloadout") end
end

if _Kyle_Buildmode["killonpvp"]=="0" then
z:SetPos( pos ) --Returns the player to where they where when they disabled buildmode
--ULIB.spawn moves the player to spawn, this will return the player to where they where while in buildmode
if _Kyle_Buildmode["returntospawn"]=="0" then
z:SetPos(pos)
end

if z:GetNWBool("kylenocliped") then
z:ConCommand( "noclip" ) --called when the player had noclip while in buildmode
--called when the player had noclip while in buildmode
z:ConCommand( "noclip" )
end

if z:InVehicle() then
TryUnNoCollide(z:GetVehicle())
end
end

z.buildmode = false
z:SendLua("GAMEMODE:AddNotify(\"Buildmode disabled.\",NOTIFY_GENERIC, 5)")
z:SetNWBool("_Kyle_Buildmode",false)
end

local function _kyle_builder_spawn_weapon(z)
Expand Down Expand Up @@ -160,16 +162,16 @@ hook.Add("PlayerNoClip", "KylebuildmodeNoclip", function(y, z)
end )

hook.Add("PlayerSpawn", "kyleBuildmodePlayerSpawn", function(z)
if (_Kyle_Buildmode["spawnwithbuildmode"]=="1" or z:GetNWBool("_Kyle_Buildmode")) and z:GetNWBool("_kyle_died") then
--z:GetNWBool("_kyle_died") makes sure that the player is spawning after a death and not the ulib respawn
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)
end
z:SetNWBool("_kyle_died", false)
end )

hook.Add("PlayerInitialSpawn", "kyleBuildmodePlayerInitilaSpawn", function (z)
if _Kyle_Buildmode["spawnwithbuildmode"]=="1" then
_kyle_Buildmode_Enable(z)
end
z:SetNWBool("_kyle_died", true)
z:SetNWBool("_Kyle_pvpoverride", false)
end )

hook.Add("PostPlayerDeath", "kyleBuildmodePostPlayerDeath", function(z)
Expand All @@ -192,14 +194,7 @@ end)

hook.Add("PlayerCanPickupWeapon", "kylebuildmoderestrictswep", function(y, z)
if y.buildmode and _Kyle_Buildmode["restrictweapons"]=="1" and not _kyle_builder_spawn_weapon(string.Split(string.Split(tostring(z),"][", true)[2],"]", true)[1]) then
if not y:GetNWBool("_kyle_buildNotify") then
y:SetNWBool("_kyle_buildNotify", true)
y:SendLua("GAMEMODE:AddNotify(\"You cannot pick this weapon up while in Build Mode.\",NOTIFY_GENERIC, 5)")
timer.Create( "_kyle_NotifyBuildmode", 5, 1, function()
y:SetNWBool("_kyle_buildNotify", false)
end)
end
return false
return false
end
end)

Expand Down Expand Up @@ -244,6 +239,9 @@ local CATEGORY_NAME = "_Kyle_1"
local buildmode = ulx.command( "_Kyle_1", "ulx buildmode", function( calling_ply, target_plys, should_revoke )
local affected_plys = {}
for y,z in pairs(target_plys) do
if calling_ply == z and _Kyle_Buildmode["persistpvp"]=="1" then
z:SetNWBool("_Kyle_pvpoverride", not should_revoke)
end
if not z.buildmode and not should_revoke and not z:GetNWBool("kylependingbuildchange") then
if _Kyle_Buildmode["builddelay"]!="0" then
z:SendLua("GAMEMODE:AddNotify(\"Enabling Buildmode in "..tonumber(_Kyle_Buildmode["builddelay"]).." seconds.\",NOTIFY_GENERIC, 5)")
Expand Down
15 changes: 9 additions & 6 deletions lua/ulx/xgui/server/sv_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ xgui.addSVModule( "kylebuildmode_load", function()
_Kyle_Buildmode["restrictweapons"] = 0
_Kyle_Buildmode["restrictsents"] = 0
_Kyle_Buildmode["allownoclip"] = 0
_Kyle_Buildmode["killonpvp"] = 0
_Kyle_Buildmode["returntospawn"] = 0
_Kyle_Buildmode["antipropkill"] = 0
_Kyle_Buildmode["spawnwithbuildmode"] = 0
_Kyle_Buildmode["persistpvp"] = 0
_Kyle_Buildmode["disablepvppropspawn"] = 0
_Kyle_Buildmode["highlightbuilders"] = 0
_Kyle_Buildmode["highlightpvpers"] = 0
Expand All @@ -41,19 +42,21 @@ xgui.addSVModule( "kylebuildmode_load", function()
_Kyle_Buildmode["pvpdelay"] = 0

--Load saved settings
local saved = {}
if file.Exists( "kylebuildmode.txt", "DATA" ) then
local saved = ULib.parseKeyValues( file.Read( "kylebuildmode.txt" ))
saved = ULib.parseKeyValues( file.Read( "kylebuildmode.txt" ))
end

--Replaced the default settings with the saved settings
for a,b in pairs(_Kyle_Buildmode) do
if not a then _Kyle_Buildmode[b] = saved[b] end
--Make sure all of the saved settings overwrite the default settings
for a,b in pairs(saved) do
_Kyle_Buildmode[b] = saved[b]
end

ULib.replicatedWritableCvar("kylebuildmode_restrictweapons", "rep_kylebuildmode_restrictweapons", _Kyle_Buildmode["restrictweapons"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_restrictsents", "rep_kylebuildmode_restrictsents", _Kyle_Buildmode["restrictsents"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_killonpvp", "rep_kylebuildmode_killonpvp", _Kyle_Buildmode["killonpvp"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_returntospawn", "rep_kylebuildmode_returntospawn", _Kyle_Buildmode["returntospawn"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_spawnwithbuildmode", "rep_kylebuildmode_spawnwithbuildmode", _Kyle_Buildmode["spawnwithbuildmode"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_persistpvp", "rep_kylebuildmode_persistpvp", _Kyle_Buildmode["persistpvp"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_allownoclip", "rep_kylebuildmode_allownoclip", _Kyle_Buildmode["allownoclip"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_antipropkill", "rep_kylebuildmode_antipropkill", _Kyle_Buildmode["antipropkill"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_highlightbuilders", "rep_kylebuildmode_highlightbuilders", _Kyle_Buildmode["highlightbuilders"], false,true,"kylebuildmodesettings")
Expand Down
5 changes: 3 additions & 2 deletions lua/ulx/xgui/settings/cl_kyle_buildmode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ panels = {}
--"Entering Buildmdode" Panel
local panel_entering = xlib.makepanel{ x=160, y=5, w=425, h=322, parent=b}
local check_buildmodespawn = xlib.makecheckbox{ x=5, y=5, label="Players Spawn with Buildmode", parent=panel_entering, repconvar="rep_kylebuildmode_spawnwithbuildmode"}
local number_buildmodedelay = xlib.makenumberwang {x=5, y=25, w=35, parent=panel_entering }
local check_pvppersist = xlib.makecheckbox{ x=5, y=25, label="Override the above if the player was in PVP", parent=panel_entering, repconvar="rep_kylebuildmode_persistpvp"}
local number_buildmodedelay = xlib.makenumberwang {x=5, y=45, w=35, parent=panel_entering }
local label_buildmodedelay = xlib.makelabel{ x=number_buildmodedelay.x+40, y=number_buildmodedelay.y+2, w=500, h=15, parent=panel_entering, label="Buildmode Delay" }
number_buildmodedelay.OnValueChanged = function(y, z)
if _Kyle_Buildmode["builddelay"] != z then
Expand All @@ -25,7 +26,7 @@ local check_highlightpvpers = xlib.makecheckbox{ x=5, y=105, label="Highlight

--"Exiting Buildmdode" Panel
local panel_exiting = xlib.makepanel{ x=160, y=5, w=425, h=322, parent=b}
local check_buildmoderespawn = xlib.makecheckbox{ x=5, y=5, label="Respawn Player on Buildmode exit", parent=panel_exiting, repconvar="rep_kylebuildmode_killonpvp"}
local check_buildmoderespawn = xlib.makecheckbox{ x=5, y=5, label="Return Player to spawn on Buildmode exit", parent=panel_exiting, repconvar="rep_kylebuildmode_returntospawn"}
local number_pvpdelay = xlib.makenumberwang {x=5, y=25, w=35, parent=panel_exiting }
local label_pvpdelay = xlib.makelabel{ x=number_pvpdelay.x+40, y=number_pvpdelay.y+2, w=500, h=15, parent=panel_exiting, label="PVP Delay" }
number_pvpdelay.OnValueChanged = function(y, z)
Expand Down

0 comments on commit 3bb8ce9

Please sign in to comment.