Raised This Month: $9 Target: $400
 2% 

MarkNativeAsOptional - inconvenient moment.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
client21
Senior Member
Join Date: Apr 2013
Old 10-14-2021 , 12:48   MarkNativeAsOptional - inconvenient moment.
Reply With Quote #1

z.inc

PHP Code:
#if defined _z_included
#endinput
#endif
#define _z_included

native int Test_z();

public 
SharedPlugin __pl_z 
{
    
name "z",
    
file "z.smx",
    
required 0
};

public 
void __pl_z_SetNTVOptional()
{
    
MarkNativeAsOptional("Test_z");

z.sp

PHP Code:
#include <z>

public void OnClientPostAdminCheck(int client)
{
    
bool b false;
    if (
b) {
        
Test_z();
    }

sm plugins load z.smx
[SM] Plugin z.smx failed to load: Native "Test_z" was not found.

If I rename z.smx to zz.smx (or other) then it works.

if I do:

PHP Code:
public APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
MarkNativeAsOptional("Test_z");
    return 
APLRes_Success;

in z.smx then it works.

Why public void __pl_z_SetNTVOptional() doesn't work for z.smx
Why am I forced to do AskPluginLoad2->MarkNativeAsOptional in z.smx

-----------------
It will work if in z.smx I do:

PHP Code:
public APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
CreateNative("Test_z"Test_z_);
    return 
APLRes_Success;
}

public 
int Test_z_(Handle pluginint args) {
    return 
0;

But my goal is to create native "Test_z" with a delay.
Apparently __pl_z_SetNTVOptional doesn't work because of the delay and I have to do MarkNativeAsOptional.
Anyway, I expected more from __pl_z_SetNTVOptional.

Last edited by client21; 10-14-2021 at 12:59.
client21 is offline
Fortis
Junior Member
Join Date: Nov 2016
Old 10-14-2021 , 23:38   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #2

Quote:
Originally Posted by client21 View Post
But my goal is to create native "Test_z" with a delay.
I'm confused by what you mean here, you create natives in AskPluginLoad2 to ensure all other plugins on your server can use the native as long as they have the include file. You can mark natives as optional in the include file so if you unload the plugin you created the native in, the other plugins using it can still run and won't fail to load.

Example:

z.inc
PHP Code:
#if defined _z_included
#endinput
#endif
#define _z_included

native int Test_Z();

public 
SharedPlugin __pl_z 
{
    
name "z",
    
file "z.smx",
#if defined REQUIRE_PLUGIN
    
required 1,
#else
    
required 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_z_SetNTVOptional()
{
    
MarkNativeAsOptional("Test_Z");
}
#endif 
z.sp
PHP Code:
#include <z>

public APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
CreateNative("Test_Z"Native_Z);
    return 
APLRes_Success;
}

public 
int Native_Z(Handle pluginint numParams)
{
    return 
0;
}

public 
void OnClientPostAdminCheck(int client)
{
    
int z Test_Z();

Any other plugin now can use the Test_Z native as long as its included

zz.sp
PHP Code:
#include <z>

public void OnClientPutInServer(int client)
{
    
int z Test_Z();


Last edited by Fortis; 10-16-2021 at 15:17.
Fortis is offline
client21
Senior Member
Join Date: Apr 2013
Old 10-15-2021 , 14:24   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #3

Quote:
Originally Posted by Fortis View Post
Example:
Thanks, but I know that. This way is not suitable for me because:

Quote:
Originally Posted by client21 View Post
But my goal is to create native "Test_z" with a delay.
Don't ask me why I need it, just accept the fact that I need it

In any case, I will find the optimal solution, but I thought that __pl_z_SetNTVOptional was not working correctly and created this thread. Perhaps I should have written about this in section "Issues" (github).
client21 is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 10-15-2021 , 20:49   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #4

Quote:
Originally Posted by client21 View Post
Thanks, but I know that. This way is not suitable for me because:
Don't ask me why I need it, just accept the fact that I need it
AskPluginLoad2 is the earliest you may create a it such that all other plugins are able to use the native.

Fortis was kind enough to show you the right way to register a native (if you're still unsure review the wiki).

Quote:
Originally Posted by client21 View Post
Perhaps I should have written about this in section "Issues" (github).
The first question we'd ask you in the issue is "why".
headline is offline
client21
Senior Member
Join Date: Apr 2013
Old 10-15-2021 , 21:33   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #5

Quote:
Originally Posted by headline View Post
Fortis was kind enough
Yes, you are all very kind, but for some reason you do not answer my main question. I've provided a specific example code and I'm wondering why __pl_z_SetNTVOptional->MarkNativeAsOptional doesn't work for z.smx. Instead of answering this, you teach me to create natives, although I can do it.
client21 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 10-16-2021 , 11:34   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #6

A plugin doesn't run its own SetNTVOptional implementation, it doesn't make sense to - natives should always exist for the lifetime of a plugin.
__________________
asherkin is offline
client21
Senior Member
Join Date: Apr 2013
Old 10-16-2021 , 12:57   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
A plugin doesn't run its own SetNTVOptional implementation, it doesn't make sense to - natives should always exist for the lifetime of a plugin.
This is done on purpose. Understood, thanks
client21 is offline
Fortis
Junior Member
Join Date: Nov 2016
Old 10-16-2021 , 13:48   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #8

Quote:
Originally Posted by client21 View Post
Don't ask me why I need it, just accept the fact that I need it
We're asking why because if you don't create the native in AskPluginLoad2 then to my knowledge no other plugin can use it besides the one it was created in. (Read the Wiki Under Registering Natives) At that point why create a Native if only one plugin is gonna use it? If you're ultimately set on creating a native with a delay, just use a timer, just note only this plugin can use it.

PHP Code:
#include <z>

public void OnPluginStart()
{
    
CreateTimer(2.0Timer_Natives);
}

public 
Action Timer_Natives(Handle timer)
{
    
CreateNative("Test_Z"Native_Z);
    return 
Plugin_Handled;


Last edited by Fortis; 10-16-2021 at 15:26. Reason: I forgot some information, was on mobile at the time.
Fortis is offline
client21
Senior Member
Join Date: Apr 2013
Old 10-16-2021 , 17:10   Re: MarkNativeAsOptional - inconvenient moment.
Reply With Quote #9

Quote:
Originally Posted by Fortis View Post
just note only this plugin can use it.

PHP Code:
#include <z>

public void OnPluginStart()
{
    
CreateTimer(2.0Timer_Natives);
}

public 
Action Timer_Natives(Handle timer)
{
    
CreateNative("Test_Z"Native_Z);
    return 
Plugin_Handled;

Why are you lying?) If another plugin is loaded later or there is the necessary communication between them (for example, using events, or GetFeatureStatus->FeatureType_Native), then this will work. The topic does not need to be continued, the answer was received. It's okay that you couldn't help me

----------
I think I understand what you mean.
If the native is created using a timer (even 0.1), then other plugins get an error: "[SM] Exception reported: Native is not bound".
But still works in "OnPluginStart" or if the plugin was loaded after the native-creator plugin.
Thx.

Last edited by client21; 10-17-2021 at 01:59.
client21 is offline
Reply


Thread Tools
Display Modes

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 16:27.


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