• DarkRP| Need help for custom shipment options
    5 replies, posted
Hi, Thank to anyone who's taking his time to read this, I am making a DarkRP server and I was wondering if there was a way to make some weapons only available to a certain rank. I've had many ideas to restrict the weapons to only a certain rank, but I'm not sure how to make it work properly: I've made the VIP weapons [B]un-droppable[/B] with the "settings.lua", what I need now is a way for players to [B]get the items directly[/B]. (F4) I can't find any [B]custom field[/B] (for shipments) and I don't know how to make a [B]function[/B] and so I do not know how to make it so a weapon you buy from the F4 menu [B]equip directly to the player[/B] instead of dropping on the floor, where everyone can pick it up. What could also work: The items will drop on the floor, but no one except a certain rank would be able to pick them up, which I do not know if it is possible. Again, thank you only for reading this, if you can help, i'll really appreaciate it. If you need any information to help me, please leave a reply, thank you! Here is an example of the code in "shipments.lua" [CODE]DarkRP.createShipment("Butterfly Knife | Fade", { model = "models/weapons/w_csgo_butterfly.mdl", entity = "csgo_butterfly_fade", price = 12600, amount = 1, seperate = false, seperate = true, pricesep = 12600, noship = true, category = "VIP Butterfly Knives", customCheck = function(ply) return ply:IsUserGroup("Donator") end })[/CODE] P.S.: Sorry for bad english :L
You could use [url]https://wiki.garrysmod.com/page/GM/AllowPlayerPickup[/url] and check if the player is a donator and the entity is that of what you want and then depending on if its okay then allow/disallow it If you don't feel like coding it or if you dont know lua or something just pop this script into lua/autorun/server/donatoritemcheck.lua [CODE] local weaponsToCheck = { --["weapon_pistol"] = true, -- Just add more lines like this one the one in the brackets is the weapon classname --["weapon_smg1"] = true, ["csgo_butterfly_fade"] = true, } local function checkPickup(ply, ent) if ent:IsValid() and ent:IsWeapon() then if weaponsToCheck[ent:GetClass()] and not ply:GetNWString('usergroup') == 'Donator' then return false end end end hook.Add("AllowPlayerPickup", "donatoritemcheckpickup", checkPickup) [/CODE] If something is broken, or if you wished that I explain what I did just ask me here or add me on steam :) If you'd rather do the straight into the player's equipped items thing, there is a custom field called onBought: [CODE] onBought = function(ply, shipment, ent) end, -- function that is called when the shipment is bought [/CODE] and you can do something like this, although I'm not sure that it'd work. Put this at the top of your file: [CODE] local function buycheckthingy(ply, ship, ent) local wclass = ent:GetClass() if wclass ~= "spawned_shipment" then ent:Remove() if ply:GetNWString('usergroup') == 'Donator' then ply:Give(wclass) end end end [/CODE] and then do this to every shipment you want to affect with what you want to do like this: [CODE] DarkRP.createShipment("Butterfly Knife | Fade", { model = "models/weapons/w_csgo_butterfly.mdl", entity = "csgo_butterfly_fade", price = 12600, amount = 1, seperate = false, seperate = true, pricesep = 12600, noship = true, category = "VIP Butterfly Knives", onBought = buycheckthingy, -- THIS IS MY CHANGE! customCheck = function(ply) return ply:IsUserGroup("Donator") end }) [/CODE] I hope it works! Tell me if I did anything stupid.
Thank you for the reply! Since I would love to have players not to pick up the weapon (equip it right after buy), I've gone with option 2. Also since I almost absolutely do not know what I'm doing when it comes to lua, please don't take my word for some of the explainations that are coming up. Sadly some things didn't work. When I tried to buy the weapon, here's what happend: The weapon didn't equip (The Give function didn't output any errors but neither worked). And when it comes to the "spawned_shipment", it didn't spawn in the certain weapon model/entity but instead spawned the CSS AK_47 model (when I tried to click on it with "e", nothing happend). [URL="http://i.imgur.com/JIYnEK9.jpg"]Screenshot [/URL](The weapon is supposed to be in slot 3). Here's my currently used shipment code format: [CODE] -- At the start local function buycheckthingy(ply, ship, ent) local wclass = ent:GetClass() if wclass ~= "spawned_shipment" then ent:Remove() if ply:GetNWString('usergroup') == 'donator' then ply:Give(wclass) end end end -- Further down DarkRP.createShipment("Bayonet Knife", { model = "models/weapons/w_csgo_bayonet.mdl", entity = "csgo_bayonet", price = 12600, amount = 1, seperate = false, seperate = true, pricesep = 12600, noship = true, category = "VIP Bayonet Knives", onBought = buycheckthingy, -- THIS IS YOUR CHANGE! customCheck = function(ply) return ply:IsUserGroup("donator") end }) [/CODE] Again, thank you for the reply! If you need anything, feel free to ask!
Ok, try doing this, tell me what it outputs [CODE] local function buycheckthingy(ply, ship, ent) local wclass = ent:GetClass() print( wclass ) -- I'm printing the class name here, tell me what it outputs. if wclass ~= "spawned_shipment" then ent:Remove() if ply:GetNWString('usergroup') == 'Donator' then ply:Give(wclass) end end end [/CODE] feel free to also add me on steam, look under my profile picture. there is a steam button there.
Added you on steam! Also, it outputs spawned_weapon. I tried to change "spawned_shipment" to "spawned_weapon" and it started dropping the knife. Thank you for your help! Edit: When I changed the ~= to == using "spawned_weapon", the css ak model appeared again.
Can nobody read nowadays? [IMG]http://i.imgur.com/9Lwx7au.png[/IMG] [IMG]http://i.imgur.com/VurhoB3.png[/IMG]
Sorry, you need to Log In to post a reply to this thread.