Raised This Month: $ Target: $400
 0% 

How to use native for this ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 02-05-2015 , 05:43   How to use native for this ?
Reply With Quote #1

I want to return a value from one plugin which is using enums, when i'm using this native in other plugin, it returns badly values. Can you help me ?

PHP Code:
enum e_PlayerInfo {
    
PLAYER_NICK[33],
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
Float:PLAYER_LONG_JUMP_TIME,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
Float:PLAYER_LIGHTING_TIME,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS,
    
bool:PLAYER_VIP,
    
PLAYER_TARGET
}

new 
any:g_PlayerInfoMAX_PLAYER+][ e_PlayerInfo ]

....
register_native("exp_get_user_info""_get_user_info"1);
...
public 
any:_get_user_info(indexe_PlayerInfo:iInfo) {
    if(
is_user_connected(index))
        return 
g_PlayerInfo[index][iInfo]
    return 
0

.inc file:
PHP Code:
enum e_PlayerInfo {
    
NOTHING_0,
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
NOTHING_1,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
NOTHING_2,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS
}

native any:exp_get_user_info(indexe_PlayerInfo:iInfoType
and the plugin

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <expmod>

#define PLUGIN "Plugin"
#define VERSION "1.0"
#define AUTHOR "GT Team"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /test""test")
}

public 
test(id) {
    for(new 
1_:e_PlayerInfoi++)  {
        
client_print(id3"%d : %d"iexp_get_user_info(ide_PlayerInfo:i))
    }

and it returns random values:

PHP Code:
84
82
73
75
69
82
45
45
77
10 
99
11 
80
12 
114
13 
48
14 
32
15 
58
16 
68
17 
0
Welcome to Counter
-Strike
18 

Its definitly stupid. . Do i something wrong ?
grs4 is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-05-2015 , 07:57   Re: How to use native for this ?
Reply With Quote #2

1. pawn cannot return array ( unless there is pointer system i haven't heard about it )
as long as i know it can only return a cell what is 4 bytes ( can be int, can be float or any other what is 4byte )

My solution would be 2 natives.
One for floats or/and ints and the other one strings or/and arrays.
.Dare Devil. is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 02-05-2015 , 13:31   Re: How to use native for this ?
Reply With Quote #3

thanks for answer. If you can see, i speccialy do in .inc values: NOTHING_0, NOTHING_1. because i dont want that end-user would get values in string or float. It doesnt matter i think. Thanks for answer btw.

I'm waiting for other solutions ;) (sr 4 english)
grs4 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-05-2015 , 19:31   Re: How to use native for this ?
Reply With Quote #4

The data is not random STRIKER--McPr0 . This is doable, see below.

You will need to use the function according to the type of data you are trying to retrieve. Floats and strings are by-reference, while integers can be returned directly by the function.

Integer : exp_get_user_info( id , Item )
Float : exp_get_user_info( id , Item , FloatVariable )
String : exp_get_user_info( id , Item , StringVariable[] , MaxChars )

Output:
Code:
Integer value: 1234
Float value: 56.789001
String value: bugsy
nativetest.inc
PHP Code:
enum e_PlayerInfo 
{
    
PLAYER_NICK[33],
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
Float:PLAYER_LONG_JUMP_TIME,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
Float:PLAYER_LIGHTING_TIME,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS,
    
bool:PLAYER_VIP,
    
PLAYER_TARGET
}

native exp_get_user_infoid e_PlayerInfo:iInfoType , {Float,_}:... ); 
Other plugin:
PHP Code:
#include <amxmodx>

enum e_PlayerInfo {
    
PLAYER_NICK[33],
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
Float:PLAYER_LONG_JUMP_TIME,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
Float:PLAYER_LIGHTING_TIME,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS,
    
bool:PLAYER_VIP,
    
PLAYER_TARGET
}

const 
MAX_PLAYER 32;

new 
any:g_PlayerInfoMAX_PLAYER+][ e_PlayerInfo ];

public 
plugin_natives()
{
    
register_native"exp_get_user_info" "_get_user_info" );
}

public 
plugin_init() 
{
    
//Set test data to array
    
new id 0;
    
    
copyg_PlayerInfoid ][ PLAYER_NICK ] , charsmaxg_PlayerInfo[][ PLAYER_NICK ] ) , "bugsy" );
    
g_PlayerInfoid ][ PLAYER_LEVEL ] = 1234;
    
g_PlayerInfoid ][ PLAYER_LONG_JUMP_TIME ] = 56.789;
}

public 
_get_user_infoiPlugins iParams )
{
    new 
iPlayerID get_param);
    new 
iItem get_param);
    
    switch ( 
iParams )
    {
        case 
2: return g_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ];
        case 
3set_float_byrefg_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ] );
        case 
4set_stringg_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ] , get_param) );
    }
    
    return 
0;

Your plugin:
PHP Code:
#include <amxmodx>
#include <nativetest>

new const VERSION[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Native test" VERSION "bugsy" );
    
    
register_concmd"test" "test" );
}

public 
test() 
{    
    new 
id 0;
    
    
server_print"Integer value: %d" exp_get_user_infoid PLAYER_LEVEL ) );
    
    new 
Float:fTest;
    
exp_get_user_infoid PLAYER_LONG_JUMP_TIME fTest );
    
server_print"Float value: %f" fTest );

    new 
szNick33 ];
    
