PDA

View Full Version : Natives, creating callbacks


yusufali
11-06-2014, 00:43
I've been reading the docs on creating natives:

https://wiki.alliedmods.net/Creating_Natives_(SourceMod_Scripting)

I was wondering how would one create a native with callback?

Senario:
Native gives "rank" of player
So it queries the server (threaded) and will return the rank in some form of callback
Kinda like how gameME has their native for getting player information

Can anyone link some docs, or some insight on how to get this done

ddhoward
11-06-2014, 00:57
https://wiki.alliedmods.net/Function_Calling_API_(SourceMod_Scripting)#Fo rwards
https://wiki.alliedmods.net/Optional_Requirements_(SourceMod_Scripting)

yusufali
11-06-2014, 09:48
awesome, thanks

Powerlord
11-06-2014, 11:03
You can implement callbacks without private forwards, it just isn't recommended.

Mainly because plugins have no idea when other plugins unload.

friagram
11-06-2014, 11:54
You can just register the same global forward over again :3

Powerlord
11-06-2014, 12:54
You can just register the same global forward over again :3

Global Forwards are great if you don't care about which plugins respond to something you do, such as MapChooser's OnMapVoteEnded callback.

However, it's lousy for if you just want one or two plugins to receive that data, such as for the menu system's MenuHandler.

At the moment, private forwards are the only real way to tell when an arbitrary plugin is unloaded. There was a request (https://bugs.alliedmods.net/show_bug.cgi?id=5274) to have a new forward added to the SourceMod core for this, but afaik it was never implemented.

friagram
11-06-2014, 13:21
Well, generally you can just check librarys. And global forwards generally get the job done.

If there is some system for loding/unloading of plugins, it would have to be something good. Like, we's need some features like:
- library name, should be required for all plugins, perhaps as part of the myinfo array. If omitted, just make the library some mangled name based off of the filename.
- automatically formed unique identifier fort the file version, crc or something of that sort, so we can index the plugin.

Chdata
11-06-2014, 13:56
You can implement callbacks without private forwards, it just isn't recommended.

Mainly because plugins have no idea when other plugins unload.

OnLibraryRemoved?

Powerlord
11-06-2014, 15:23
OnLibraryRemoved?

And here are the issues with that approach:

It only works if the other plugin uses RegPluginLibrary.
You have to know the library name of the other plugin.


In theory, you can require other plugins to do that. In practice... good luck with that!