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

Natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 12-30-2023 , 02:25   Natives
Reply With Quote #1

How do I make native get, id, level, xp

PHP Code:
enum _:PlayerEnum
{
    
bool:pIsAuthorized,
    
bool:pIsConnected,
    
bool:pIsAuthenticated,
    
bool:pIsWaitingLoginAttemptResponse,
    
bool:pRegisterPlayerIfNotFound,
    
bool:pShowRegisterOption,

    
pName[MAX_NAME_LENGTH],
    
pAuthid[MAX_AUTHID_LENGTH],
    
pIP[MAX_IP_LENGTH],
    
pLogin[128],
    
pPassword[128],
    
pJoinedClanAtDate[12],
    
pInviteCode[MAX_INVITE_CODE_LENGTH],

    
pTemporaryClanName[MAX_CLAN_NAME_LENGTH],
    
pTemporaryClanTag[MAX_CLAN_TAG_LENGTH],

    
pClanId,
    
pClanPrivilegies,
    
pID,
    
pXP,
    
pKills,
    
pDeaths,
    
pCaptures,
    
pDefenses,
    
pPasswordLength,

    Array:
pNotifications,
}


enum _:ClanStatus
{
    
CLAN_STATUS_INACTIVE 0,
    
CLAN_STATUS_ACTIVE 1,
    
CLAN_STATUS_WAITING_APPROVAL 2,
    
CLAN_STATUS_DELETED 404,
}


enum _:ClanMemberEnum
{
    
CLAN_MEMBER_STATUS_INACTIVE 0,
    
CLAN_MEMBER_STATUS_ACTIVE 1,
}


enum _:ClanMemberPrivilegiesEnum
{
    
CLAN_MEMBER_PRIVILEGIES_MEMBER = (<< 1),
    
CLAN_MEMBER_PRIVILEGIES_INVITE = (<< 2),
    
CLAN_MEMBER_PRIVILEGIES_MANAGER = (<< 3),

    
CLAN_MEMBER_PRIVILEGIES_ALL = (
          
CLAN_MEMBER_PRIVILEGIES_MEMBER
        
CLAN_MEMBER_PRIVILEGIES_INVITE
        
CLAN_MEMBER_PRIVILEGIES_MANAGER
    
),
}


enum _:ClanEnum
{
    
cName[MAX_CLAN_NAME_LENGTH],
    
cTag[MAX_CLAN_TAG_LENGTH],
    
cCreatedBy[MAX_NAME_LENGTH],
    
cDeletedBy[MAX_NAME_LENGTH],
    
cLastOwnerName[MAX_NAME_LENGTH],
    
cOwnerName[MAX_NAME_LENGTH],
    
cCreatedAt[11],
    
cDeletedAt[11],
    
    
cId,
    
cOwnerId,
    
cCreatorId,
    
cMembersCount,
    
cStatus,
    
cAcumulatedPlayersXP,
    
cLevel,

    Array:
cMembers,
}


public 
Player[MAX_PLAYERS 1][PlayerEnum];
public Array:
Clans;
public 
Trie:InviteCodes;

public 
cvarAuthenticationType;
public 
cvarMaxMembersPerClan;
public 
cvarInviteCodeExpireDays;
public 
cvarInviteCodeAutoClose;
public 
cvarClanPrefixAtNames;
public 
cvarXPGapBetweenLevels;
public 
cvarXPEarnedPerDeaths;
public 
cvarXPEarnedPerKills;
public 
cvarXPExtraEarnedPerHeadshot;
public 
cvarXPExtraEarnedPerGrenades;
public 
cvarXPExtraEarnedPerMelee;
public 
cvarMinimumRequiredXPToCreateAClan;




enum _:QueryDataEnum
{
    
qPlayerId,
    
qOtherId
}

public 
Query[2048];

public 
bool:isPluginRunningOnDebugMode
yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 12-30-2023 , 03:21   Re: Natives
Reply With Quote #2

Code:
#include <amxmodx> enum _:PlayerEnum {     pClanId,     pClanPrivilegies,     pID,     pXP,     pKills,     pDeaths,     pCaptures,     pDefenses,     pPasswordLength, } public Player[MAX_PLAYERS + 1][PlayerEnum]; public plugin_init() {} public plugin_natives() {     register_native("get_pid", "native_get_pid"); } /*expecting to use the native as follows where index = player index const userPID = get_pid(index) if(userPID == -1) {     server_print("invalid index") } if(userPID == -1) {     server_print("not connected") } */ #define is_valid(%0) (0 < %0 < 33) public native_get_pid(const iPluginID, const iParams) {     new const id = get_param(1)     if(!is_valid(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -1     }     if(!is_user_connected(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -2        }     return Player[id][pID] }