exp_get_user_infoid PLAYER_NICK szNick charsmaxszNick ) );
    
server_print"String value: %s" szNick );

__________________

Last edited by Bugsy; 02-05-2015 at 23:39.
Bugsy is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 02-06-2015 , 07:58   Re: How to use native for this ?
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
The data is not random STRIKER--McPr0 . This is doable, see below.

You will need to use the function according to the type of data you are trying to retrieve. Floats and strings are by-reference, while integers can be returned directly by the function.

Integer : exp_get_user_info( id , Item )
Float : exp_get_user_info( id , Item , FloatVariable )
String : exp_get_user_info( id , Item , StringVariable[] , MaxChars )

Output:
Code:
Integer value: 1234
Float value: 56.789001
String value: bugsy
nativetest.inc
PHP Code:
enum e_PlayerInfo 
{
    
PLAYER_NICK[33],
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
Float:PLAYER_LONG_JUMP_TIME,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
Float:PLAYER_LIGHTING_TIME,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS,
    
bool:PLAYER_VIP,
    
PLAYER_TARGET
}

native exp_get_user_infoid e_PlayerInfo:iInfoType , {Float,_}:... ); 
Other plugin:
PHP Code:
#include <amxmodx>

enum e_PlayerInfo {
    
PLAYER_NICK[33],
    
PLAYER_LEVEL,
    
PLAYER_EXP,
    
PLAYER_COINS,
    
PLAYER_POINTS,
    
PLAYER_ULTRA_POINTS,
    
PLAYER_MEGA_POINTS,
    
PLAYER_HEALTH,
    
PLAYER_SPEED,
    
PLAYER_GRAVITY,
    
PLAYER_MONEY,
    
PLAYER_DAMAGE,
    
PLAYER_LONG_JUMP,
    
Float:PLAYER_LONG_JUMP_TIME,
    
PLAYER_JUMPS,
    
PLAYER_INVISIBLE,
    
PLAYER_LIGHTING,
    
Float:PLAYER_LIGHTING_TIME,
    
PLAYER_STRENGHT,
    
PLAYER_RESPAWN,
    
PLAYER_CRITICAL,
    
PLAYER_FAST_STATS,
    
bool:PLAYER_VIP,
    
PLAYER_TARGET
}

const 
MAX_PLAYER 32;

new 
any:g_PlayerInfoMAX_PLAYER+][ e_PlayerInfo ];

public 
plugin_natives()
{
    
register_native"exp_get_user_info" "_get_user_info" );
}

public 
plugin_init() 
{
    
//Set test data to array
    
new id 0;
    
    
copyg_PlayerInfoid ][ PLAYER_NICK ] , charsmaxg_PlayerInfo[][ PLAYER_NICK ] ) , "bugsy" );
    
g_PlayerInfoid ][ PLAYER_LEVEL ] = 1234;
    
g_PlayerInfoid ][ PLAYER_LONG_JUMP_TIME ] = 56.789;
}

public 
_get_user_infoiPlugins iParams )
{
    new 
iPlayerID get_param);
    new 
iItem get_param);
    
    switch ( 
iParams )
    {
        case 
2: return g_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ];
        case 
3set_float_byrefg_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ] );
        case 
4set_stringg_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ] , get_param) );
    }
    
    return 
0;

Your plugin:
PHP Code:
#include <amxmodx>
#include <nativetest>

new const VERSION[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Native test" VERSION "bugsy" );
    
    
register_concmd"test" "test" );
}

public 
test() 
{    
    new 
id 0;
    
    
server_print"Integer value: %d" exp_get_user_infoid PLAYER_LEVEL ) );
    
    new 
Float:fTest;
    
exp_get_user_infoid PLAYER_LONG_JUMP_TIME fTest );
    
server_print"Float value: %f" fTest );

    new 
szNick33 ];
    
exp_get_user_infoid PLAYER_NICK szNick charsmaxszNick ) );
    
server_print"String value: %s" szNick );

you don't need to separate floats and integer, at least i haven't had any problems using same native for floats and its. Is there something i dont know about?
.Dare Devil. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-06-2015 , 18:13   Re: How to use native for this ?
Reply With Quote #6

Quote:
Originally Posted by .Dare Devil. View Post
you don't need to separate floats and integer, at least i haven't had any problems using same native for floats and its. Is there something i dont know about?
Of course you don't need to, Pawn only has a single data type which is a 4-byte cell so it's all the same. You can either do it how I have it, or tag the native with 'any:' in the .inc and you can return Floats as you do integers. I think my approach is cleaner, at the expense of an extra line of code when used.

If you prefer to return floats and int's the same way, make the following change(s):
PHP Code:
//In the inc., tag the native with any:
native any:exp_get_user_infoid e_PlayerInfo:iInfoType , {Float,_}:... );

//Optional: Remove the below line in the plugin containing the _get_user_info() native function. 
case 3set_float_byrefg_PlayerInfoiPlayerID ][ e_PlayerInfo:iItem ] ); 
__________________

Last edited by Bugsy; 02-06-2015 at 18:14.
Bugsy is offline
grs4
Senior Member
Join Date: Dec 2010
Location: Poland
Old 02-07-2015 , 16:50   Re: How to use native for this ?
Reply With Quote #7

I go check then reply an answer (sr for english, be friendly for poles xD)
grs4 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 02:30.


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