My favorites | Sign in
Project Home Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 258 attachment: sv_restriction.lua (4.0 KB)

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*-------------------------------------------------------------------------------------------------------------------------
Restriction
-------------------------------------------------------------------------------------------------------------------------*/

local PLUGIN = {}
PLUGIN.Title = "Restriction"
PLUGIN.Description = "Restricts weapons."
PLUGIN.Author = "Overv"

function PLUGIN:PlayerSpawnSWEP( ply, name, tbl )
if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "@" .. name ) and !ply:EV_HasPrivilege( "@" .. name ) ) then
evolve:Notify( ply, evolve.colors.red, "You are not allowed to spawn this weapon!" )
return false
end
end
function PLUGIN:PlayerGiveSWEP( ply, name, tbl )
if ( self:PlayerSpawnSWEP( ply, name, tbl ) == false ) then
return false
end
end

function PLUGIN:PlayerSpawnSENT( ply, class )
if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, ":" .. class ) and !ply:EV_HasPrivilege( ":" .. class ) ) then
evolve:Notify( ply, evolve.colors.red, "You are not allowed to spawn this entity!" )
return false
end
end

function PLUGIN:CanTool( ply, tr, class )
if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "#" .. class ) and !ply:EV_HasPrivilege( "#" .. class ) ) then
evolve:Notify( ply, evolve.colors.red, "You are not allowed to use this tool!" )
return false
end
end

function PLUGIN:PlayerSpawn( ply )
// Only block picking up when a player spawns, because we still want to make it possible to use !give and allow admins to drop weapons for players!
ply.EV_PickupTimeout = CurTime() + 0.5
end

function PLUGIN:PlayerCanPickupWeapon( ply, wep )
if ( GAMEMODE.Name == "Sandbox" and table.HasValue( evolve.privileges, "@" .. wep:GetClass() ) and !ply:EV_HasPrivilege( "@" .. wep:GetClass() ) and ( !ply.EV_PickupTimeout or CurTime() < ply.EV_PickupTimeout ) ) then
return false
end
end

function PLUGIN:Initialize()
// Weapons
local weps = {}

for _, wep in pairs( weapons.GetList() ) do
table.insert( weps, "@" .. wep.ClassName )
end

table.Add( weps, {
"@weapon_crowbar",
"@weapon_pistol",
"@weapon_smg1",
"@weapon_frag",
"@weapon_physcannon",
"@weapon_crossbow",
"@weapon_shotgun",
"@weapon_357",
"@weapon_rpg",
"@weapon_ar2",
"@weapon_physgun",
} )

table.Add( evolve.privileges, weps )

// Entities
local entities = {}

for class, ent in pairs( scripted_ents.GetList() ) do
if ( ent.t.Spawnable or ent.t.AdminSpawnable ) then
table.insert( entities, ":" .. ( ent.ClassName or class ) )
end
end

table.Add( evolve.privileges, entities )

// Tools
local tools = {}

if ( GAMEMODE.Name == "Sandbox" ) then
for _, val in ipairs( file.FindInLua( "weapons/gmod_tool/stools/*.lua" ) ) do
local _, __, class = string.find( val, "([%w_]*)\.lua" )
table.insert( tools, "#" .. class )
end
end

table.Add( evolve.privileges, tools )

// If this is the first time the restriction plugin runs, add all weapon and entity privileges to all ranks so it doesn't break anything
if ( !evolve:GetGlobalVar( "RestrictionSetUp", false ) ) then
for id, rank in pairs( evolve.ranks ) do
if ( id != "owner" ) then
table.Add( rank.Privileges, weps )
end
end

evolve:SetGlobalVar( "RestrictionSetUp", true )
evolve:SaveRanks()
end

if ( !evolve:GetGlobalVar( "RestrictionSetUpEnts", false ) ) then
for id, rank in pairs( evolve.ranks ) do
if ( id != "owner" ) then
table.Add( rank.Privileges, entities )
end
end

evolve:SetGlobalVar( "RestrictionSetUpEnts", true )
evolve:SaveRanks()
end

if ( !evolve:GetGlobalVar( "RestrictionSetUpTools2", false ) ) then
for id, rank in pairs( evolve.ranks ) do
if ( id != "owner" ) then
table.Add( rank.Privileges, tools )
end
end

evolve:SetGlobalVar( "RestrictionSetUpTools2", true )
evolve:SaveRanks()
end
end

evolve:RegisterPlugin( PLUGIN )
Powered by Google Project Hosting