Raised This Month: $ Target: $400
 0% 

By-ref bidimensional arrays in dynamic natives...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alexx109
Junior Member
Join Date: Jun 2010
Location: Brazil
Old 10-01-2010 , 19:48   By-ref bidimensional arrays in dynamic natives...
Reply With Quote #1

Kinda an impressive title. Indeed a seems-to-be-hard question...

If you have no knowledge about fake/dynamic natives ands its parameter-handling methods like set_* and get_* please do not post senseless or incertain code in this thread, although your opinion is surely welcomed...

Lets take by example the following dynamic native:

PHP Code:
native myNative(&integer_byrefstring[33][33]) 
This statement tells us that both our first and second parameters are passed by-reference (the & signal defines that in the first argument, and as the second argument is an array, its always passed by-ref)

So, in the native code:

PHP Code:
register_native("myNative""_myNative")
 
...
...
 
public 
_myNative(iPluginiArgs){
// After iPlugin and iArgs, arguments starts from 1, that's it beign our &integer_byref
// So, the second argument is the bidimensional array... 
to set the integer by-ref var i can simply use set_param_byref(1, value) (correct me if i'm wrong)...

if the second var were a normal string with a defined lenght of 5 (0 to 4) (char array) we could use set_string(2, "string", 4) or set_array(2, "string", 4) (again, correct me if i'm wrong)...

but, how to set a bidimensional array?

Hope I was clear enough...

Last edited by alexx109; 10-01-2010 at 19:51.
alexx109 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2010 , 21:30   Re: By-ref bidimensional arrays in dynamic natives...
Reply With Quote #2

Are you looking to populate the entire 2d array or just a particular index? Why not explain exactly what you're doing and maybe someone can suggest a solution?
__________________
Bugsy is offline
alexx109
Junior Member
Join Date: Jun 2010
Location: Brazil
Old 10-01-2010 , 22:19   Re: By-ref bidimensional arrays in dynamic natives...
Reply With Quote #3

Well i actually need to fill a dynamic part of the array...

The plugin that i'm actually working on is to retrieve the players number and each player name on a remote server through sockets...

This is the fake native that will automatically do that for me to use on future plugins...

The actuall fake native is this one:

native get_server_players_info(host[], port, &playersNum, players[33][33])

i've already did everything i needed, except for setting the players array with the players name i already got in a pls[33][33] var...
alexx109 is offline
alexx109
Junior Member
Join Date: Jun 2010
Location: Brazil
Old 10-01-2010 , 22:45   Re: By-ref bidimensional arrays in dynamic natives...
Reply With Quote #4

I'm starting to think it's impossible, check this:

set_array(param, const source[], size)
set_string(param, const source[], len)

both them got a source[] param, how can i be able to simply put a var[][] instead of a var[]... the answer is: i'm not able, it generates a Array dimensions do not match error...

I think i'll just stick all the names thogether in a huge string separating them by a char 0 (0xFF), null...

I'll post later on if this solved my problems... If you have any idea, please post on...
alexx109 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-01-2010 , 22:49   Re: By-ref bidimensional arrays in dynamic natives...
Reply With Quote #5

The prototype for all of those functions indicate only a 1-dimension array, you cannot pass a 2-dimension array.

This is just an example to show how you can populate a multi-dimension array manually. If you need further help to make it work with your plugin let me know.
PHP Code:
#include <amxmodx>

native GetName2Dint string33 ] );

const 
CELL_SIZE 4;

new 
szNames33 ][ 33 ];

public 
plugin_init()
{
    
register_plugin"Native 2D String Test" "0.1" "bugsy" );
}

public 
plugin_natives()
{
    
register_native"GetName2D" "_GetName2D" );
}

public 
client_authorizedid )
{
    
//You must always pass szNames[ 0 ] to the native. The position 
    //in the array is determined by the id passed as the first param.
    
GetName2Did szNames] );
    
    
//This will display the name that was just retrieved, using the
    //player id as the array index.
    
server_print"%s has Connected!" szNamesid ] );
}

public 
client_disconnectid )
{
    
server_print"%s has Disconnected!" szNamesid ] );
}

public 
_GetName2DiPlugin iArgs )
{
    new 
szName33 ] , iLen;
    new 
iParam1 get_param);
    new 
iParam2 get_param);
    new const 
iArrayPos = ( iParam2 + ( iParam1 * ( sizeofszNames[] ) * CELL_SIZE ) ) );
    
    
iLen get_user_nameiParam1 szName charsmaxszName ) );
    
    for ( new 
iCharPos iCharPos iLen iCharPos++ )
        
set_addr_valiArrayPos + ( iCharPos CELL_SIZE ) , szNameiCharPos ] );
            
    
set_addr_valiArrayPos + ( iLen CELL_SIZE ) , EOS );

__________________

Last edited by Bugsy; 10-02-2010 at 00:50.
Bugsy 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 14:21.


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