Raised This Month: $32 Target: $400
 8% 

Solved Plugin API - How can transfer data properly


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-19-2018 , 10:14   Re: Plugin API - How can transfer data properly
Reply With Quote #11

Quote:
Originally Posted by Hembi View Post
I made a theroretical question about dyn natives. Does not need other codes than I provided. I can make an example if necessary.
My question is that how can I send the datas from the CellArray what I created, trought the plugins.
Pass the array handle through the native(as an integer). Then retieve the handle where you need and use the Array natives as usual.
__________________
HamletEagle is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-20-2018 , 19:56   Re: Plugin API - How can transfer data properly
Reply With Quote #12

Quote:
Originally Posted by HamletEagle View Post
Pass the array handle through the native(as an integer). Then retieve the handle where you need and use the Array natives as usual.
I would have to see this answer. Thank you!
I would like to ask you how can I set the values in the array what I get from the second plugin.

Example:

#1 core plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

enum _:ExampleType
{
    String1[44],
    String2[44],
    String3[32],
    String4[11],
    String5[11],	
    String6[32],
    String7[64]
}

new Array:g_ExampleArrayCore;

public plugin_init()
{
	g_ExampleArrayCore = ArrayCreate( ExampleType);

	new tempArray[ExampleType];
        //Here put some data to this array.

        ArrayPushArray( g_ExampleArrayCore, tempArray );
}

public plugin_natives()
{
    register_library("inc_example");
    
    register_native("native_transf_array","_native_transf_array"); //Register it with style 0
}

public plugin_end()
{
	ArrayDestroy( g_ExampleArrayCore );
}

public _native_transf_array(iPlugin, iParams)
{
      //How can I set the array what get as param?
      //I would like to put all data from g_ExampleArrayCore to g_ExampleArraySecond
      //I did this with set_string(2, string, len) when I tried this transfer with a normal string array
}
#2 second plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <inc_example>

enum _:ExampleType
{
    String1[44],
    String2[44],
    String3[32],
    String4[11],
    String5[11],	
    String6[32],
    String7[64]
}

new Array:g_ExampleArraySecond;

public plugin_init()
{
	g_ExampleArraySecond = ArrayCreate( ExampleType );
	register_srvcmd("test", "test");
}

public test()
{
	native_transf_array(g_ExampleArraySecond);
	
	new tempArray[ExampleType];
	ArrayGetArray(g_ExampleArraySecond, 0, tempArray);
	
	log_amx("TEST: %s", tempArray[String1]);
}
inc_example.inc:
Code:
#pragma reqlib "inc_example"

native native_transf_array(Array:dynarray);

Last edited by Hembi; 08-21-2018 at 18:16.
Hembi is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-21-2018 , 03:46   Re: Plugin API - How can transfer data properly
Reply With Quote #13

PHP Code:
public plugin_natives()
{
    
register_library("inc_example");
    
    
register_native("native_transf_array","_native_transf_array"); //Register it with style 0
}

public 
plugin_end()
{
    
ArrayDestroyg_ExampleArrayCore );
}

public 
_native_transf_array(iPluginiParams)
{     
     new 
iArrayHandle get_param);
     new 
iItem get_param);
     new 
iLen get_param);
     
     new 
szValue16 ];
     
get_string3szValueiLen );
          
     
ArraySetStringiArrayHandleiItemszValue );


Code:
native native_transf_array( const iArrayHandle, const iItem, const szInput[ ], const iLen )
__________________

Last edited by edon1337; 08-21-2018 at 03:49.
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-21-2018 , 05:29   Re: Plugin API - How can transfer data properly
Reply With Quote #14

what Hamlet suggested he meant to pass the array handler index to the other plugin by using a native.

PHP Code:
new Array:iHandler_array;

@
plugin_natives() {
         
iHandler_array ArrayCreate(size);

        
register_native("get_array_handler""_get_array_handler");
}

