HOOK_PLUGINS_LOADED and Aliases
#1
[strike]Is HOOK_PLUGINS_LOADED called both when all plugins are loaded during initial startup AND when there are plugins loaded later on by command, or only during the former time?[/strike]

If it is only triggered after initial loading, what is the best way to get other plugins to realize that an API plugin has loaded if it doesn't load at startup? I'm thinking that the API plugin will loop through all plugins when it is initialized and execute a specifically named function on all of them, but that seems like it might be glitchy.

Edit: I just checked, and it is only triggered after initial loading, or reloads. Using load and unload from the console doesn't trigger it.

So, in that case. A function that gets called every few ticks could work. It would initially be called during load, then it would be called using cWorld:ScheduleTask() from within itself. In my attempts to test where to go from here, I kept encountering errors.

Code:
[spoiler]
function Initialize(Plugin)
	Plugin:SetName( "HookLoadedTest" )
	Plugin:SetVersion( 15 )

	cPluginManager:AddHook(cPluginManager.HOOK_PLUGINS_LOADED,OnPluginsLoaded)

	LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
  cRoot:Get():GetPluginManager():BindConsoleCommand("doallplugins",doAllPlugins,"")

	return true
end

function OnDisable()
	LOG( "Disabled Core!" )
end

function OnPluginsLoaded()
  LOG("Plugins loaded!asdfasdrfqwerasdfqwer")
end

function doAllPlugins(split)
  local PLMan = cRoot:Get():GetPluginManager()
  PLMan:ForEachPlugin(function(plugin)
      PLMan:CallPlugin(plugin:GetName(),mySpecialFunction)
    end
  )
end
[/spoiler]
Error:
[spoiler]
Code:
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[21:03:28] LUA: Plugins/HookLoadedTest/main.lua:24: error in function 'CallPlugin'.
     argument #1 is 'cPluginManager'; 'cPluginManager' expected.

[21:03:28] Stack trace:
[21:03:28]   [C](-1): CallPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(24): (no name)
[21:03:28]   [C](-1): ForEachPlugin
[21:03:28]   Plugins/HookLoadedTest/main.lua(23): (no name)
[21:03:28] Stack trace end
[21:03:28] Error in <attached> calling function <callback>()
[/spoiler]
Attempted with and without :GetName() and using the full cRoot:Get... instead of PLMan. So explanation of what I've done wrong would be great.


Now onto command Aliases (as defined in Info.lua). I know that things go wrong if two plugins share the same base name for a function (like both using /ext). What about if Plugin A registers their command as "/command1" but Plugin B registers it as "/asdfasdfcommand1" with alias "/command1"? Are aliases handled differently then names, or are they all stored in the same way?
Reply
Thanks given by:


Messages In This Thread
HOOK_PLUGINS_LOADED and Aliases - by Zee1234 - 12-03-2015, 12:30 PM
RE: HOOK_PLUGINS_LOADED and Aliases - by Zee1234 - 12-03-2015, 04:25 PM
RE: HOOK_PLUGINS_LOADED and Aliases - by NiLSPACE - 12-03-2015, 05:29 PM
RE: HOOK_PLUGINS_LOADED and Aliases - by Zee1234 - 12-03-2015, 05:58 PM
RE: HOOK_PLUGINS_LOADED and Aliases - by xoft - 12-03-2015, 06:08 PM
RE: HOOK_PLUGINS_LOADED and Aliases - by Zee1234 - 12-03-2015, 06:18 PM



Users browsing this thread: 1 Guest(s)