This commit is contained in:
Kyle 2017-08-11 11:12:37 -05:00
commit ec80fc4b9d
4 changed files with 377 additions and 0 deletions

6
addon.txt Normal file
View File

@ -0,0 +1,6 @@
"AddonInfo"
{
"name" "Buildmode"
"version" "69"
"author_name" "Kyle"
}

View File

@ -0,0 +1,204 @@
_Kyle_Buildmode = _Kyle_Buildmode or {}
local function _kyle_Buildmode_Enable(z)
z:SendLua("GAMEMODE:AddNotify(\"Buildmode enabled. Type !pvp to disable\",NOTIFY_GENERIC, 5)")
ULib.getSpawnInfo( z )
if _Kyle_Buildmode["restrictweapons"]=="1" then
z:StripWeapons()
for x,y in pairs(_Kyle_Buildmode["buildloadout"]) do
z:Give(y)
print(y)
end
end
z.buildmode = true
z:SetNWBool("_Kyle_Buildmode",true)
end
local function _kyle_Buildmode_Disable(z)
if z:Alive() then
local pos = z:GetPos()
if _Kyle_Buildmode["restrictweapons"]=="1" or _Kyle_Buildmode["killonpvp"]=="1" then
ULib.spawn( z, false )
end
if _Kyle_Buildmode["killonpvp"]=="0" then
z:SetPos( pos )
end
end
z.buildmode = false
z:SendLua("GAMEMODE:AddNotify(\"Buildmode disabled.\",NOTIFY_GENERIC, 5)")
z:SetNWBool("_Kyle_Buildmode",false)
end
local u = true
local v = false
hook.Add("PreDrawHalos", "KyleBuildmodehalos", function()
local w = {}
local x = {}
local z = {}
for y,z in pairs(player.GetAll()) do
if _Kyle_Buildmode["highlightbuilders"]=="1" and z:Alive() then
if z:GetNWBool("_Kyle_Buildmode") then
table.insert(w, z)
else
table.insert(x, z)
end
end
end
if v then
z = string.Split( _Kyle_Buildmode["highlightbuilderscolor"],"," )
halo.Add(w, Color(z[1],z[2],z[3]), 4, 4, 1, true)
z = string.Split( _Kyle_Buildmode["highlightpvperscolor"],"," )
halo.Add(x, Color(z[1],z[2],z[3]), 4, 4, 1, true)
elseif u then
u = false
timer.Create( "u", 20, 1, function() v = true end)
end
end)
hook.Add("PhysgunPickup", "KylebuildmodePropKill", function(y,z)
if IsValid(z) and (not z:IsPlayer()) and y.buildmode and _Kyle_Buildmode["antipropkill"]=="1" then
z:SetNWInt("RenderMode", z:GetRenderMode())
z:SetNWInt("Alpha", z:GetColor()["a"])
z:SetColor( Color( z:GetColor()["r"], z:GetColor()["g"], z:GetColor()["b"], 200 ) )
z:SetRenderMode(1)
z:SetCustomCollisionCheck(true)
z:SetNWBool("NoCollide", true)
end
end)
local function UnNoclip(z)
z:SetNWBool("Colliding", false)
timer.Simple( 0.1, function()
if not z:GetNWBool("Colliding") and z:IsValid() then
z:SetNWBool("NoCollide", false)
z:SetColor( Color( z:GetColor()["r"], z:GetColor()["g"], z:GetColor()["b"], z:GetNWInt("Alpha") ) )
z:SetRenderMode(z:GetNWInt("RenderMode"))
elseif z:IsValid() then
UnNoclip(z)
end
end )
end
hook.Add("PhysgunDrop", "KylebuildmodePropKill", function(y,z)
if IsValid(z) and (not z:IsPlayer()) and y.buildmode and _Kyle_Buildmode["antipropkill"]=="1" then
z:SetPos(z:GetPos())
UnNoclip(z)
end
end)
hook.Add("ShouldCollide", "Kylebuildmodetrycollide", function(y, z)
print(y, y:GetNWBool("_Kyle_Buildmode"))
print(z, z:GetNWBool("_kyle_Buildmode"))
return true
--[[if (y:IsPlayer() or z:IsPlayer()) and _Kyle_Buildmode["antipropkill"]=="1" then
if y:IsPlayer() then
z:SetNWBool("Colliding", true)
if z:IsVehicle() then
print("a")
if y.buildmode or z:GetDriver().buildmode then
return false
end
end
else
y:SetNWBool("Colliding", true)
if y:IsVehicle() then
print("a")
if z.buildmode then
return false
end
end
end
if (y:GetNWBool("NoCollide") or z:GetNWBool("NoCollide")) then
return false
end
end ]]
end)
hook.Add("PlayerNoClip", "KylebuildmodeNoclip", function( y, z )
if z == false then
return true
elseif _Kyle_Buildmode["allownoclip"]=="1" and y.buildmode then
return true
end
end )
hook.Add("PlayerSpawn", "kyleBuildmodePlayerSpawn", function( z )
if _Kyle_Buildmode["spawnwithbuildmode"]=="1" and z:GetNWBool("_kyle_died") then
_kyle_Buildmode_Enable(z)
end
z:SetNWBool("_kyle_died", false)
end )
hook.Add("PostPlayerDeath", "kyleBuildmodePostPlayerDeath", function( z )
z:SetNWBool("_kyle_died", true)
end )
hook.Add( "PlayerInitialSpawn", "kyleBuildmodePlayerInitilaSpawn", function (z)
if _Kyle_Buildmode["spawnwithbuildmode"]=="1" then
_kyle_Buildmode_Enable(z)
end
end )
hook.Add("PlayerGiveSWEP", "kyleBuildmodeTrySWEPGive", function(y, z)
if y.buildmode and _Kyle_Buildmode["restrictweapons"]=="1" and not table.HasValue( _Kyle_Buildmode["buildloadout"], z ) then
y:SendLua("GAMEMODE:AddNotify(\"You cannot give yourself weapons while in Buildmode.\",NOTIFY_GENERIC, 5)")
return false
end
end)
hook.Add("PlayerSpawnSWEP", "kyleBuildmodeTrySWEPSpawn", function(y, z)
if y.buildmode and _Kyle_Buildmode["restrictweapons"]=="1" and not table.HasValue( _Kyle_Buildmode["buildloadout"], z ) then
y:SendLua("GAMEMODE:AddNotify(\"You cannot spawn weapons while in Buildmode.\",NOTIFY_GENERIC, 5)")
return false
end
end)
hook.Add("EntityTakeDamage", "kyleBuildmodeTryTakeDamage", function(y,z)
if y.buildmode or z:GetAttacker().buildmode then
z:SetDamage( 0 )
end
end)
hook.Add("PlayerCanPickupWeapon", "kyleBuildmodeTrySWEPPickup", function(y,z)
if y.buildmode and _Kyle_Buildmode["restrictweapons"]=="1" then -- and not table.HasValue( _Kyle_Buildmode["buildloadout"], string.Explode(z,"%[[.]+%]", true)[2] )
if y:GetNWBool("_kyle_buildNotify")then
y:SetNWBool("_kyle_buildNotify", true)
y:SendLua("GAMEMODE:AddNotify(\"You cannot pick up weapons while in Build Mode.\",NOTIFY_GENERIC, 5)")
timer.Create( "_kyle_NotifyBuildmode", 5, 1, function()
y:SetNWBool("_kyle_buildNotify", false)
end)
end
PrintTable(string.Split(tostring(z),"["))
PrintTable(string.Split(tostring(z),"%[[.]+%]", true))
return false
end
end)
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 not z.buildmode and not should_revoke then
_kyle_Buildmode_Enable(z)
elseif z.buildmode and should_revoke then
_kyle_Buildmode_Disable(z)
end
table.insert( affected_plys, z )
end
if should_revoke then
ulx.fancyLogAdmin( calling_ply, "#A revoked Buildmode from #T", affected_plys )
else
ulx.fancyLogAdmin( calling_ply, "#A granted Buildmode upon #T", affected_plys )
end
end, "!build" )
buildmode:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional}
buildmode:defaultAccess( ULib.ACCESS_ALL )
buildmode:addParam{ type=ULib.cmds.BoolArg, invisible=true }
buildmode:help( "Grants Buildmode to target(s)." )
buildmode:setOpposite( "ulx pvp", {_, _, true}, "!pvp" )

