AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register and Use Native in the Same Plugin (https://forums.alliedmods.net/showthread.php?t=118049)

hleV 02-07-2010 07:46

Register and Use Native in the Same Plugin
 
Hello. I'm using native with style 0 and I'm trying to use the native in the same plugin in which I registered it.

Include file test.inc contains:
PHP Code:

#if defined TEST_INCLUDED
 #endinput
#endif
 
#define TEST_INCLUDED;
 
#pragma library Test
 
native Test(Client); 

Source file contains:
PHP Code:

#include <amxmodx>
#include <test>
 
public plugin_natives()
{
        
register_library("Test");
 
        
register_native("Test""_Test");
}
 
public 
SomeFunction(Client)
{
        
// I want to use native Test()
        // Can't use Test() since it doesn't exist yet
        // so I'm going directly to native function
        
_Test(Client);
}
 
public 
_Test(Client)
{
        
// I'm using style 0, so I need to do this
        // new Param = get_param(1);
        
Client get_param(1);
 
        
// Stuff


So I'm doing this:
PHP Code:

public SomeFunction(Client)
{
        
// I'm adding an argument with a value of 9999
        
_Test(Client9999);
}
 
public 
_Test(ClientArgument)
{
        
// Now I'm checking if Argument's value is 9999
        // If not - it's called as a native
        // otherwise - it's called as a normal function from this plugin
        
if (Argument != 9999)
                
Client get_param(1);
 
        
// Stuff


Is there a better method?

xbatista 02-07-2010 07:57

Re: Register and Use Native in the Same Plugin
 
If you're not using strings in native like public _Test(String[]) something like this, I suggest to use style 1 which is more easier ^^

hleV 02-07-2010 08:10

Re: Register and Use Native in the Same Plugin
 
Quote:

Originally Posted by xbatista (Post 1081445)
If you're not using strings in native like public _Test(String[]) something like this, I suggest to use style 1 which is more easier ^^

I'm using strings.

SnoW 02-07-2010 09:25

Re: Register and Use Native in the Same Plugin
 
What's your purpose of creating and using a native in the same plugin in the first place?

joropito 02-07-2010 09:46

Re: Register and Use Native in the Same Plugin
 
I'm sure that I read somewhere that using natives in the same plugin where they are defined it's not allowed or not recommended. Don't remember exactly.

hleV 02-07-2010 10:47

Re: Register and Use Native in the Same Plugin
 
Quote:

Originally Posted by SnoW (Post 1081539)
What's your purpose of creating and using a native in the same plugin in the first place?

Let's say I have 2 natives: Test1() and Test2(). Native Test1() does something that uses native Test2(). So:
PHP Code:

public MyNative1()
{
        
// Stuff
}
 
public 
MyNative2()
{
        
MyNative1();
 
        
// Stuff


So basically one native calls another one.

fysiks 02-07-2010 13:40

Re: Register and Use Native in the Same Plugin
 
Call the function directly. There is no reason to use the "native" as a native.

Oh, wait, in post 1 you are not using the native. You are using the local function like I am suggesting.

EDIT: umm . . . maybe I'm wrong, I'll need to find out what style 0 and style 1 are.

joropito 02-07-2010 13:48

Re: Register and Use Native in the Same Plugin
 
Quote:

Originally Posted by fysiks (Post 1081848)

EDIT: umm . . . maybe I'm wrong, I'll need to find out what style 0 and style 1 are.

style 1 is like in zombie plague, function prototype is like native declaration (with parameters)

In style 0 you need to use get_param functions.

fysiks 02-07-2010 14:20

Re: Register and Use Native in the Same Plugin
 
Well, it's probably better to recreate the native's functionality as a stock and use that anyways.


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

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