Raised This Month: $51 Target: $400
 12% 

'Hybrid' Plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 09-22-2021 , 03:56   'Hybrid' Plugin?
Reply With Quote #1

Hello there guys, i'm a newbie here. I have a simple question regarding plugins. Is it possible to make "hybrid" plugin e.g. Extra Items for ZP and for vanilla mode just in one .sma ?

Imagine having zp_xxx.sma and normal_xxx.sma which is exact same file and the difference is only zp_ natives thing and register_clcmd for obtaining the item. What a pain..
asdian is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 09-22-2021 , 04:41   Re: 'Hybrid' Plugin?
Reply With Quote #2

it is possible and you have 2 way:
1. Using Module filter and check libary zp50_core (since it usually there) and then use Native Filter to prevent an error throw at you when you check zp_get_user_zombie. After that, you can just check Libary to see if they are running ZP or not

PHP Code:
new bool:IsZPRunning false

public plugin_natives()
{
    
set_module_filter("module_filter")
    
set_native_filter("native_filter")
}
public 
module_filter(const module[])
{
    if (
equal(module"zp50_core"))
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}
public 
native_filter(const name[], indextrap)
{
    if (!
trap)
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}

public 
plugin_init()
{
    if(
LibraryExists(LIBRARY_BUYMENUSLibType_Library)) 
        
IsZPRunning true //then just check it if to seprate ZP and Normal

This way will automatically swap between 2 mode without needing to edit it.
The downside is it not work with ZP 4.3 since ZP 4.3 was not used Library

2. Make a #define and make #if every time you need to separate between ZP and Normal. Here I used #if defined
PHP Code:
#define ZP_MODE 

#if defined ZP_MODE
    //Do ZP stuff
#else
    //Do Normal Stuff
#endif 
So you could just comment the #define to switch to other mode. Of course, the #else is optional.
But with this, you have to manually change and have to compile again.

P/S: I am not sure with filter way since I haven't try it yet but you could take look at ZP 5.0 Main Menu as example
P/S2: If you use native for plugins then the second one is more ideal since you have to register_native (which called before plugin_init)
__________________
My plugin:

Last edited by Celena Luna; 09-22-2021 at 05:03.
Celena Luna is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 09-22-2021 , 06:54   Re: 'Hybrid' Plugin?
Reply With Quote #3

Quote:
Originally Posted by Celena Luna View Post
it is possible and you have 2 way:
1. Using Module filter and check libary zp50_core (since it usually there) and then use Native Filter to prevent an error throw at you when you check zp_get_user_zombie. After that, you can just check Libary to see if they are running ZP or not

PHP Code:
new bool:IsZPRunning false

public plugin_natives()
{
    
set_module_filter("module_filter")
    
set_native_filter("native_filter")
}
public 
module_filter(const module[])
{
    if (
equal(module"zp50_core"))
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}
public 
native_filter(const name[], indextrap)
{
    if (!
trap)
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}

public 
plugin_init()
{
    if(
LibraryExists(LIBRARY_BUYMENUSLibType_Library)) 
        
IsZPRunning true //then just check it if to seprate ZP and Normal

This way will automatically swap between 2 mode without needing to edit it.
The downside is it not work with ZP 4.3 since ZP 4.3 was not used Library

2. Make a #define and make #if every time you need to separate between ZP and Normal. Here I used #if defined
PHP Code:
#define ZP_MODE 

#if defined ZP_MODE
    //Do ZP stuff
#else
    //Do Normal Stuff
#endif 
So you could just comment the #define to switch to other mode. Of course, the #else is optional.
But with this, you have to manually change and have to compile again.

P/S: I am not sure with filter way since I haven't try it yet but you could take look at ZP 5.0 Main Menu as example
P/S2: If you use native for plugins then the second one is more ideal since you have to register_native (which called before plugin_init)
how to use that native filter to prevent error with zp_ natives ?

Last edited by asdian; 09-22-2021 at 06:55.
asdian is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 09-22-2021 , 23:47   Re: 'Hybrid' Plugin?
Reply With Quote #4

Quote:
Originally Posted by asdian View Post
how to use that native filter to prevent error with zp_ natives ?
PHP Code:
new bool:IsZPRunning false //Boolean to check if ZP is running.

public plugin_natives()
{
    
set_native_filter("native_filter")
    
set_module_filter("module_filter")
}

public 
native_filter(const name[], indextrap)
{
    if(!
trap)
        return 
PLUGIN_HANDLED
    
    
return PLUGIN_CONTINUE
}

public 
module_filter(const module[])
{
    if (
equal(module"zp50_core"))
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}

public 
plugin_init()
{
    if(
LibraryExists("zp50_core"LibType_Library)) 
        
IsZPRunning true //if zp50_core loaded, plugin will be in ZP mode


//I will make example here when tanking damage
public fw_Player_TakeDamage(victiminflictorattackerFloat:DamageiDamageBits)
{
    if(
IsZPRunning)
    {
        if(
zp_core_is_zombie(id)
        {
             
//Do ZP stuff
            
SetHamParamFloat(42000.0)
        }
    }
    else
   {
       
//Do Normal CS Mode stuff
      
SetHamParamFloat(4100.0)
   }

If you want to know if there is a Libary, check the include file
Code:
#if AMXX_VERSION_NUM >= 175     #pragma reqlib zp50_core     #if !defined AMXMODX_NOAUTOLOAD
        #pragma loadlib zp50_core
    #endif #else
    #pragma library zp50_core
#endif

Because zombieplague.inc doesn't have libary, it can't be check this way.
__________________
My plugin:

Last edited by Celena Luna; 09-22-2021 at 23:53.
Celena Luna is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 09-23-2021 , 02:38   Re: 'Hybrid' Plugin?
Reply With Quote #5

Quote:
Originally Posted by Celena Luna View Post
PHP Code:
new bool:IsZPRunning false //Boolean to check if ZP is running.

public plugin_natives()
{
    
set_native_filter("native_filter")
    
set_module_filter("module_filter")
}

public 
native_filter(const name[], indextrap)
{
    if(!
trap)
        return 
PLUGIN_HANDLED
    
    
return PLUGIN_CONTINUE
}

public 
module_filter(const module[])
{
    if (
equal(module"zp50_core"))
        return 
PLUGIN_HANDLED;
    
    return 
PLUGIN_CONTINUE;
}

public 
plugin_init()
{
    if(
LibraryExists("zp50_core"LibType_Library)) 
        
IsZPRunning true //if zp50_core loaded, plugin will be in ZP mode


//I will make example here when tanking damage
public fw_Player_TakeDamage(victiminflictorattackerFloat:DamageiDamageBits)
{
    if(
IsZPRunning)
    {
        if(
zp_core_is_zombie(id)
        {
             
//Do ZP stuff
            
SetHamParamFloat(42000.0)
        }
    }
    else
   {
       
//Do Normal CS Mode stuff
      
SetHamParamFloat(4100.0)
   }

If you want to know if there is a Libary, check the include file
Code:
#if AMXX_VERSION_NUM >= 175     #pragma reqlib zp50_core     #if !defined AMXMODX_NOAUTOLOAD
        #pragma loadlib zp50_core
    #endif #else
    #pragma library zp50_core
#endif

Because zombieplague.inc doesn't have libary, it can't be check this way.
i see...
PHP Code:
if (equal(module"zp50_core")) 
is 'module' code meant the .sma ?
asdian is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 09-23-2021 , 03:27   Re: 'Hybrid' Plugin?
Reply With Quote #6

Quote:
Originally Posted by asdian View Post
i see...
PHP Code:
if (equal(module"zp50_core")) 
is 'module' code meant the .sma ?
I am not sure but I think it is also referring to the library.
__________________
My plugin:
Celena Luna is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 09-23-2021 , 05:15   Re: 'Hybrid' Plugin?
Reply With Quote #7

Quote:
Originally Posted by Celena Luna View Post
I am not sure but I think it is also referring to the library.
the .inc ?
asdian is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-23-2021 , 10:15   Re: 'Hybrid' Plugin?
Reply With Quote #8

The inc has nothing to do with creating the library, it is simply loading it for you. The library is created in the plugin itself by calling register_library. If there is no library as in zp43, you won't need module_filter, just native_filter. You could do something like this

Code:
#include <amxmodx>
#tryinclude <zombieplague>

new g_mod_zp43 = true

public plugin_init()
{
	register_plugin("Plugin", "Version", "Author")
	
#if defined _zombieplague_included
	zp_register_extra_item("item", 30, ZP_TEAM_HUMAN)
#else
	g_mod_zp43 = false
#endif

	if (g_mod_zp43)
	{
		// zombie plague
	}
	else
	{
		// an other mod
	}
}

public plugin_natives()
{
	set_native_filter("native_filter")
}

public native_filter(const name[], index, trap)
{
	if (equal(name, "zp_register_extra_item"))
	{
		if (!trap)
			g_mod_zp43 = false

		return PLUGIN_HANDLED
	}

	return PLUGIN_CONTINUE
}
It would be a lot easier and would look better if amxmodx had a native_exists.

Code:
enum
{
	NATIVE_PARAM_CELL,
	NATIVE_PARAM_FLOAT,
	NATIVE_PARAM_STRING,
	NATIVE_PARAM_ARRAY,
	NATIVE_PARAM_BYREF,
}

NATIVE_PARAM_CELL - ensure param is an integer
NATIVE_PARAM_FLOAT - ensure param is a float
NATIVE_PARAM_STRING - ensure param is a string
NATIVE_PARAM_STRING - ensure param is an array
NATIVE_PARAM_BYREF - ensure param is byref

native native_exists(const native[], any:...)
native call_native(const native[], any:...)
...

if (native_exists("the_native", NATIVE_PARAM_STRING, NATIVE_PARAM_STRING))
{
	call_native("the_native", "foo", "bar")
}
// native doesn't exists or param types doesn't apply
else
{

	do_something_else("foo", "bar")
}
__________________









Last edited by CrazY.; 09-23-2021 at 10:33.
CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 09-23-2021 , 23:05   Re: 'Hybrid' Plugin?
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
The inc has nothing to do with creating the library, it is simply loading it for you.
I haven't used it for awhile now so I forgot.
So _zombieplague_included already defined in zombieplague.inc so we just need to check it to see if ZP is running or not, don't need to create a new #define. Noted.

But it still required user to re-compile the plugins with the compiler that doesn't have zombieplague.inc in the include folder or remove the #include <zombieplague> in the plugins. Which isn't what he want.
Also, it would only handle zp_register_extra_item in your example. If the plugins contain another native zp_get_user_zombie or zp_class_nemesis_get would throw an error.

This is what I came up with
PHP Code:
public plugin_natives()
{
    
set_native_filter("native_filter")
}

public 
native_filter(const name[], indextrap)
{
    if (
equal(name"zp_get_user_zombie")) //For both ZP43 & ZP5.0+ compat
    
{
        if (!
trap)
            
g_mod_zp43 false

        
return PLUGIN_HANDLED
    
}
    
    
//Just filter all of them to prevent throwing error
    
if (!trap)
        return 
PLUGIN_HANDLED

    
return PLUGIN_CONTINUE
}

public 
do_something(id)
{
    if(
g_mode_zp43
    {
        if(
zp_class_nemesis_get(id))
            
do_stuff(id)
    }
    else
    {
        
do_normal_mode_stuff(id)
    }

@CrazY. Is it possible to do something like this? Since OP want the native only create for ZP and clcmd for Normal
PHP Code:
public plugin_natives()
{
    
set_native_filter("native_filter")
    if(
g_mode_zp43register_native("zp_get_cannon""Native_Get_Cannon"1);
}

public 
native_filter(const name[], indextrap)
{
    if (
equal(name"zp_register_extra_item"))
    {
        if (!
trap)
            
g_mod_zp43 false

        
return PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE

__________________
My plugin:

Last edited by Celena Luna; 09-24-2021 at 00:37.
Celena Luna is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-24-2021 , 08:16   Re: 'Hybrid' Plugin?
Reply With Quote #10

Quote:
But it still required user to re-compile the plugins with the compiler that doesn't have zombieplague.inc in the include folder or remove the #include <zombieplague> in the plugins.
Yes but wouldn't need to remove the include, as I replaced with #tryinclude, which first check if the file exists before including. If you want this to be dynamic, that is, not recompiling the plugin in order to it work, delete the #if defined part of the code, but then the user would need to have zombieplague.inc, alternatively you can define the natives directly in the plugin as you do in includes. If you're targetting only zp50 and zp43 you should be fine, but for modified ZPs you may end up having problems

Quote:
Also, it would only handle zp_register_extra_item in your example. If the plugins contain another native zp_get_user_zombie or zp_class_nemesis_get would throw an error.
if zp_register_extra_item exists it's very likely that zp43 is also loaded but if you want to make sure, you can check all natives you're going to use in your plugin using the same native_filter method.

Quote:
@CrazY. Is it possible to do something like this? Since OP want the native only create for ZP and clcmd for Normal
That's not going to work as expected since native_filter seems to be called only after you "trigger" a native. I would probably register a native without the zp prefix and then check if zp is running or not and make the plugin act accordingly
__________________








CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:55.


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