public 
_get_array_handler(pluginargs)
{
       return 
iHandler_array;

And here is the native to use in the other plugins.

PHP Code:
native Array:get_array_handler() 
And now you can apply the array public natives on the handler (ArraySetCell, etc....)
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-21-2018 at 05:33.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-21-2018 , 07:20   Re: Plugin API - How can transfer data properly
Reply With Quote #15

Quote:
Originally Posted by Natsheh View Post
what Hamlet suggested he meant to pass the array handler index to the other plugin by using a native.

PHP Code:
new Array:iHandler_array;

@
plugin_natives() {
         
iHandler_array ArrayCreate(size);

        
register_native("get_array_handler""_get_array_handler");
}

public 
_get_array_handler(pluginargs)
{
       return 
iHandler_array;

And here is the native to use in the other plugins.

PHP Code:
native Array:get_array_handler() 
And now you can apply the array public natives on the handler (ArraySetCell, etc....)
Why pass the array index when you can directly set the value?
__________________

Last edited by edon1337; 08-21-2018 at 07:20.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-21-2018 , 07:36   Re: Plugin API - How can transfer data properly
Reply With Quote #16

Quote:
Originally Posted by edon1337 View Post
Why pass the array index when you can directly set the value?
Because you may want to do multiple operations on the array(destroy/clear/deleting items, etc). Passing only the handle gives more flexibility.
__________________
HamletEagle is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-21-2018 , 18:02   Re: Plugin API - How can transfer data properly
Reply With Quote #17

Quote:
Originally Posted by Natsheh View Post
what Hamlet suggested he meant to pass the array handler index to the other plugin by using a native.

PHP Code:
new Array:iHandler_array;

@
plugin_natives() {
         
iHandler_array ArrayCreate(size);

        
register_native("get_array_handler""_get_array_handler");
}

public 
_get_array_handler(pluginargs)
{
       return 
iHandler_array;

And here is the native to use in the other plugins.

PHP Code:
native Array:get_array_handler() 
And now you can apply the array public natives on the handler (ArraySetCell, etc....)
Thank you, I tried to do this at the first time (after Hamlet suggested it) in this way as you wrote, but I got a "Tag mismatch" compiler error, because the return type is an array.

I could fix this error in this way for example in your code:
Code:
public Array:_get_array_handler(plugin, args)
{
       return iHandler_array;
}
Here is the compete code what I needed, may it will be useful for someone later:

1# core plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

enum _:ExampleType
{
    String1[44],
    String2[44],
    String3[32],
    String4[11],
    String5[11],	
    String6[32],
    String7[64]
}

new Array:g_ExampleArrayCore;

public plugin_init()
{
	g_ExampleArrayCore = ArrayCreate( ExampleType );

	new tempArray[ExampleType];
        //Here put some data to this array. For Example:
        //formatex(tempArray[String1], charsmax(tempArray[String1]), "putsometexthere");

        ArrayPushArray( g_ExampleArrayCore, tempArray );
}

public plugin_natives()
{
    register_library("inc_example");
    
    register_native("native_transf_array","_native_transf_array"); //Register it with style 0
}

public plugin_end()
{
	ArrayDestroy( g_ExampleArrayCore );
}

public Array:_native_transf_array(iPlugin, iParams)
{
        return g_ExampleArrayCore;
}
#2nd plugin:
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <inc_example>

enum _:ExampleType
{
    String1[44],
    String2[44],
    String3[32],
    String4[11],
    String5[11],	
    String6[32],
    String7[64]
}

new Array:g_ExampleArraySecond;

public plugin_init()
{
	g_ExampleArraySecond = ArrayCreate( ExampleType );
	register_srvcmd("test", "test");
}

public plugin_end()
{
	ArrayDestroy( g_ExampleArraySecond );
}

public test()
{
	g_ExampleArraySecond = native_transf_array();
	
	new tempArray[ExampleType];
	ArrayGetArray(g_ExampleArraySecond, 0, tempArray);
	
	log_amx("Print String1 from the array: %s", tempArray[String1]);
}
inc_example.inc:
Code:
#pragma reqlib "inc_example"

native Array:native_transf_array();

Thank you so much for the information and help guys!

Last edited by Hembi; 08-21-2018 at 18:17.
Hembi is offline
Reply


Thread Tools
Display Modes

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 19:47.


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