AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Pass 2 dimensional array in native (https://forums.alliedmods.net/showthread.php?t=171688)

drekes 11-09-2011 08:48

[SOLVED] Pass 2 dimensional array in native
 
I'm trying to find random origins using Joropito's random location generator & pass those locations to calling plugins. But i can't find out how to pass multi-dimensional arrays using natives.

native function:
PHP Code:

public _find_ent_spawns(iPluginsiParams)
{
    new 
FloatflOrigins[MAX_ORIGINS][3]
        , 
i
    
;
        
    while(
i++ < MAX_ORIGINS)
    {
        if(!
SsGetOrigin(flOrigins[i]))
            break;
    }
    
    
// set_param_byref(1, flOrigins);
    // set_array_f(1, flOrigins, sizeof(flOrigins));
    
    
return i;


Calling plugin:
PHP Code:


if(cmd_access(idiLeveliCid1))
{
    new 
FloatflOrigins[MAX_ORIGINS][3]
        , 
iSpawns os_get_ent_spawns(flOrigins)
    ;
        
    
// Unfinished: Create entities & set them to spawns.
    // Write spawns to file.
        
    
log_amx("Found %s spawn points."iSpawns);        
}
    
return 
PLUGIN_HANDLED


Emp` 11-09-2011 22:47

Re: Pass 2 dimensional array in native
 
You might not be able to send more than a single dimension through the fake natives.

What I would suggest you do instead would be to have a native for how many spawns were created, and then a second for getting a specific spawn.

eg:
Code:

new flOrigins[MAX_ORIGINS][3];
new iMaxSpawns = min( sizeof flOrigins, os_get_spawn_count() );
for ( new i; i < iMaxSpawns; i++ )
{
    os_get_ent_spawn( i, flOrigins[ i ] );
}


drekes 11-10-2011 03:18

Re: Pass 2 dimensional array in native
 
Okay. Thank you Emp`

Bugsy 11-10-2011 12:50

Re: [SOLVED] Pass 2 dimensional array in native
 
You can try this, if you need help just ask.

http://forums.alliedmods.net/showthread.php?t=139495

Bugsy 11-10-2011 23:24

Re: [SOLVED] Pass 2 dimensional array in native
 
I know that you solved your problem with Emps solution but I was bored and decided to do it anyway. This will read the TestFloats array into flOrigins through the native function. Not the prettiest thing in the world for referencing the origins since you are using a 1-dimension array and doing everything manually but that can probably be cleaned up with macros.

PHP Code:


#include <amxmodx>

const MAX_ORIGINS 5;
const 
ORIGIN_SIZE 3;

new 
Float:TestFloatsMAX_ORIGINS ][ ORIGIN_SIZE ] = 
{
    { 
1.2 3.4 5.6 },
    { 
2.1 4.2 6.5 },
    { 
1.1 2.2 3.3 },
    { 
4.4 5.5 6.6 },
    { 
7.7 8.8 9.9 }
};

native os_get_ent_spawnsFloat:fOrigins[] , iSize );

public 
plugin_natives()
{
    
register_native"os_get_ent_spawns" "_find_ent_spawns" );
}

public 
plugin_init() 
{
    
register_plugin"Get Native Float Array" "0.1" "bugsy" );
    
    
register_concmd"t" "Test" );
}

public 
Test( )
{
    new 
Float:flOriginsMAX_ORIGINS ORIGIN_SIZE ];
    
os_get_ent_spawnsflOrigins MAX_ORIGINS );
    
    for ( new 
MAX_ORIGINS i++ )
    { 
        
server_print"Origin%d = %f %f %f" i+flOrigins[ ( ORIGIN_SIZE ) + ] , flOrigins[ ( ORIGIN_SIZE ) + ] , flOrigins[ ( ORIGIN_SIZE ) + ] );
    }
}

public 
_find_ent_spawnsiPlugins iParams )
{
    const 
CELL_SIZE 4;
    const 
ORIGIN_CELL_SIZE ORIGIN_SIZE CELL_SIZE;
    
    new 
iVar get_param);
    new 
iMax get_param);

    for ( new 
iMax i++ )
    {
        
set_addr_valiVar + ( ORIGIN_CELL_SIZE ) + ( CELL_SIZE ) , _:TestFloats][ ] );
        
set_addr_valiVar + ( ORIGIN_CELL_SIZE ) + ( CELL_SIZE ) , _:TestFloats][ ] );
        
set_addr_valiVar + ( ORIGIN_CELL_SIZE ) + ( CELL_SIZE ) , _:TestFloats][ ] );
    }



drekes 11-11-2011 05:28

Re: [SOLVED] Pass 2 dimensional array in native
 
I've looked at your previous post too but i have a hard time understanding how they both work.

I'm using Emp's solution now also because i can get just 1 free origin instead of filling an entire array everytime.


All times are GMT -4. The time now is 14:21.

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