-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsv_commands.lua
93 lines (74 loc) · 2.19 KB
/
sv_commands.lua
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
local isUndroppable = {
weapon_physgun = true,
weapon_physcannon = true,
weapon_none = true,
gmod_tool = true,
gmod_camera = true
}
local commands = {}
commands.drop = {
["!drop"] = true,
["/drop"] = true,
}
commands.dropall = {
["!dropall"] = true,
["/dropall"] = true,
["/strip"] = true,
}
local dropCooldown = 1
local function isOnCooldown( ply )
if not IsValid( ply ) then return true end
if not ply.WeaponDropCooldown then
ply.WeaponDropCooldown = 0
return false
end
if ply.WeaponDropCooldown > CurTime() then
ply:PrintMessage( 4, "You cannot drop your weapon(s) yet!" )
return true
end
ply.WeaponDropCooldown = CurTime() + dropCooldown
end
local function dropPlyWeapon( ply )
if isOnCooldown( ply ) then return end
local currentWeapon = ply:GetActiveWeapon()
if not IsValid( currentWeapon ) or isUndroppable[currentWeapon:GetClass()] then
ply:ChatPrint( "This weapon is unable to be dropped!" )
return
end
ply:DropWeapon( currentWeapon )
currentWeapon.despawn = timer.Simple( 10, function()
if not IsValid( currentWeapon ) then return end
if IsValid( currentWeapon.Owner ) then return end
currentWeapon:Remove()
end )
end
local function dropAllWeapons( ply )
if isOnCooldown( ply ) then return end
pvpMoveSpeed.setSpeedFromWeight( ply, 0 )
for _, weapon in ipairs( ply:GetWeapons() ) do
ply:StripWeapon( weapon:GetClass() )
end
end
local function onPlayerSay( ply, text )
if not IsValid( ply ) then return end
if not ply:Alive() then return end
text = string.lower( text )
if commands.drop[text] then
dropPlyWeapon( ply )
elseif commands.dropall[text] then
dropAllWeapons( ply )
else
return
end
return ""
end
hook.Add( "PlayerSay", "CFC_PlyMS_HandlePlySay", onPlayerSay )
-- Commands
util.AddNetworkString( "dropPlayerWeapon" )
util.AddNetworkString( "dropAllWeapons" )
net.Receive( "dropPlayerWeapon", function( _, ply )
dropPlyWeapon( ply )
end )
net.Receive( "dropAllWeapons", function( _, ply )
dropAllWeapons( ply )
end )