ZeusXBr Posted June 12, 2021 Share Posted June 12, 2021 (edited) addEventHandler("onResourceStart", resourceRoot, function(res) local resourceName = getResourceName(resourceRoot) local commandsList = {} --table to store commands for _, subtable in pairs( getCommandHandlers() ) do local commandName = subtable[1] local theResource = subtable[2] if not commandsList[theResource] then commandsList[theResource] = {} end table.insert( commandsList[theResource], commandName ) local commands = getCommandHandlers( theResource ) for _, command in pairs( commands ) do commandFound = command if commandFound then outputDebugString("Commands found in "..resourceName..": "..commandFound, 3, 255, 0, 0) end end end end) I'm trying to get all commands found in some resource, i'm trying to use this code, but doesnt works! any kind of help? please? How i want to work: On resource starts > Get Resource Name > Get Resource Commands > return (resName, Commands). Edited June 12, 2021 by ZeusXBr Link to comment
βurak Posted June 12, 2021 Share Posted June 12, 2021 addEventHandler("onResourceStart", resourceRoot, function(res) local commandsList = {} --table to store commands for _, subtable in pairs( getCommandHandlers() ) do local commandName = subtable[1] local theResource = subtable[2] if not commandsList[theResource] then commandsList[theResource] = {} end table.insert( commandsList[theResource], commandName ) local commands = getCommandHandlers( theResource ) for _, command in pairs( commands ) do commandFound = command if commandFound then local resourceName = getResourceName(theResource) outputDebugString("Commands found in "..resourceName..": "..commandFound, 3, 255, 0, 0) end end end end) Link to comment
ZeusXBr Posted June 13, 2021 Author Share Posted June 13, 2021 5 hours ago, Burak5312 said: addEventHandler("onResourceStart", resourceRoot, function(res) local commandsList = {} --table to store commands for _, subtable in pairs( getCommandHandlers() ) do local commandName = subtable[1] local theResource = subtable[2] if not commandsList[theResource] then commandsList[theResource] = {} end table.insert( commandsList[theResource], commandName ) local commands = getCommandHandlers( theResource ) for _, command in pairs( commands ) do commandFound = command if commandFound then local resourceName = getResourceName(theResource) outputDebugString("Commands found in "..resourceName..": "..commandFound, 3, 255, 0, 0) end end end end) Dont works good, i think its better if on "for command in pairs( commands )", its put the commandsfound into a list, and after return at string, do you know how? Link to comment
SpecT Posted June 13, 2021 Share Posted June 13, 2021 If you only want to see them and don't need to store them in a table (for later use) then this should do the job: addEventHandler("onResourceStart", resourceRoot, function(res) -- res = the resource that just started local resourceName = getResourceName(res) local commands = getCommandHandlers(res) -- get all commands from the resource outputChatBox("Commands found in "..resourceName..":", root, 255, 255, 255) for _, command in pairs(commands) do outputChatBox(command, root, 255, 255, 255) end end) Link to comment
ZeusXBr Posted June 13, 2021 Author Share Posted June 13, 2021 13 hours ago, SpecT said: If you only want to see them and don't need to store them in a table (for later use) then this should do the job: addEventHandler("onResourceStart", resourceRoot, function(res) -- res = the resource that just started local resourceName = getResourceName(res) local commands = getCommandHandlers(res) -- get all commands from the resource outputChatBox("Commands found in "..resourceName..":", root, 255, 255, 255) for _, command in pairs(commands) do outputChatBox(command, root, 255, 255, 255) end end) I want to store it, but, ts not working perfect... if python i use this like: test = [''] resourceName = getResourceName(res) for command in resource: test.append(command) print(f'Comand found in {resourceName}: {test}' How i can do this in lua? Link to comment
βurak Posted June 13, 2021 Share Posted June 13, 2021 I'm not sure but you can try this local allCommands = {} addEventHandler("onResourceStart", resourceRoot, function(res) -- res = the resource that just started local resourceName = getResourceName(res) local commands = getCommandHandlers(res) -- get all commands from the resource if not (allCommands[resourceName]) then allCommands[resourceName] = {} end for _, command in pairs(commands) do table.insert(allCommands[resourceName], command) outputDebugString("Comand found in "..resourceName.." : "..command) end end) addCommandHandler("testing",function() end) Link to comment
ZeusXBr Posted June 13, 2021 Author Share Posted June 13, 2021 55 minutes ago, Burak5312 said: I'm not sure but you can try this local allCommands = {} addEventHandler("onResourceStart", resourceRoot, function(res) -- res = the resource that just started local resourceName = getResourceName(res) local commands = getCommandHandlers(res) -- get all commands from the resource if not (allCommands[resourceName]) then allCommands[resourceName] = {} end for _, command in pairs(commands) do table.insert(allCommands[resourceName], command) outputDebugString("Comand found in "..resourceName.." : "..command) end end) addCommandHandler("testing",function() end) Dont works Link to comment
βurak Posted June 13, 2021 Share Posted June 13, 2021 what is not working? i tested it works fine for me Link to comment
ZeusXBr Posted June 14, 2021 Author Share Posted June 14, 2021 1 hour ago, Burak5312 said: what is not working? i tested it works fine for me The code isnt returning nothing. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now