AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   plugin-to-plugin communication (https://forums.alliedmods.net/showthread.php?t=658)

ann0yanc3 03-30-2004 01:18

plugin-to-plugin communication
 
to what extent can plugins communicate with one another?

Johnny got his gun 03-30-2004 01:20

xvars, cvars, vault, files, sql, tasks, ...

But to be honest; why do you need interplugin communication? I have made a lot of plugins and almost never really needed that.

KiN | SuicideDog 03-30-2004 03:23

I can see that .. I'm thinking of redoing next map.. and map chooser so they track the last 5 maps.. I would like to share vars between them.

PM 03-30-2004 05:25

you can also call a public function in an another plugin using the callfunc_* natives. Check the amxmodx.inc file for details

MagicShot 03-30-2004 12:04

hmm
 
Quote:

Originally Posted by PM
you can also call a public function in an another plugin using the callfunc_* natives. Check the amxmodx.inc file for details

Quote:

/* Call a function in this / an another plugin by name.
* Parameters:
* plugin - plugin name; if "", the caller plugin is used.
* If specified, it has to be the exact name (for example stats.amx)
* func - function name
* Return value:
* 1 - Success
* 0 - Runtime error
* -1 - Plugin not found
* -2 - Function not found */
native callfunc_begin(const plugin[]="", const func[]);


/* Push a parameter (integer, string, float) */
native callfunc_push_int(value);
native callfunc_push_str(value[]);
native callfunc_push_float(Float: value);
native callfunc_push_intrf(&value);
native callfunc_push_floatrf(& Float: value);

/* Make the actual call.
* Return value of the function called. */
native callfunc_end();
Do all three of those need to be used when calling a pubic?

when

PM 03-30-2004 12:20

hmm lol the function prototype actually is
Code:
native callfunc_begin(const func[], const plugin[]="");
looks like we have messed it up in the include file

anyways, here is an example:
Code:
callfunc_begin("my_function", "theplugin.amx"); callfunc_push_int(4); callfunc_push_str("Hello"); callfunc_push_float(myfloatvalue); new returnValue = callfunc_end();

this will call the public function my_function in the plugin theplugin.amx, the first parameter will be 4, the second parameter will be "Hello", the third parameter will be the value of myfloatvalue variable / constant / whatever. In returnValue, the return value will be stored ;]

callfunc_push_int: push the value of the integer
used with normal parameters
callfunc_push_intrf: push the reference to the variable
used with &prm parameters
callfunc_push_float: push the value of the float
used with Float:prm parameters
callfunc_push_floatrf: push the reference to the float variable
used with &Float:prm parameters
callfunc_push_str: push a string (an array)
used with prm[] / const prm[] parameters

A native like
callfunc(func, plugin, param1, param2, param2);
is not possible / very very hard to implement.

]FUSION[ Gray Death 03-30-2004 12:34

Is there anything bad, to use a couple of cvars for communication? Especially slow, limited, etc...?

MagicShot 03-30-2004 18:02

Hrm
 
What does it mean to "push"?

AssKicR 03-30-2004 18:05

snd info over to that plugin

BAILOPAN 03-30-2004 18:05

push and pop refer to stacks of data such as an array or list.

Push adds an item to the tail/end of a list. PM's callfunc works by pushing values onto a list of parameters and then calling the actual function once you end it. much like message_begin ... write_x.... message_end

MagicShot 03-30-2004 18:10

Hrm...
 
What kinda things is this usefull for?

BAILOPAN 03-30-2004 18:24

if you have to ask you don't know ;]

<serious> it's useful for calling arbitrary functions that you do not know the name for.

for example, PHP has this ability:
$x = "myfunction"
$x(); //This will call "myfunction" if it exists

same thing in C:

int myfunc(void);

int (*func)(void) = myfunc;
(*func)();

MagicShot 03-30-2004 18:55

?
 
Does the "callfunc_begin" execute the public fuction in the plugin also?

PM 03-31-2004 07:39

Re: ?
 
Quote:

Originally Posted by MagicShot
Does the "callfunc_begin" execute the public fuction in the plugin also?

What? The callfunc_end does the actual execution

MagicShot 03-31-2004 11:58

oh
 
yeah sorry PM.. thats what i meant but when You execute it it will run what evers in that public command?

PM 03-31-2004 12:21

i don't really understand you so i'll make an example :)

plugin1
Code:
// other code (plugin_init etc)... public the_function(paramint, &paramintref, paramstr[]) {    log_amx("the_function called. paramint = %d, paramintref = %d, paramstr = %s", paramint, paramintref, paramstr);    paramintref++;    paramstr[0] = '[';    return 100; } // other code...

plugin2
Code:
// in a function new intVar = 8; new strVar[] = "(:" log_amx("Will call the_function in plugin1.amx; the int param is 4, the intrf Param is 8, the str param is ^"(:^""); callfunc_begin("the_function", "plugin1.amx"); callfunc_push_int(4); callfunc_push_intrf(intVar); callfunc_push_str(strVar); new retVal = callfunc_end(); log_amx("Called it. Return value: %d; the int var is %d and the str var is %s", retVal, intVar, strVar);

The output should be:
Code:

Will call the_function in plugin1.amx; the int param is 4, the intrf Param is 8, the str param is "(:"

the_function called. paramint = 4, paramintref = 8, paramstr = (:

Called it. Return value: 100; the int var is 9 and the str var is [:

Not tested tho :)


All times are GMT -4. The time now is 21:35.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.