As of rev945 I added the functionality needed to call functions on another plugin.
Even though this opens possibilities of deadlocks, these possibilities were already always there so I thought there was no harm in adding this.
To use this, first you need to acquire a reference to the plugin you want to use. You get this reference by asking the plugin manager for a plugin by its name.
Now you have this reference you can call ANY global function in its script.
This Call() function is very flexible though, it can take any number of arguments and returns any number of values. You can for example do this
When Plugin2:HandleCoinCommand() is called, this should be the output
There's one thing you should keep in mind though, and that is that you can only pass integers, booleans, strings and usertypes (cPlayer, cEntity, cCuboid, etc.). This means NO tables, arrays, lists, etc.
Even though this opens possibilities of deadlocks, these possibilities were already always there so I thought there was no harm in adding this.
To use this, first you need to acquire a reference to the plugin you want to use. You get this reference by asking the plugin manager for a plugin by its name.
PluginManager = cRoot:Get():GetPluginManager() local CorePlugin = PluginManager:GetPlugin("Core")
Now you have this reference you can call ANY global function in its script.
CorePlugin:Call("HandleReloadCommand")This will reload all plugins. The HandleReloadCommand is (AFAIK) the only function that does not require an array of strings or a player reference.
This Call() function is very flexible though, it can take any number of arguments and returns any number of values. You can for example do this
-- Plugin1 local Coins = 0 function GetCoins() return Coins end function AddCoins( Amount, PlayerName ) Coins = Coins + Amount LOG("Added " .. Amount .. " coins to " .. PlayerName ); return Coins, PlayerName end -- Plugin2 function HandleCoinCommand() PluginManager = cRoot:Get():GetPluginManager() local Plugin1 = PluginManager:GetPlugin("Plugin1") LOG( "Coins: " .. Plugin1:Call("GetCoins") ) local NumCoins, PlayerName = Plugin1:Call("AddCoins", 100, "FakeTruth") LOG("AddCoins returned: ".. NumCoins ..", ".. PlayerName ) LOG( "Coins: " .. Plugin1:Call("GetCoins") ) end
When Plugin2:HandleCoinCommand() is called, this should be the output
Coins: 0 Added 100 coins to FakeTruth AddCoins returned: 100, FakeTruth Coins: 100
There's one thing you should keep in mind though, and that is that you can only pass integers, booleans, strings and usertypes (cPlayer, cEntity, cCuboid, etc.). This means NO tables, arrays, lists, etc.