Referencing one plugin from another

Questions, comments, and news on the server side plug-ins and it's API
Post Reply
Grue
Private First Class
Private First Class
Posts: 27
Joined: Tue Apr 08, 2014 12:23 am
Contact:

Referencing one plugin from another

Post by Grue »

Hey all,

I'm trying to make one plugin that contains a bunch of functions that are run continuously throughout the game and trigger at random points, and then make another plugin that references a few of those functions from the first plugin.

Is there any way to #include one plugin into the other? If so, how would I do so and reference functions/classes from the other plugin? It tried looking for the plugins' .h files but I couldn't find them.

Thanks,
Grue
User avatar
blast
General
General
Posts: 4931
Joined: Fri Mar 21, 2003 3:49 pm
Location: playing.cxx
Contact:

Re: Referencing one plugin from another

Post by blast »

I'm moving this from "Plug-in Releases" to "Plug-in Development", since it isn't a release of a plugin.

As for your question. you could make something like our plugin_utils and put your classes/functions in there.

There's also Inter-Plug-in Communcations that would let one plugin communicate with another and Plug-in Management functions that would let you check for loaded plugins and load/unload other plugins.
"In addition to knowing the secrets of the Universe, I can assure you that I am also quite potty trained." -Koenma (Yu Yu Hakusho)

Image
User avatar
JeffM
Staff Sergeant
Staff Sergeant
Posts: 5196
Joined: Fri Dec 13, 2002 4:11 am

Re: Referencing one plugin from another

Post by JeffM »

The generic callback system would be best to use.

Handle callbacks in plug-in A by overriding the

Code: Select all

GeneralCallback 
method on the plug-in class, and call them from plugin-in B using

Code: Select all

bz_callPluginGenericCallback()
you can pass in structure pointers as the void * argument to pass in data and get results.
ImageJeffM
User avatar
Zehra
Private First Class
Private First Class
Posts: 914
Joined: Sun Oct 18, 2015 3:36 pm
Location: Within the BZFS API and Beyond it
Contact:

Re: Referencing one plugin from another

Post by Zehra »

Some other ideas

If one plug-in is controlling things like frequency of an action, custom BZDB variables may be used. For example, if a custom world weapon/server shot plug-in for spawning random shots in a world, but it needs to be adjustable for how close or how frequent..etc, a custom BZDB variable may be used:

Code: Select all

bz_registerCustomBZDBBool()
bz_registerCustomBZDBDouble()
bz_registerCustomBZDBInt()
bz_registerCustomBZDBString()
bz_removeCustomBZDBVariable() 
The global-database-management-bzdb functions can be used and the bz_eBZDBChange can be used to keep plug-ins in sync about how often something may happen or what it may do, but it won't provide a notification of when.

To give a bit of an example of what can be done: (It's a bit of a complex one too.)
Let's say there's a custom CTF mode and it needs to take into account player and team strengths and tries to balance them out a bit by giving flags on spawn to players and stuff. flagOnSpawn nearly works perfectly for this particular reason.

In theory, it's easy to make a plug-in which uses the join and part data of players and calculates team sizes and scores of players, so if there's a lot of players on one team, but nearly none on the other, the flagOnSpawn plug-in could be unloaded and reloaded with a different set of flags to give on spawn. (This is simply an example, not an ideal way of doing it.)

Or it's simply possible to simply use custom BZDB variables for the spawns and flags, maybe even modifying flagOnSpawn to give flags based on BZDB variables and then simply setting the BZDB variables to what it should give based on x conditions.

But if it's simply calling a function or knowing when a plug-in is calling a function, either the inter-plug-in communications may work or simply including/duplicating the logic or specific use and need of code may be suitable.

There's also a bit of a hack which would involve sending debug messages bz_eLoggingEvent to act as a receiver of them and simply use that to base actions. (Untested theory.)

But probably anything larger is either merging plug-ins or simply modifying them to work in sync.

-Zehra
Those who are critical of me, I'll likely be the same of them. ~Zehra
The decisions we make are the ones we look forward too and the ones we regret. ~Zehra
There's a difference between knowing my name and knowing me, one shows respect to my name and the other is to who I am. ~Zehra

See where I've last been active at Strayers.
Visit BZList.net for a modern HTML5 server stats site.

Click here to view the 101 Leaderboard & Score Summaries Last updated 2021-01-12 (YYYY-MM-DD)
Latest 101 thread
Post Reply