View File

@ -0,0 +1,82 @@
ULib.ucl.registerAccess( "kylebuildmodesettings", "superadmin", "Allows managing all settings related to Buildmode.", "XGUI" )
_Kyle_Buildmode = {}
util.AddNetworkString( "kylebuildmode_senddata" )
local function Save()
net.Start( "kylebuildmode_senddata", false )
net.WriteTable( _Kyle_Buildmode )
net.Broadcast()
file.Write("kylebuildmode.txt", ULib.makeKeyValues(_Kyle_Buildmode))
end
xgui.addSVModule( "kylebuildmode_load", function()
xgui.addDataType( "_Kyle_Buildmode", function()
net.Start( "kylebuildmode_senddata", false )
net.WriteTable( _Kyle_Buildmode )
net.Broadcast()
end, "kylebuildmodesettings", 0, -10 )
if not file.Exists( "kylebuildmode.txt", "DATA" ) then
_Kyle_Buildmode["restrictweapons"] = 0
_Kyle_Buildmode["allownoclip"] = 0
_Kyle_Buildmode["killonpvp"] = 0
_Kyle_Buildmode["antipropkill"] = 1
_Kyle_Buildmode["spawnwithbuildmode"] = 0
_Kyle_Buildmode["disablepvppropspawn"] = 0
_Kyle_Buildmode["highlightbuilders"] = 0
_Kyle_Buildmode["highlightpvpers"] = 0
_Kyle_Buildmode["buildloadout"] = {"weapon_physgun", "gmod_tool", "gmod_camera"}
_Kyle_Buildmode["highlightbuilderscolor"]= "0,128,255"
_Kyle_Buildmode["highlightpvperscolor"]= "255,0,0"
else
_Kyle_Buildmode = ULib.parseKeyValues( file.Read( "kylebuildmode.txt" ) )
end
ULib.replicatedWritableCvar("kylebuildmode_restrictweapons", "rep_kylebuildmode_restrictweapons", _Kyle_Buildmode["restrictweapons"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_killonpvp", "rep_kylebuildmode_killonpvp", _Kyle_Buildmode["killonpvp"], false,true,"kylebuildmodesettings")
ULib.replicatedWritableCvar("kylebuildmode_spawnwithbuildmode", "rep_kylebuildmode_spawnwithbuildmode", _Kyle_Buildmode["spawnwithbuildmode"], 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")
ULib.replicatedWritableCvar("kylebuildmode_highlightpvpers", "rep_kylebuildmode_highlightpvpers", _Kyle_Buildmode["highlightpvpers"], false,true,"kylebuildmodesettings")
Save()
end )
hook.Add( "PlayerSpawnedProp", "kylebuildmodepropspawn", function( ply, model, ent )
end)
hook.Add( "ULibReplicatedCvarChanged", "kylebuildmodecvar", function( v, w, x, y, z )
local u = string.Split(v, "_")
if(u[1]=="kylebuildmode") then
_Kyle_Buildmode[u[2]] = z
Save()
end
end)
concommand.Add("kylebuildmode", function( x, y, z )
if (x:query( "kylebuildmodesettings" )) then
if z[1]=="addweapon" then
table.insert(_Kyle_Buildmode["buildloadout"], z[2])
elseif z[1]=="removeweapon" then
table.RemoveByValue( _Kyle_Buildmode["buildloadout"], z[2] )
elseif z[1]=="set" then
if z[2] then
if z[3] then
_Kyle_Buildmode[z[2]]=z[3]
else
print (_Kyle_Buildmode[z[2]])
end
else
PrintTable(_Kyle_Buildmode)
return
end
else
print("Invalid Command")
end
Save()
end
end)

View File

@ -0,0 +1,85 @@
_Kyle_Buildmode = _Kyle_Buildmode or {}
xgui.prepareDataType( "_Kyle_Buildmode" )
local b = xlib.makepanel{ parent=xgui.null }
local ba = xlib.makecheckbox{ x=10, y=10, label="Limit weapons to Builder Loadout", parent=b, repconvar="rep_kylebuildmode_restrictweapons"}
local bb = xlib.makepanel{ x=420, y=10, w=150, h=165, parent=b}
local bba = xlib.makelistview{ x=0, y=0, w=150, h=140, parent=bb }
local bbb = xlib.makebutton{x=125, y=140, w=25, h=25, parent=bb, label="+", disabled=true }
local bbc = xlib.maketextbox{x=0, y=140, w=125, h=25, parent=bb}
local bc = xlib.makecheckbox{ x=10, y=30, label="Respawn Player on Buildmode exit", parent=b, repconvar="rep_kylebuildmode_killonpvp"}
local bd = xlib.makecheckbox{ x=10, y=50, label="Players Spawn with Buildmode", parent=b, repconvar="rep_kylebuildmode_spawnwithbuildmode"}
local be = xlib.makelabel{ x=300, y=300, w=500, h=15, parent=b, label="Tell Kyle if you want to see any changes to this addon" }
local bf = xlib.makecheckbox{ x=10, y=70, label="Allow Noclip in Buildmode", parent=b, repconvar="rep_kylebuildmode_allownoclip"}
local bg = xlib.makecheckbox{ x=10, y=90, label="Prevent Propkill in Buildmode -- DO NOT RELY ON THIS", parent=b, repconvar="rep_kylebuildmode_antipropkill"}
local bg = xlib.makecheckbox{ x=10, y=110, label="Highlight Builders", parent=b, repconvar="rep_kylebuildmode_highlightbuilders"}
local bj = xlib.makecheckbox{ x=150, y=110, label="Highlight PVPers", parent=b, repconvar="rep_kylebuildmode_highlightpvpers"}
local bh = xlib.makepanel{ x=10, y=170, w=130, h=150, parent=b}
local bha = xlib.makelabel{ x=1, y=1, w=500, h=15, parent=bh, label="Builder Halo Color" }
local bhb = xlib.makecolorpicker{ x=1, y=15, parent=bh }
local bhc = xlib.makelabel{ x=10, y=150, w=500, h=15, parent=b}
local bi = xlib.makepanel{ x=150, y=170, w=130, h=150, parent=b}
local bia = xlib.makelabel{ x=1, y=1, w=500, h=15, parent=bi, label="PVPer Halo Color" }
local bib = xlib.makecolorpicker{ x=1, y=15, parent=bi }
bba:AddColumn( "Build Loadout" )
bba.OnRowSelected = function(z)
bbb:SetText("-")
bbb.a = false
bbb:SetDisabled(false)
end
bbb.DoClick = function()
if bbb.a then
RunConsoleCommand( "kylebuildmode", "addweapon", bbc:GetValue())
bbc:SetValue("")
else
if bba:GetSelected()[1]:GetColumnText(1) then
RunConsoleCommand( "kylebuildmode", "removeweapon", bba:GetSelected()[1]:GetColumnText(1))
end
end
bbb:SetDisabled(true)
end
bbc.OnEnter = function()
if bbc:GetValue() then
RunConsoleCommand( "kylebuildmode", "addweapon", bbc:GetValue())
bbb:SetDisabled(true)
end
end
bbc.OnChange = function()
bbb:SetText("+")
bbb.a = true
if bbc:GetValue() then
bbb:SetDisabled(false)
else
bbb:SetDisabled(true)
end
end
function bhb:OnChange( z )
z = {z["r"],z["g"],z["b"]}
RunConsoleCommand("kylebuildmode", "set", "highlightbuilderscolor", string.sub(table.ToString(z),2,string.len(table.ToString(z))-2))
end
function bib:OnChange( z )
z = {z["r"],z["g"],z["b"]}
RunConsoleCommand("kylebuildmode", "set", "highlightpvperscolor", string.sub(table.ToString(z),2,string.len(table.ToString(z))-2))
end
net.Receive( "kylebuildmode_senddata", function()
_Kyle_Buildmode = net.ReadTable()
bba:Clear()
for y,z in pairs(_Kyle_Buildmode["buildloadout"]) do
bba:AddLine(z)
end
local z = string.Split( _Kyle_Buildmode["highlightbuilderscolor"],"," )
bhb:SetColor( Color(z[1],z[2],z[3]))
z = string.Split( _Kyle_Buildmode["highlightpvperscolor"],"," )
bib:SetColor( Color(z[1],z[2],z[3]))
end )
xgui.addSettingModule( "Buildmode", b, "icon16/eye.png", "kylebuildmodesettings" )