[Tutorial] Communicating data across plugins (or how to use natives in general)
Hi, I'm a bad sourcepawn programmer, and I made this because I'm tired of seeing this in plugins and not knowing what the hell I'm looking at! :salty:
http://puu.sh/p6ODs/4049adfdf7.png Three W's: 1. When should I use this? - When your plugin looks like pasketti. 2. Why should I use this? - To organize stuff and consolidate your spaghetti into manageable partitions. 3. Where should I use this? - Anywhere you damn well please or intend to be communicating data across plugins, or exposing your functions to other people. Ahem, so continuing on. Well it says here on the wiki that "Natives" are and I quote: "It is a powerful inter-plugin communication resource that can greatly enhance the functionality you provide." So I assume we would want to start off with introducing you to some functions we'll be using:
To begin we'll want to make our plugin (go figure?). In order to make our natives work, we'll need to use a forward that may be new to many of you: AskPluginLoad2 Code:
forward APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max);PHP Code:
PHP Code:
After we've done this, we can move on back to our uselessnatives.sp and write the function of our native! Here's the callback we'll be using: NativeCall Code:
functag public NativeCall(Handle:plugin, numParams);PHP Code:
PHP Code:
Plugin with the native functions: PHP Code:
PHP Code:
Closing statements:
I would post some like profiler results showing a cached result vs. repeatedly using GetNativeCell or String repeatedly but I'm too lazy :( To you guys to refer to me as "that one bad kid", please do point out some mishaps in the tutorial. I found myself rewriting about every segment in php tags about 4x each, so there's bound to be something I forgot to clean up. Thanks and good luck in the future! So now instead of having 30,000 lines in one plugin, you have 19 plugins to be confused about dealing with like me! http://puu.sh/p6RB2/7263b46f5c.png pls dont kill me newdecls elitists i use them sometimes p.s. if theres any admins who see this and think it is good and want to be my friend temporarily if you could please drop the "Eas" out of my username and make it just "Sidezz" that would be sick as fuck. |
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
You forgot to talk about marking natives as optional.
https://github.com/ntoxin66/Dynamic/...namic.inc#L439 |
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Quote:
|
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Quote:
On a side note, never name a variable int as this isn't a valid variable name in SourcePawn 1.8 or newer. |
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Quote:
|
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
I got into the habit of this with includes:
Code:
#if defined _dynamic_included_ |
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Good job!
|
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
I hate my stupid brain! :-(
|
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Ok, I think I finally get it!
So we have this first plugin: PHP Code:
PHP Code:
PHP Code:
1) setAnInt(50) from second plugin is actually a function. Function from first plugin called native_setAnInt. 2) it pass the value 50 via uselessnatives.inc 3) uselessnatives.inc communicate with CreateNative("setAnInt", native_setAnInt) from first plugin 4) and by this magic, 50 is set in native_setAnInt function in first plugin. This function than changes value of anInt = 50. That's setAnInt. Passing data from second plugin to the first plugin. After it is set (passed) it is called by a function getAnInt. And there is no need for magic? It is just called like this? Directly? I need to pass an array from first plugin to second. Only one-way. What do I need??? |
Re: [Tutorial] Communicating data across plugins (or how to use natives in general)
Quote:
A) CreateNative tells SourceMod to bind setAnInt native to plugin function native_setAnInt through FakeNatives. B) 2nd Plugin calls setAnInt and pushes 50 to param stack. C) Sourcepawn lookups the native binding of setAnInt, discovers it as a fake native and calls the fake native router associated with the native. D) SourceMod sets up internal variables related to the fake native it's currently executing (in this case, setAnInt). E) SourceMod calls the bound plugin function. F) First plugin does logic for native and returns 0 (because SP compiler code injection). G) SourceMod re-returns 0 back to SP. H) SP re-returns 0 back to the 2nd plugin. I) Second plugin discards the returned value after current function is done executing. |
| All times are GMT -4. The time now is 18:55. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.