AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [help] letting 2 plugins interact with each other (https://forums.alliedmods.net/showthread.php?t=184136)

striker07 05-01-2012 10:03

[help] letting 2 plugins interact with each other
 
I just made this include, could anyone tell me if this is correct for what i want to do?


the point of the include is to remember when a first plugin has done something that needs to enable an action inside another plugin. So that they can work/interact on each other, will this work?


PHP Code:

 
#if defined _jbrebel_included
#endinput
#endif
#define _jbrebel_included
 
/**
* Returns whether a player is a rebel or not.
*
* @param id Player index.
* @return True if he is, false otherwise.
*/
native is_user_rebel(id)
/**
* Set's a players status to rebel.
*
* @param id Player index.
* @return True on success, false otherwise.
*/
native set_user_rebel(id)
/**
* Removes a player's rebelstatus.
*
* @param id Player index.
* @return True on success, false otherwise.
*/
native remove_user_rebel(id


striker07 05-28-2012 10:58

Re: [help] letting 2 plugins interact with each other
 
I must be overseeing something becous this is not working,
when I started up my server with the 2 plugins that use this include it showed me this error:

Code:

L 05/28/2012 - 16:55:07: [AMXX] Plugin "walkguard.amxx" failed to load: Plugin uses an unknown function (name "set_user_rebel") - check your modules.ini.
L 05/28/2012 - 16:55:07: [AMXX] Plugin "jailbreak-the-siege.amxx" failed to load: Plugin uses an unknown function (name "is_user_rebel") - check your modules.ini.

Can some1 give me a lil explanation on how to do this pls?

<VeCo> 05-28-2012 11:00

Re: [help] letting 2 plugins interact with each other
 
Did you registered the library and those natives in plugin_natives() in the main plugin?

striker07 05-28-2012 11:16

Re: [help] letting 2 plugins interact with each other
 
No, I added this now but i need some help, this is the first time I attempt something like this:
PHP Code:

public plugin_natives ()
{
 
register_native("is_user_rebel""_is_user_rebel");
 
register_native("set_user_rebel""_set_user_rebel");
 
register_native("remove_user_rebel""_remove_user_rebel");
}
public 
_is_user_rebel(id)
{
 if(
is_user_rebel(id) )
  return 
1;
 else
  return 
0;
}
public 
_set_user_rebel(id)
{
 if(!
is_user_rebel(id) )
 {
  
//No clue what to put here, just some bold guesses
  
return 1;
 }
}
public 
_remove_user_rebel(id)
{
 
// need some help


When this piece of code is finished then i should put that in both plugin that use this include right?
what do you mean with the library?

Liverwiz 05-28-2012 11:30

Re: [help] letting 2 plugins interact with each other
 
Quote:

Originally Posted by striker07 (Post 1718136)
if(is_user_rebel(id) )
return 1;
else
return 0;

Code:

(is_user_rebel(id) ) ? return 1 : return 0
Both work....that is just pretty. ;)

Bugsy 05-28-2012 11:39

Re: [help] letting 2 plugins interact with each other
 
PHP Code:

public _is_user_rebel(id)
{
    return 
is_user_rebel(id);


Or if is_user_rebel returns values != 0/1

PHP Code:

public _is_user_rebel(id)
{
    return !!
is_user_rebel(id);



<VeCo> 05-28-2012 12:05

Re: [help] letting 2 plugins interact with each other
 
If you don't use 1 in the end of register_native, then the native function should look like this:

PHP Code:

public _is_user_rebel(plugin,params)
{
return 
/*...*/is_user_rebel(get_param(1))


For the library I meant using register_library.

striker07 05-28-2012 12:37

Re: [help] letting 2 plugins interact with each other
 
Quote:

Originally Posted by Bugsy (Post 1718144)
PHP Code:

public _is_user_rebel(id)
{
return 
is_user_rebel(id);


Or if is_user_rebel returns values != 0/1
PHP Code:

public _is_user_rebel(id)
{
return !!
is_user_rebel(id);



hehe bugsy you expert, i see you like making you're code hard to read :p

Quote:

Originally Posted by <VeCo> (Post 1718162)
If you don't use 1 in the end of register_native, then the native function should look like this:

PHP Code:

public _is_user_rebel(plugin,params)
{
return 
/*...*/is_user_rebel(get_param(1))


For the library I meant using register_library.

I'm confused, are the first 2 (_is_user_rebel & _set_user_rebel ) correct the way i did it?

and how about the _remove_user_rebel, will this do it:
PHP Code:

public _remove_user_rebel(id)
{
 if( 
is_user_rebel(id) )
  return 
0;
// Or just this, if it's possible:
 
return is_user_rebel(id) = 0;


for the libraby: it doesnt use a dictionary, its worked in the plugin itself and for walkguard i adjusted the existing library

<VeCo> 05-28-2012 12:41

Re: [help] letting 2 plugins interact with each other
 
Add ",1" in the end of register_native if you want to use the nativе parameters directly.

striker07 05-28-2012 12:53

Re: [help] letting 2 plugins interact with each other
 
Quote:

Originally Posted by <VeCo> (Post 1718174)
Add ",1" in the end of register_native if you want to use the nativе parameters directly.

So then i dont need the public functions linked to the natives?
but then will the game know that the remove function removes the rebel state( is_user_rebel(id) )?


All times are GMT -4. The time now is 07:47.

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