• DarkRP Weapon Restricting
    16 replies, posted
I am currently trying to fix a problem that my Darkrp server is having. Whenever someone drops a crowbar, it drops the view model instead of the world model and it cannot be removed in any way. I cannot seem to fix the problem in any other way so I figured the best course of action would be to restrict being able to drop the crowbar completely. I found the bit of code that says which weapons cannot be dropped and the way it works is that if the weapon can be bought via shipments then you can drop it. I would like to add an additional if statement to check if the weapon attempting to be dropped is a crowbar but I'm not very good at LUA syntax. Here's the code: [code]if GetConVarNumber("RestrictDrop") == 1 then local found = false for k,v in pairs(CustomShipments) do if v.entity == ent:GetClass() then found = true break end end if not found then Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon) return "" end end[/code] I was planning on adding "if v.entity == "weapon_crowbar" then break" or something like that after the loop starts, but I don't know the proper syntax. Could someone please help me?
Im a noob at lua also and just to experiment I would copy and paste that code below it and then replace with the crowbar thing you were talking about but that might make it worse but who cares you can delete the code if it does
[QUOTE=Warstories;23985352]Im a noob at lua also and just to experiment I would copy and paste that code below it and then replace with the crowbar thing you were talking about but that might make it worse but who cares you can delete the code if it does[/QUOTE] I attempted to add my addition into the original code and now no weapons can be dropped.
[QUOTE=Zwolf11;23979188]I am currently trying to fix a problem that my Darkrp server is having. Whenever someone drops a crowbar, it drops the view model instead of the world model and it cannot be removed in any way. I cannot seem to fix the problem in any other way so I figured the best course of action would be to restrict being able to drop the crowbar completely. I found the bit of code that says which weapons cannot be dropped and the way it works is that if the weapon can be bought via shipments then you can drop it. I would like to add an additional if statement to check if the weapon attempting to be dropped is a crowbar but I'm not very good at LUA syntax. Here's the code: [code]if GetConVarNumber("RestrictDrop") == 1 then local found = false for k,v in pairs(CustomShipments) do if v.entity == ent:GetClass() then found = true break end end if not found then Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon) return "" end end[/code] I was planning on adding "if v.entity == "weapon_crowbar" then break" or something like that after the loop starts, but I don't know the proper syntax. Could someone please help me?[/QUOTE] This is a long shot, as I mainly do Roblox Lua instead of Gmod Lua nowadays, but... try this. if ply:GetActiveWeapon() == "Crowbar" then return end --[[ If that's the name of the SWEP. ]] Put that where the drop function is, and it will not drop the crowbar... hopefully. Tell me your result.
I tried to add 4 sets of code using the ply:GetActiveWeapon() function and none of them worked. I tried: [code]if ply:GetActiveWeapon() == "weapon_crowbar" then break end[/code] [code]if ply:GetActiveWeapon() == "weapon_crowbar" then return end[/code] [code]if ply:GetActiveWeapon() == "CROWBAR" then break end[/code] [code]if ply:GetActiveWeapon() == "CROWBAR" then return end[/code] After using all these codes I could still drop the crowbar sadly. Thanks for trying anyway.
help would still be appreciated.
Could you post the entire function? I think I might know how to fix your problem, but I need the full function to confirm it.
I was looking through the entire function when I realized that there was a built in blacklist for weapon drops right above what I posted. (I know I can't believe I looked right past that) But after realizing this I put "weapon_crowbar" into the blacklist and I was still able to drop the crowbar. Then I thought that it might just be a problem with the crowbar itself so I tried changing it to "weapon_real_cs_glock18" (my server uses cs realistic weapons) and it still let me drop that, so I'm thinking it's a problem with the blacklist. Anyway, here's the whole section on dropping weapons. [code]/*--------------------------------------------------------- Shipments ---------------------------------------------------------*/ local NoDrop = {} -- Drop blacklist local function DropWeapon(ply) local ent = ply:GetActiveWeapon() if not ValidEntity(ent) then return "" end if GetConVarNumber("RestrictDrop") == 1 then local found = false for k,v in pairs(CustomShipments) do if ply:GetActiveWeapon() == "CROWBAR" then return end if v.entity == ent:GetClass() then found = true break end end if not found then Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon) return "" end end if table.HasValue(NoDrop, ent:GetClass()) then 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(ply, ent) if ValidEntity(ply) and ValidEntity(ent) and ent:GetModel() then ply:DropWeapon(ent) -- drop it so the model isn't the viewmodel local weapon = ents.Create("spawned_weapon") local model = (ent:GetModel() == "models/weapons/v_physcannon.mdl" and "models/weapons/w_physics.mdl") or ent:GetModel() weapon.ShareGravgun = true weapon:SetPos(ply:GetShootPos() + ply:GetAimVector() * 30) weapon:SetModel(model) weapon:SetSkin(ent:GetSkin()) weapon.weaponclass = ent:GetClass() weapon.nodupe = true weapon:Spawn() ent:Remove() end end, ply, ent) return "" end AddChatCommand("/drop", DropWeapon) AddChatCommand("/dropweapon", DropWeapon) AddChatCommand("/weapondrop", DropWeapon)[/code]
When you are trying to drop the crowbar, are you using the chat commannd or the built in shortcut key in gmod? If you are using the chat command, try to replace the return in the code you added with return false
[QUOTE=c0baltha1l;24105561]When you are trying to drop the crowbar, are you using the chat commannd or the built in shortcut key in gmod? If you are using the chat command, try to replace the return in the code you added with return false[/QUOTE] man, it didn't work :(. I could still drop the crowbar. Here's what I changed the code to: [code]if GetConVarNumber("RestrictDrop") == 1 then local found = false for k,v in pairs(CustomShipments) do if ply:GetActiveWeapon() == "weapon_crowbar" then return false end if v.entity == ent:GetClass() then found = true break end end if not found then Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon) return "" end end[/code]
Ok, lets try this. It involves editing this part: [lua] umsg.Start("anim_dropitem", RP) umsg.Entity(ply) umsg.End() ply.anim_DroppingItem = true timer.Simple(1, function(ply, ent) if ValidEntity(ply) and ValidEntity(ent) and ent:GetModel() then ply:DropWeapon(ent) -- drop it so the model isn't the viewmodel local weapon = ents.Create("spawned_weapon") local model = (ent:GetModel() == "models/weapons/v_physcannon.mdl" and "models/weapons/w_physics.mdl") or ent:GetModel() weapon.ShareGravgun = true weapon:SetPos(ply:GetShootPos() + ply:GetAimVector() * 30) weapon:SetModel(model) weapon:SetSkin(ent:GetSkin()) weapon.weaponclass = ent:GetClass() weapon.nodupe = true weapon:Spawn() ent:Remove() end end, ply, ent) [/lua] Change it to: [lua] if ent:GetClass() == "weapon_crowbar" then return else umsg.Start("anim_dropitem", RP) umsg.Entity(ply) umsg.End() ply.anim_DroppingItem = true timer.Simple(1, function(ply, ent) if ValidEntity(ply) and ValidEntity(ent) and ent:GetModel() then ply:DropWeapon(ent) -- drop it so the model isn't the viewmodel local weapon = ents.Create("spawned_weapon") local model = (ent:GetModel() == "models/weapons/v_physcannon.mdl" and "models/weapons/w_physics.mdl") or ent:GetModel() weapon.ShareGravgun = true weapon:SetPos(ply:GetShootPos() + ply:GetAimVector() * 30) weapon:SetModel(model) weapon:SetSkin(ent:GetSkin()) weapon.weaponclass = ent:GetClass() weapon.nodupe = true weapon:Spawn() ent:Remove() end end, ply, ent) end [/lua] I looked at the function more closely, and found that this is the part where it does the actual dropping. Now it should check to see if the weapon is a weapon_crowbar and if it is, do not drop the weapon.
Hey it worked...kinda haha. When I type /drop or go to drop current weapon in the f4 menu, it won't let me drop it but the chat says that I said an empty string. I doesn't say that I can't drop the weapon like all the other ones. So, thanks! It should work fine for my needs. I have nothing to offer but my love, so have a heart.
No problem. If you really want it to notify you, put this line of code the line above the 'return' in the second block of code on the third line: [code]Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon)[/code]
[QUOTE=c0baltha1l;24121030]No problem. If you really want it to notify you, put this line of code the line above the 'return' in the second block of code on the third line: [code]Notify(ply, 1, 4, LANGUAGE.cannot_drop_weapon)[/code][/QUOTE] Awesome, once again thank you very much.
No problem, I'm here to help
Could you please send the ready code that would prohibit arms drop
[QUOTE=mj2009;39698807]Could you please send the ready code that would prohibit arms drop[/QUOTE] Omg, don't bump these old threads.
Sorry, you need to Log In to post a reply to this thread.