is there a way for me when i create a swep to pool all the models used in DarkRP jobs.lua, similar to what the f4 menu does with its preview of jobs i want something to pull its data from the assigned models and create a table.
This is for a disguise swep and id rather it be automatic, then setting up a config to do it manually.]
Any help is appreciated.
[code]
local Models = {"model/model1.mdl", "model/model2.mdl"}
for k, v in pairs(Models) do
--whatever you want to do
end
[/code]
?
[QUOTE=Tomvdr;45657125][code]
local Models = {"model/model1.mdl", "model/model2.mdl"}
for k, v in pairs(Models) do
--whatever you want to do
end
[/code]
?[/QUOTE]
I was hoping not to do it manually that way :/
[QUOTE=helplesskitty;45657225]I was hoping not to do it manually that way :/[/QUOTE]
write a script to get all models from the file and add to table.
[lua]
local ModelsList = {}
for k,v in ipairs(RPExtraTeams) do
if v.model and istable(v.model) then
for k2,v2 in ipairs(v.model) do
table.insert(ModelsList,v2)
end
elseif v.model and isstring(v.model) then
table.insert(ModelsList,v.model)
end
end
PrintTable(ModelsList)
[/lua]
Will print every job model.
[QUOTE=Jarva;45657318][lua]
local ModelsList = {}
for k,v in ipairs(RPExtraTeams) do
if v.model and istable(v.model) then
for k2,v2 in ipairs(v.model) do
table.insert(ModelsList,v2)
end
elseif v.model and isstring(v.model) then
table.insert(ModelsList,v.model)
end
end
PrintTable(ModelsList)
[/lua]
Will print every job model.[/QUOTE]
I will try this thank you very much!
[QUOTE=Jarva;45657318][lua]
local ModelsList = {}
for k,v in ipairs(RPExtraTeams) do
if v.model and istable(v.model) then
for k2,v2 in ipairs(v.model) do
table.insert(ModelsList,v2)
end
elseif v.model and isstring(v.model) then
table.insert(ModelsList,v.model)
end
end
PrintTable(ModelsList)
[/lua]
Will print every job model.[/QUOTE]
god damit, just wasted my time writing this
[code]
local addonJobs = string.Explode( "\n", file.Read("darkrp_customthings/jobs.lua", "LUA") )
local coreJobs = string.Explode( "\n", file.Read("gamemodes/darkrp/gamemode/config/jobrelated.lua", "MOD") )
function ReturnModels( stringTbl )
local models = {}
for k,v in pairs(stringTbl) do
if v:find( "models/" ) then
v = v:Replace( "model =", "" )
v = v:Replace( "{", "" )
v = v:Replace( "}", "" )
v = v:Replace( "\"", "" )
v = v:Replace( ",", "" )
v = v:Trim()
models[#models + 1] = v
end
end
return models
end
addonJobs = ReturnModels( addonJobs )
coreJobs = ReturnModels( coreJobs )
local allModels = coreJobs
for k,v in pairs(addonJobs) do
allModels[#allModels + 1] = v
end
addonJobs = nil
coreJobs = nil
PrintTable(allModels)
[/code]
[sp] What is gsub [/sp]
Slightly off-topic but I saw this in the ticker and I thought you meant this kind of table
[t]http://www.ikea.com/PIAimages/20315_PE105482_S5.JPG[/t]
v:v:v
[QUOTE=Coyoteze;45657451]Slightly off-topic but I saw this in the ticker and I thought you meant this kind of table
[t]http://www.ikea.com/PIAimages/20315_PE105482_S5.JPG[/t]
v:v:v[/QUOTE]
I was about to post a blueprint of a wooden table goddamnit you
Well what you could try is printing the v values of the table
instead of printing the table itself ; D
How...... (never used tables)
I did some research as to how DarkRP works and came up with this for you.
[lua]
//RPTeamModels[job] = {"modelPath1", "modelPath2"}
local RPTeamModels = {}
for k,v in pairs(RPExtraTeams) do
local mdl = v.model
RPTeamModels[k] = istable(mdl) and mdl or {mdl}
end
[/lua]
Thankyou.
now how would i get that to display in a DListView or as buttons/panels/icons.
To pull the v data from the table?
Loop through the RPTeamModels table and add it to the list view
[QUOTE=crazyscouter;45685606]Loop through the RPTeamModels table and add it to the list view[/QUOTE]
Loops and tables, arent really my area with Lua (im more GUI and effects), so i actually have no idea how to use loops or tables, or their functionality, everywhere ive read hasnt really helped either....
But uh, iterations and tables are fundamental to lua. GUI or not.
[url]http://www.lua.org/pil/7.html[/url] <-- Six pages or so on iteration
Well, you should just read all of the chapters there. :)
Sorry, you need to Log In to post a reply to this thread.