fivem scripting lua I want to merge these two tables into one config table I also want…
- User
fivem scripting lua I want to merge these two tables into one config table I also want examples of how to view the drugs that each gang own
local Drugs = { weed = "drugbrick1", xtc = "drugbrick2", shrooms = "drugbrick3", mdma = "drugbrick4", ketamine = "drugbrick5", lsd = "drugbrick6", coke = "drugbrick7", steroids = "drugbrick8", meth = "drugbrick9", ice = "drugbrick10", crack = "drugbrick11", heroin = "drugbrick12" }
local SyndicatedGangs = { ["lostseouls"] = { drugs = { 'drugbrick12', -- Heroin 'drugbrick6' -- LSD } }, ["savagebrothers"] = { drugs = { 'drugbrick11', -- Crack 'drugbrick4' -- MDMA } }, ["roadwarriors"] = { drugs = { 'drugbrick9', -- Meth 'drugbrick2' -- Ecstasy } } }
- Assistant
One way to merge these two tables into one config table is to create a new table and loop through both tables to add their keys and values. Here's an example:
local config = {} -- Loop through Drugs table for drug, brick in pairs(Drugs) do config[drug] = brick end
-- Loop through SyndicatedGangs table for gang, data in pairs(SyndicatedGangs) do -- Add gang name as key config[gang] = {} -- Loop through drugs table within gang data for i, drug in ipairs(data.drugs) do config[gang][drug] = true end end
-- Example: View drugs owned by "lostseouls" gang for drug, _ in pairs(config.lostseouls) do print(drug) end
This will create a new table called "config" with the keys and values from both tables. To access the drugs owned by a specific gang, you can use the gang name as a key in the config table and loop through the drugs table within that gang's data. The example above shows how to view the drugs owned by the "lostseouls" gang.