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

Solved Plugin API - How can transfer data properly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-19-2018 , 03:30   Plugin API - How can transfer data properly
Reply With Quote #1

Hello,

I would like to make a unique admin system for myself with some plus functions that are not in the original AmxModX admin system.
I tried to make a core plugin that only connect to database, put and get datas from it.

I made a structure to store all data.
In core plugin it looks like this:
Code:
enum _:ExampleType
{
    Array1[44],
    Array2[44],
    Array3[32],
    Array4[11],
    Array5[11],	
    Array6[32],
    Array7[64]
}

new g_ExampleList[][ExampleType]; //g_ExampleList[StoredAdmins][ExampleType]
I would like to transfer this structure and the stored data between the core and the other plugins of the system.

My question is how can I do this properly?

I read some tutorial about Xvars, dynamic natives and fake forwards, but I do this on the first time, so I am a bit embarrassed.
Make an array or "stuct" public for use as xvar is not possible in amxmodx, if I know right.
I could make the data transfer for array: I defined this struct in the second plugin and I can send the variables from the struct one by one to the second plugin by set_string function.
Can I transfer the complete struct to the second plugin with only one native call or I have to make it as I mentioned above (may with more params and more set_string func to do it with one call)?
I checked set_array, but it can not handle 2d (or more) arrays. I found only this thread about this:
https://forums.alliedmods.net/showthread.php?t=139495

I welcome any advice.

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

Use CellArray, you might not be able to pass more than 1 array dimension in a native.
__________________
edon1337 is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-19-2018 , 06:01   Re: Plugin API - How can transfer data properly
Reply With Quote #3

I read roughly Hamlet's Dynamic Array tutorial at the late nitht yesterday, but I decided to skip the use of CellArray, it looked a bit more complicated in first time, but thanks for the advice I will read it more carefully again.

This parts is a bit confused me:
Code:
new Data[ eData ] 
    new const szConst[] = "test"
    copy( Data[ szString ], charsmax( Data ), szConst )
    Data[ iValue ] = 15
    //Push the array into our array
    ArrayPushArray( g_aArray, Data )
In the copy function the charsmax parts seems not correct for me. It get the complete Data array size included the iValue size. The correct way would be charsmax(Data[szString]) right?
In first time I tought to get the arrays sizes inside an array be more complicated.


So returning to this topic, if I create a dyn array I can set its value from a native with set_array?

Last edited by Hembi; 08-19-2018 at 06:27. Reason: szConst -> szString
Hembi is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 06:05   Re: Plugin API - How can transfer data properly
Reply With Quote #4

Quote:
Originally Posted by Hembi View Post
The correct way would be charsmax(Data[szConst]) right?
No,
PHP Code:
charsmaxDataszString ] ) 
Here's how your enum should look like:
PHP Code:
enum _:eData
{
    
szString32 ],
    
iValue
}; 
You retrieve the string that holds the data (usually seen in enum), not the string that you're trying to set.
__________________

Last edited by edon1337; 08-19-2018 at 06:06.
edon1337 is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-19-2018 , 06:13   Re: Plugin API - How can transfer data properly
Reply With Quote #5

Oh I am blind, I thought what you write. I write szConst by mistake, the enum first array name what I thought. So the example is wrong in the tutorial.


What's about my last question in my previous post?

Last edited by Hembi; 08-19-2018 at 06:18. Reason: I see it now.
Hembi is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 06:29   Re: Plugin API - How can transfer data properly
Reply With Quote #6

Quote:
Originally Posted by Hembi View Post
Oh I am blind, I thought what you write. I write szConst by mistake, the enum first array name what I thought. So the example is wrong in the tutorial.


What's about my last question in my previous post?
Actually I was wrong it should be just
PHP Code:
charsmaxData 
Quote:
Originally Posted by Hembi View Post
In the copy function the charsmax parts seems not correct for me. It get the complete Data array size included the iValue size.
That's how it should be.

About your other question, I don't really get what you meant, could you explain?
__________________
edon1337 is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-19-2018 , 06:48   Re: Plugin API - How can transfer data properly
Reply With Quote #7

Why just Data?
In Hamlet example he copy the text to Data[szString] so you need the max character num of this array which is 49, because it is szString[50] in enum.
The charsmax( Data ) return the size-1 of the struct(complete enum) which is 50 (szString -> 50, iValue -> 1) and it can be caused an index out of bounds error, if you try to copy more than 49 char.

My other question was about the CellArray use with native.
I create a native in core which contain set_array(whichparam, array, charsmax(array));
In the second plugin I create a dyn array, then I call my native with the array in params.
For example:
Code:
new Array: g_Array; //DynArr
public test()
{
  call_examplenative(g_Array); //example native call
}
I do not tested this yet, but this works and can I transfer the datas in this way?

Last edited by Hembi; 08-19-2018 at 06:49.
Hembi is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 06:53   Re: Plugin API - How can transfer data properly
Reply With Quote #8

Quote:
Originally Posted by Hembi View Post
Why just Data?
In Hamlet example he copy the text to Data[szString] so you need the max character num of this array which is 49, because it is szString[50] in enum.
The charsmax( Data ) return the size-1 of the struct(complete enum) which is 50 (szString -> 50, iValue -> 1) and it can be caused an index out of bounds error, if you try to copy more than 49 char.
PHP Code:
native copy(dest[],len,const src[]); 
It requires the destination length, not destination buffer length.
Quote:
Originally Posted by Hembi View Post
My other question was about the CellArray use with native.
I create a native in core which contain set_array(whichparam, array, charsmax(array));
In the second plugin I create a dyn array, then I call my native with the array in params.
For example:
Code:
new Array: g_Array; //DynArr
public test()
{
  call_examplenative(g_Array); //example native call
}
I do not tested this yet, but this works and can I transfer the datas in this way?
You did not provide any code, so I can't say whether it will work, CellArray can be used anywhere, it doesn't matter where.
__________________
edon1337 is offline
Hembi
Member
Join Date: Mar 2013
Location: Hungary
Old 08-19-2018 , 08:23   Re: Plugin API - How can transfer data properly
Reply With Quote #9

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.

Last edited by Hembi; 08-19-2018 at 08:24.
Hembi is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-19-2018 , 08:33   Re: Plugin API - How can transfer data properly
Reply With Quote #10

Quote:
Originally Posted by Hembi View Post
My question is that how can I send the datas from the CellArray what I created, trought the plugins.
You asked a question that can't be answered without having more information about it.
Isn't it obvious already? By Dynamic Natives of course.

Code:
new Array: g_Array; //DynArr
public test()
{
  call_examplenative(g_Array); //example native call
}
If your purpose is to call something with that example, that is WRONG. You should start by telling what you're trying to achieve, otherwise we can't help you.
__________________

Last edited by edon1337; 08-19-2018 at 08:36.
edon1337 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 04:28.


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