AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved get_array_byref? (https://forums.alliedmods.net/showthread.php?t=321437)

redivcram 02-10-2020 16:44

get_array_byref?
 
This is a bit mind-boggling and I cannot find anything related to my issue. Is it even possible to refer arrays in dynamic/fake natives?

Bugsy 02-10-2020 17:56

Re: get_array_byref?
 
Can you show an example of what you're trying to accomplish?

redivcram 02-10-2020 19:13

Re: get_array_byref?
 
PHP Code:

// Plugin 1
public plugin_natives()
{
    
register_library("fakenatives");
    
    
register_native("FakeNative""_FakeNative");
}

public 
_FakeNative(iPluginiParams) {
    
    
// Do something to the parsed array?


I wanna use the native as such:
PHP Code:

// Plugin 2
new myArray[8];

FakeNative(myArray);

// Do something with the modified array. 

Basically what I said in the first post.

Bugsy 02-10-2020 19:23

Re: get_array_byref?
 
Here's an example setting string and an array
PHP Code:


#include <amxmodx>

public plugin_init()
{
    
register_plugin"String/Array in Dynamic Natives" "0.1" "bugsy" );
}

public 
plugin_natives()
{
    
register_library"bugsy_test" );
    
    
register_native"get_steam_id","_get_steam_id" );
    
register_native"get_random_nums","_get_random_nums" );
}

public 
_get_steam_idiPlugin iParams )
{
    new 
szTmpStr34 ];
    
    
get_user_authidget_param(1) , szTmpStr charsmaxszTmpStr ) );
    
set_stringszTmpStr get_param) );
}

public 
_get_random_numsiPlugin iParams )
{
    new 
iCount iNumbers10 ];
    
    
iCount get_param);
    
    if ( 
iCount 10 
        return -
1;
        
    for ( new 
iCount i++ )
    {
        
iNumbers] = random5000 );
    }
    
    
set_arrayiNumbers iCount );
    
    return 
iCount;


PHP Code:

#pragma reqlib "bugsy_test"

native get_steam_idid szDest[] , iMaxChars )
native get_random_numsiCount iDest[] ) 

The plugin
PHP Code:


#include <amxmodx>
#include <bugsytest>

new const VERSION[] = "0.1";

public 
plugin_init() 
{
    
register_plugin"Native test" VERSION "bugsy" );
    
    
register_clcmd"say string" "GetAuthID" );
    
register_clcmd"say array" "RandomNumbers" );
}

public 
GetAuthIDid 
{    
    new 
szSteamID33 ];
    
get_steam_idid szSteamIDcharsmaxszSteamID ) );
    
server_print"String value: %s" szSteamID );


public 
RandomNumbersid 
{    
    new 
iNumbers10 ];
    
get_random_numsiNumbers );
    
server_print"%d %d %d %d %d" iNumbers[0] , iNumbers[1] ,iNumbers[2] ,iNumbers[3] ,iNumbers[4] );



redivcram 02-15-2020 13:02

Re: get_array_byref?
 
Thanks! All seems to be working well for me.


All times are GMT -4. The time now is 13:45.

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