Jump to content

Get resources commands.


ZeusXBr

Recommended Posts

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 by ZeusXBr
Link to comment
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
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

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
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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...