1. Sign up for news, events and more!

    You're currently visiting the official DarkRP Forums as a guest. Sign up now to participate in our community and we'll let you know when we have news.

Shipment WhiteList

Discussion in 'DarkRP Modding Questions & Help' started by [LB] GravityWolf, Jan 1, 2018.

  1. [LB] GravityWolf

    [LB] GravityWolf New Member

    I am trying to make a whitelist for shipments; I am doing this because I do not wish to have all of my weapons on the server accessible by the Armory. My original idea was to create a new variable for shipments named IsWhiteListed, and run a check for if it is or isn't. After which it would add to a new table (away from CustomShipments) and use that table in order to feed my armory.

    Added to line 546 of sh_createitems.lua

    if customShipment.IsWhiteListed then
    shipByName[string.lower(name or "")] = table.insert(WhiteListedShipments, customShipment)
    shipByName[string.lower(name or "")] = table.insert(CustomShipments, customShipment)
    else
    shipByName[string.lower(name or "")] = table.insert(CustomShipments, customShipment)
    end


    Added to 511 of sh_createitems.lua

    local customShipment = tableSyntaxUsed and model or {model = model, entity = entity, price = price, amount = Amount_of_guns_in_one_shipment, seperate = Sold_separately, pricesep = price_separately, noship = noshipment, allowed = classes, shipmodel = shipmentmodel, customCheck = CustomCheck, weight = 5, whitelist = IsWhiteListed}


    I feel like there is a simple way of doing this and I am just over thinking x.x Plus, this syntax is killing me.
    --- Double Post Merged, Jan 1, 2018 ---
    [ERROR] gamemodes/sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/custom.lua:191: attempt to call field 'GetCustomPropTable' (a nil value)
    1. v - gamemodes/sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/custom.lua:191
    2. Call - lua/includes/modules/hook.lua:84
    3. CallPopulateHook - gamemodes/sandbox/gamemode/spawnmenu/creationmenu/content/content.lua:49
    4. Function - gamemodes/sandbox/gamemode/spawnmenu/creationmenu/content/content.lua:80
    5. unknown - gamemodes/sandbox/gamemode/spawnmenu/creationmenu.lua:38
     
  2. oh hey gravity.
     
  3. (FPtje) Atheos

    (FPtje) Atheos Main Developer Staff Member

  4. [LB] GravityWolf

    [LB] GravityWolf New Member

    I am already aware of that...I also asked if there was a way to do this. I don't want to edit the core files, but that is all I could think of. Any help would be greatly appricated. Could I achive this in the custom check for shipments?
     
  5. (FPtje) Atheos

    (FPtje) Atheos Main Developer Staff Member

    Depends on what your whitelist is supposed to be a whitelist for. Do you mean to prevent people from buying the shipment? Then yes, you can use the customCheck.
     
  6. [LB] GravityWolf

    [LB] GravityWolf New Member

    We have an Armory Add-on, the script takes random shipments from the custom shipments table and when that function is called it spawns a bunch of random shipments around the armory when the raid timer runs out. I would like to create a white list that will take the place of the original table in the script. This will allow us to choose what shipments spawn when the raid timer goes out instead of having random possibilities of all of the possible shipments.


    local foundKey
    for k,v in pairs(CustomShipments) do
    foundKey = math.random(table.Count(CustomShipments))
    end
    --- Double Post Merged, Jan 2, 2018 ---
    Thank you for your time.
    --- Double Post Merged, Jan 2, 2018 ---
    This is the only reason I messed with core files. I know you all do NOT want people to mess with core game mode files, but I had not other idea of a way to create such a thing...
     
  7. (FPtje) Atheos

    (FPtje) Atheos Main Developer Staff Member

    You can add arbitrary fields to your shipments. So in your shipments.lua in the darkrpmod you can just add a field, say
    Code (Text):
     armorySpawnable = true,
    Like under the cmd, under the customCheck or whatever, just somewhere in the shipment's definition. Then in the armory code, you can change the bit where it picks a random shipment to something that first checks which shipments are whitelisted (by checking whether the armorySpawnable field is set to true), and then picks a random shipment from there.
    --- Double Post Merged, Jan 2, 2018 ---
    Here's an example shipment with the added field:

    Code (Text):

    DarkRP.createShipment("AK47", {
        model = "models/weapons/w_rif_ak47.mdl",
        entity = "weapon_ak472",
        price = 2450,
        amount = 10,
        separate = false,
        pricesep = nil,
        armorySpawnable = true,
        noship = false,
        allowed = {TEAM_GUN},
        category = "Rifles",
    })
    The shipment finding code in the armory would then look like this:
    Code (Text):

    local whitelisted = {} -- Table that will contain all whitelisted shipments
    -- Find all whitelisted shipments and put them in the whitelisted table
    for k, v in pairs(CustomShipments) do
        if v.armorySpawnable then table.insert(whitelisted, v) end
    end
    -- Random key of table (similar to value of foundKey in previous code)
    local randomWhitelistedShipmentKey = math.random(1, #whitelisted)
    -- The found shipment entry:
    local randomWhitelistedShipment = whitelisted[randomWhitelistedShipmentKey]
     
    Untested!
     
    Last edited: Jan 2, 2018

Share This Page