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

How to create properly a native for a bool value?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 10-14-2022 , 22:39   How to create properly a native for a bool value?
Reply With Quote #1

In base plugin:
Code:
new bool:RankedMatch = false;

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	CreateNative("RankedMatch", Native_RankedMatch);
	
	RegPluginLibrary("warmode");
	
	return APLRes_Success;
}

public int Native_RankedMatch(Handle plugin, int numParams)
{
	return RankedMatch;
}
My include:

Code:
#if defined _warmode_included
 #endinput
#endif
#define _warmode_included

native int RankedMatch();

public SharedPlugin __pl_warmode =
{
	name = "War mode",
	file = "warmode.smx",
#if defined REQUIRE_PLUGIN
	required = 1,
#else
	required = 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_warmode_SetNTVOptional()
{

	MarkNativeAsOptional("RankedMatch");
}
#endif

In other plugin added the inc file and created a debug command but have error 076: syntax error in the expression, or invalid function call on both "rankedmatch" when compiling
Code:
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	RegPluginLibrary("warmode");


	return APLRes_Success;
}

public Action DebugWar_Cmd(int client, int args)
{
    if ( RankedMatch == true )
    {
        PrintToChat(client,"Enabled");
    }
    
    if ( RankedMatch == false )
    {
        PrintToChat(client,"Disabled");
    }
}

Last edited by JLmelenchon; 10-14-2022 at 22:46.
JLmelenchon is offline
Cruze
Veteran Member
Join Date: May 2017
Old 10-15-2022 , 04:35   Re: How to create properly a native for a bool value?
Reply With Quote #2

if ( RankedMatch() == true )
if ( RankedMatch() == true )
PHP Code:
public Action DebugWar_Cmd(int clientint args)
{
    if ( 
RankedMatch() == true )
    {
        
PrintToChat(client,"Enabled");
    }
    
    if ( 
RankedMatch() == false )
    {
        
PrintToChat(client,"Disabled");
    }

Also, you can change native return type to boolean:
native bool RankedMatch();
__________________
Taking paid private requests! Contact me

Last edited by Cruze; 10-15-2022 at 04:36.
Cruze is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 10-15-2022 , 12:38   Re: How to create properly a native for a bool value?
Reply With Quote #3

Is it not exactly what i did ?
JLmelenchon is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 10-15-2022 , 14:28   Re: How to create properly a native for a bool value?
Reply With Quote #4

No, notice the red missing paranthesis after RankedMatch. You were calling it like variable instead of a function thus causing the error.

One thing I would personally change is to rename the native to IsRankedMatch and then later call it with if( IsRankedMatch() ).
If you use SM 1.11 (not sure if this was already a thing in 1.10) you can use any for the native callback. In the include you can then change it to bool instead of int.

Last edited by xerox8521; 10-15-2022 at 14:29.
xerox8521 is offline
BRU7US
Member
Join Date: Jul 2020
Location: Tatarstan, Kazan
Old 10-16-2022 , 07:04   Re: How to create properly a native for a bool value?
Reply With Quote #5

My way:

Code:

PHP Code:
bool RankedMatch false;

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
CreateNative("RankedMatch"Native_RankedMatch);
    
    
RegPluginLibrary("warmode");
    
    return 
APLRes_Success;
}

public 
any Native_RankedMatch(Handle pluginint numParams// "any" instead "int"
{
    return 
RankedMatch//or try "view_as<bool>(RankedMatch);"

Include:

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

native bool RankedMatch(); // "bool" instead "int"

public SharedPlugin __pl_warmode =
{
    
name "War mode",
    
file "warmode.smx",
#if defined REQUIRE_PLUGIN
    
required 1,
#else
    
required 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_warmode_SetNTVOptional()
{

    
MarkNativeAsOptional("RankedMatch");
}
#endif 
BRU7US is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 10-16-2022 , 08:38   Re: How to create properly a native for a bool value?
Reply With Quote #6

It works thank you. I just add to add a few more things to plugin2and remove RegPluginLibrary("reputation"); because it was not loading anymore.


#define warmode_AVAILABLE() (GetFeatureStatus(FeatureType_Native, "RankedMatch") == FeatureStatus_Available)

native void Native_RankedMatch();

Last edited by JLmelenchon; 10-16-2022 at 08:38.
JLmelenchon 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 06:59.


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