Raised This Month: $ Target: $400
 0% 

'Hybrid' Plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 09-23-2021 , 10:15   Re: 'Hybrid' Plugin?
Reply With Quote #1

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 #2

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
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 11:35.


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