also, you could share the enum in a .inc file that it's included in both plugins to not create a different native for every PlayerEnum data

Code:
// get_info(id, PlayerEnum:peData) public _:native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const data = get_param(2)     if(!is_valid(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -1;     }     if(!is_user_connected(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -2;        }     return Player[id][data]; }

in the plugin that call the native you must declare it (in a .inc file or in plugin)

Code:
native native_name(params);

detailed tutorial: https://forums.alliedmods.net/showthread.php?t=41251

anyways, it's a good practice to do the checks before you call the native and set the native return value as a PlayerEnum value

Code:
// new const PlayerEnum:pdata = PlayerEnum:get_info(id, PlayerEnum:pClanId) public native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const PlayerEnum:data = PlayerEnum:get_param(2)     return Player[id][_:data]; }

in this way you will keep your code more readable

because you used the untag keyword to define the PlayerEnum, when retrieving the data in return statement in the native you need to untag de data variable or to not tag it with PlayerEnum

Code:
public native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const data = get_param(2)     return Player[id][data]; }

in this way you will get rid of the tag mismatch warning when compiling

Last edited by lexzor; 12-30-2023 at 03:31.
lexzor is offline
yagami
Senior Member
Join Date: Jan 2021
Old 12-30-2023 , 11:22   Re: Natives
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
Code:
#include <amxmodx> enum _:PlayerEnum {     pClanId,     pClanPrivilegies,     pID,     pXP,     pKills,     pDeaths,     pCaptures,     pDefenses,     pPasswordLength, } public Player[MAX_PLAYERS + 1][PlayerEnum]; public plugin_init() {} public plugin_natives() {     register_native("get_pid", "native_get_pid"); } /*expecting to use the native as follows where index = player index const userPID = get_pid(index) if(userPID == -1) {     server_print("invalid index") } if(userPID == -1) {     server_print("not connected") } */ #define is_valid(%0) (0 < %0 < 33) public native_get_pid(const iPluginID, const iParams) {     new const id = get_param(1)     if(!is_valid(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -1     }     if(!is_user_connected(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -2        }     return Player[id][pID] }

also, you could share the enum in a .inc file that it's included in both plugins to not create a different native for every PlayerEnum data

Code:
// get_info(id, PlayerEnum:peData) public _:native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const data = get_param(2)     if(!is_valid(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -1;     }     if(!is_user_connected(id))     {         log_error(AMX_ERR_NATIVE, "The given index is not a valid player entity [%i]", id);         return -2;        }     return Player[id][data]; }

in the plugin that call the native you must declare it (in a .inc file or in plugin)

Code:
native native_name(params);

detailed tutorial: https://forums.alliedmods.net/showthread.php?t=41251

anyways, it's a good practice to do the checks before you call the native and set the native return value as a PlayerEnum value

Code:
// new const PlayerEnum:pdata = PlayerEnum:get_info(id, PlayerEnum:pClanId) public native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const PlayerEnum:data = PlayerEnum:get_param(2)     return Player[id][_:data]; }

in this way you will keep your code more readable

because you used the untag keyword to define the PlayerEnum, when retrieving the data in return statement in the native you need to untag de data variable or to not tag it with PlayerEnum

Code:
public native_get_info(const iPluginID, const iParams) {     new const id = get_param(1)     new const data = get_param(2)     return Player[id][data]; }

in this way you will get rid of the tag mismatch warning when compiling

I already have one made here for the clan name, but I was confused about how to do the same

PHP Code:
@get_user_clan_tag(pluginIdparams)
{
    new 
clan[ClanEnum];
    new 
id get_param(1);
    
    if (!
is_user_connected(id) || !Player[id][pIsAuthenticated])
    {
        return 
set_string(2""charsmax(clan[cTag]));
    }

    new 
clanId Player[id][pClanId];

    if (!
clanId)
    {
        return 
set_string(2""charsmax(clan[cTag]));
    }

    if (!
getClanInfo(clanIdclan))
    {
        return 
set_string(2""charsmax(clan[cTag]));
    }

    return 
set_string(2clan[cTag], charsmax(clan[cTag]));

yagami is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-31-2023 , 17:48   Re: Natives
Reply With Quote #4

There is a tutorial for creating your own natives.
__________________
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 03:08.


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