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