summaryrefslogtreecommitdiff
path: root/gamemode/spp/sh_spp.lua
blob: 1c22943c37576138f27e97ea7b7848d54f8ea5e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
AddCSLuaFile( "sh_cppi.lua" )
AddCSLuaFile( "sh_spp.lua" )
AddCSLuaFile( "cl_init.lua" )

SPropProtection = SPropProtection or {}
SPropProtection.Version = 2

CPPI = CPPI or {}
CPPI_NOTIMPLEMENTED = 26
CPPI_DEFER = 16

include( "sh_cppi.lua" )

if ( SERVER ) then
	include( "sv_init.lua" )
else
	include( "cl_init.lua" )
end

/* ----------------------------------------------
	Keep these shared, so client can predict
------------------------------------------------ */

function SPropProtection.PhysGravGunPickup( ply, ent )
	if ( !IsValid( ent ) && ent:GetClass() != "worldspawn") then return end
	if ( ent:GetNWString( "Owner" ) == "World" && ply:IsAdmin() && GetConVarNumber( "spp_admin_wp" ) == 1 ) then return true end
	if ( SPropProtection.PlayerCanTouch( ply, ent ) ) then return true end
end
/*hook.Add( "GravGunPunt", "SPropProtection.GravGunPunt", PhysGravGunPickup )
hook.Add( "GravGunPickupAllowed", "SPropProtection.GravGunPickupAllowed", PhysGravGunPickup )
hook.Add( "PhysgunPickup", "SPropProtection.PhysgunPickup", PhysGravGunPickup )
hook.Add( "CanTool", "SPropProtection.CanTool", PhysGravGunPickup )*/

/* ----------------------------------------------
	SPP Console Variables
------------------------------------------------ */

if ( SPPCVars ) then return end -- Auto-Refresh protection

SPPCVars = {}

function CreateSPPCVar( name, def )
	if ( SERVER ) then

		table.insert( SPPCVars, "spp_" .. name )
		CreateConVar( "spp_" .. name, def, FCVAR_ARCHIVE )

		cvars.AddChangeCallback( "spp_" .. name, function( cvar, old, new )

			if ( math.floor( old ) == math.floor( new ) ) then return end
			for id, pl in pairs( player.GetAll() ) do pl:ConCommand( "spp_" .. name .. " " .. math.floor( new ) ) end

		end )

	else

		CreateConVar( "spp_" .. name, def )
		cvars.AddChangeCallback( "spp_" .. name, function( cvar, old, new )

			if ( math.floor( old ) == math.floor( new ) ) then return end
			timer.Destroy( "spp_update" .. name )
			timer.Create("spp_update" .. name, 2, 1, function() RunConsoleCommand( "spp_update", name, math.floor( new ) ) end )

		end )

	end
end

CreateSPPCVar( "enabled", "1" )
CreateSPPCVar( "admin", "0" )
CreateSPPCVar( "admin_wp", "0" )
CreateSPPCVar( "use", "1" )
CreateSPPCVar( "entdmg", "1" )
CreateSPPCVar( "del_disconnected", "1" )
CreateSPPCVar( "del_adminprops", "1" )
CreateSPPCVar( "del_delay", "120" )

if ( CLIENT ) then return end

concommand.Add( "spp_update", function( ply, cmd, args )

	if ( !ply:IsAdmin() ) then return end

	local cmd = args[ 1 ]
	local val = args[ 2 ]

	if ( math.floor( GetConVarNumber( "spp_" .. cmd ) ) == math.floor( val ) ) then return end

	RunConsoleCommand( "spp_" .. cmd, math.floor( val ) )

end )

hook.Add( "PlayerInitialSpawn", "spp.sync_cvars", function( ply )
	for id, cvar in pairs( SPPCVars ) do ply:ConCommand( cvar .. " " .. math.floor( GetConVarNumber( cvar ) ) ) end
end )