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

[SOLVED] Pass 2 dimensional array in native


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 11-09-2011 , 08:48   [SOLVED] Pass 2 dimensional array in native
Reply With Quote #1

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
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 11-10-2011 at 03:19.
drekes is offline
Send a message via MSN to drekes
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-09-2011 , 22:47   Re: Pass 2 dimensional array in native
Reply With Quote #2

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 ] );
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Old 11-09-2011, 22:56
nikhilgupta345
This message has been deleted by nikhilgupta345. Reason: nvrm
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 11-10-2011 , 03:18   Re: Pass 2 dimensional array in native
Reply With Quote #3

Okay. Thank you Emp`
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-10-2011 , 12:50   Re: [SOLVED] Pass 2 dimensional array in native
Reply With Quote #4

You can try this, if you need help just ask.

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

Last edited by Bugsy; 11-10-2011 at 12:53.
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-10-2011 , 23:24   Re: [SOLVED] Pass 2 dimensional array in native
Reply With Quote #5

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][ ] );
    }

__________________

Last edited by Bugsy; 11-10-2011 at 23:34.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 11-11-2011 , 05:28   Re: [SOLVED] Pass 2 dimensional array in native
Reply With Quote #6

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.
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
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 23:03.


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