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

Solved First time creating natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 03-31-2021 , 22:51   First time creating natives
Reply With Quote #1

Hey, I am learning how to create natives and after reading the article on wiki I came up with this. Does it seem correct? At least it works but it doesn't necessarily mean that's it's 'smartly' done.

.inc file

Code:
/**
 * Check if a client has a certain admin flag.
 *
 * @param num1    a client.
 * @param num2    a flag.
 * @return        True if the client has the flag, false otherwise.
 */
 
 native bool CheckClientFlag(int client, char[] flag);
.sp file

Code:
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	CreateNative("CheckClientFlag", Native_FlagHelper);
	return APLRes_Success;
}

public any Native_FlagHelper(Handle plugin, int numParams)
{
	int client = GetNativeCell(1);
	char flag = view_as<int>(GetNativeCell(2));
	return(CheckCommandAccess(client, "", flag, true));
}
example

Code:
CheckClientFlag(client, "b");

Last edited by LiveAndLetDie; 04-04-2021 at 10:52.
LiveAndLetDie is offline
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 03-31-2021 , 23:08   Re: First time creating natives
Reply With Quote #2

And yes, I know that a native like that doesn't make much sense but it's just an example.
LiveAndLetDie is offline
Cruze
Veteran Member
Join Date: May 2017
Old 04-01-2021 , 01:31   Re: First time creating natives
Reply With Quote #3

PHP Code:
public any Native_FlagHelper(Handle pluginint numParams)
{
    
int client GetNativeCell(1);
    
char flag[5];
        
GetNativeString(2flag5);
    return(
CheckCommandAccess(client""ReadFlagString(flag), true));

Rest seem correct to me
__________________
Taking paid private requests! Contact me
Cruze is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-01-2021 , 19:45   Re: First time creating natives
Reply With Quote #4

FYI, it isn't safe (or sane) to pass an empty command string to CheckCommandAccess.
__________________
asherkin is offline
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 04-01-2021 , 21:59   Re: First time creating natives
Reply With Quote #5

Quote:
Originally Posted by Cruze View Post
PHP Code:
public any Native_FlagHelper(Handle pluginint numParams)
{
    
int client GetNativeCell(1);
    
char flag[5];
        
GetNativeString(2flag5);
    return(
CheckCommandAccess(client""ReadFlagString(flag), true));

Rest seem correct to me
Thanks!

Quote:
Originally Posted by asherkin View Post
FYI, it isn't safe (or sane) to pass an empty command string to CheckCommandAccess.
Why is that? Especially if one doesn't have a need to check overrides or commands.
LiveAndLetDie is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 04-01-2021 , 22:01   Re: First time creating natives
Reply With Quote #6

Quote:
Originally Posted by LiveAndLetDie View Post
Thanks!



Why is that? Especially if one doesn't have a need to check overrides or commands.
You can directly check if they have a certain flag through GetUserAdmin and checking if they have access to a certain flag.
ThatKidWhoGames 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 08:33.


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