Raised This Month: $ Target: $400
 0% 

Register and Use Native in the Same Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 02-07-2010 , 07:46   Register and Use Native in the Same Plugin
Reply With Quote #1

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?
__________________
hleV is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 02-07-2010 , 07:57   Re: Register and Use Native in the Same Plugin
Reply With Quote #2

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 ^^
__________________
xbatista is offline
Send a message via Skype™ to xbatista
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 02-07-2010 , 08:10   Re: Register and Use Native in the Same Plugin
Reply With Quote #3

Quote:
Originally Posted by xbatista View Post
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.
__________________
hleV is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 02-07-2010 , 09:25   Re: Register and Use Native in the Same Plugin
Reply With Quote #4

What's your purpose of creating and using a native in the same plugin in the first place?
SnoW is offline
Send a message via MSN to SnoW
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 02-07-2010 , 09:46   Re: Register and Use Native in the Same Plugin
Reply With Quote #5

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.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 02-07-2010 , 10:47   Re: Register and Use Native in the Same Plugin
Reply With Quote #6

Quote:
Originally Posted by SnoW View Post
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.
__________________
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-07-2010 , 13:40   Re: Register and Use Native in the Same Plugin
Reply With Quote #7

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.
__________________

Last edited by fysiks; 02-07-2010 at 13:44.
fysiks is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 02-07-2010 , 13:48   Re: Register and Use Native in the Same Plugin
Reply With Quote #8

Quote:
Originally Posted by fysiks View Post

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.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-07-2010 , 14:20   Re: Register and Use Native in the Same Plugin
Reply With Quote #9

Well, it's probably better to recreate the native's functionality as a stock and use that anyways.
__________________
fysiks 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 07:17.


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