AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   How to create properly a native for a bool value? (https://forums.alliedmods.net/showthread.php?t=339981)

JLmelenchon 10-14-2022 22:39

How to create properly a native for a bool value?
 
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");
    }
}


Cruze 10-15-2022 04:35

Re: How to create properly a native for a bool value?
 
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();

JLmelenchon 10-15-2022 12:38

Re: How to create properly a native for a bool value?
 
Is it not exactly what i did ?

xerox8521 10-15-2022 14:28

Re: How to create properly a native for a bool value?
 
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.

BRU7US 10-16-2022 07:04

Re: How to create properly a native for a bool value?
 
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 


JLmelenchon 10-16-2022 08:38

Re: How to create properly a native for a bool value?
 
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();


All times are GMT -4. The time now is 01:02.

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