I made a few new classes and I want to add a small addition.. them not being able to drop weapons.
The problem is, I want other classes to drop the same weapons.
I tried adding a new line in config.lua
[lua]GM.Config.restrictclassdrop = true[/lua]
Then adding a function to gamemode_functions.lua
[lua]function GM:CanClassDropWeapon(ply, weapon)
if not IsValid(weapon) then return false end
local class = string.lower(weapon:GetClass())
if self.Config.DisallowClassDrop[class] then return false end
if not GAMEMODE.Config.restrictclassdrop then return true end
for k,v in pairs(CustomShipments) do
if v.entity ~= class then continue end
return true
end
return false
end
function GM:DatabaseInitialized()
FPP.Init()
DarkRP.initDatabase()
end[/lua]
Then making a new lua file in lua/autorun/server
[lua]local function DropWeapon(ply)
local ent = ply:GetActiveWeapon()
if not IsValid(ent) then
GAMEMODE:Notify(ply, 1, 4, DarkRP.getPhrase("cannot_drop_weapon"))
return ""
end
local canDrop = hook.Call("CanClassDropWeapon", GAMEMODE, ply, ent)
local GetPlyTeam = LocalPlayeR().Team()
if GetPlyTeam == TEAM_SNIPER and if not canDrop then
GAMEMODE:Notify(ply, 1, 4, DarkRP.getPhrase("cannot_drop_weapon"))
return ""
end
local RP = RecipientFilter()
RP:AddAllPlayers()
umsg.Start("anim_dropitem", RP)
umsg.Entity(ply)
umsg.End()
ply.anim_DroppingItem = true
timer.Simple(1, function()
if IsValid(ply) and IsValid(ent) and ent:GetModel() then
ply:DropDRPWeapon(ent)
end
end)
return ""
end
AddChatCommand("/drop", DropWeapon)
AddChatCommand("/dropweapon", DropWeapon)
AddChatCommand("/weapondrop", DropWeapon)
[/lua]
Doesn't work still.
What do I do wrong? D:
Pretty new to lua, so excuse me.
Bumping, going to sleep. Hopefully someone can help.
Two options.
A) Update to the refactor branch
B)
[code]
hook.Add("CanDropWeapon", "noSpawnDrop", function(ply, weapon)
if not IsValid(weapon) then return end
local class = weapon:GetClass()
class = string.lower(class)
if RPExtraTeams[ply:Team()] and table.HasValue(RPExtraTeams[ply:Team()].weapons, class) then
return false
end
end)
[/code]
If you mean update to 2.5, no thanks I don't want to do that right now.
Where would this code go, where do I define the teams that cannot drop the weapons and so on?
That code goes in a module. It makes every team unable to drop anything their job is set to spawn with.
Thank you very much, worked.
Getting an error whenever someone types /drop, it works but it displays /drop globally as it was in OOC.
[ERROR] gamemodes/darkrp/gamemode/server/main.lua:77: attempt to call local 'ply' (a userdata value)
1. callback - gamemodes/darkrp/gamemode/server/main.lua:77
2. RP_PlayerChat - gamemodes/darkrp/gamemode/server/chat.lua:35
3. unknown - gamemodes/darkrp/gamemode/server/chat.lua:82
[QUOTE=arcaneex;42168360]Getting an error whenever someone types /drop, it works but it displays /drop globally as it was in OOC.
[ERROR] gamemodes/darkrp/gamemode/server/main.lua:77: attempt to call local 'ply' (a userdata value)
1. callback - gamemodes/darkrp/gamemode/server/main.lua:77
2. RP_PlayerChat - gamemodes/darkrp/gamemode/server/chat.lua:35
3. unknown - gamemodes/darkrp/gamemode/server/chat.lua:82[/QUOTE]
If you dropped it in you darkrp/gamemode/modules folder you should be getting no errors. It works fine for me.
Fuck 2.5.0.
I've put it in darkrp/gamemode/modules/blockweapons.lua, creates the error above.
darkrp/gamemode/modules/blockweapons/blockweapons.lua, doesn't work.
sv_blockweapons.lua
Edit: AND enable it in the config
Same error.
darkrp/gamemode/modules/sv_blockweapons.lua - works with error and global /drop message
darkrp/gamemode/modules/blockweapons/sv_blockweapons.lua - doesn't work at all
[ERROR] gamemodes/darkrp/gamemode/server/main.lua:77: attempt to call local 'ply' (a userdata value)
1. callback - gamemodes/darkrp/gamemode/server/main.lua:77
2. RP_PlayerChat - gamemodes/darkrp/gamemode/server/chat.lua:35
3. unknown - gamemodes/darkrp/gamemode/server/chat.lua:82
Do you have any addons that may be interfering? Past that, I couldn't tell you much, as the code itself seems to function as intended for me.
I'm not sure at all, how can I tell if it's interfering?
Bumping, any help would be appreciated.
Bump.
Bumping.
Did you do a full restart after you added this? If you have remove addons or any core files you have edited one by one until you find the problem.
You can simply go into config.lua and configure what weapons can be dropped.
Line 243:
[CODE]
GM.Config.DisallowDrop = {
["arrest_stick"] = true,
["door_ram"] = true,
["gmod_camera"] = true,
["gmod_tool"] = true,
["keys"] = true,
["lockpick"] = true,
["med_kit"] = true
}
[/CODE]
I have 2.4.3 and it works.
I don't need it to affect all jobs.
And yes I did a full restart.
Sorry, you need to Log In to post a reply to this thread.