[Plugin] Char array returnen
#1

How to return a string (in func it is a char array)
Reply
#2

How to return a string (in func it is a char array)
Reply
#3

Need help
Reply
#4

Need help heh?
Then, please, write your topic in English, so we can assist you.
Reply
#5

How to return a string (in func it is a char array)
Reply
#6

You can only post in english here, update your topic.
Reply
#7

Done. Searching for help:How to return a string (in func it is a char array)
Reply
#8

I noticed the explicit "no c/c++ support here" rule is gone.

To return a string/array you would retrieve the address of the array passed by the script, and then just write into that referenced array. The plugin SDK provides the functions needed for that.
Take a look e.g. at the vector plugin (or any other plugin that can return strings):

pawn Код:
native cvector_get_arr(vector, index, destination[], len=sizeof(string));

cell AMX_NATIVE_CALL CVectorNatives::get_arr(AMX* amx, cell* params){
    cell pawnid = params[1];
    cell elem = params[2];
    if (!sdk_is_vector_exists(amx,pawnid) || !sdk_is_exists(amx,pawnid,elem))
        return -1;
   
    if (local_vectors[amx][pawnid].get_type(elem) != 0)
        return -2;

    // Relevant part starts here
    cell* addr = NULL;  // Get the address of the destination array
    amx_GetAddr(amx,params[3],&addr);
    cell size = params[4];  // Get the size of the destination array
    // ...
    amx_SetString(addr,some_string,0,0,size); // write some_string into the destination array to return it to pawn
    return 1;
}
Reply
#9

Sry i am new but this was my first opinon but then the vector didnt bring anything cauz you hafe a buffer with a defined size but i want a direct return so at the end i can place it for ex in SendClientMessage
Reply
#10

Afaik a plugin native can only return a single pawn cell, I havent seen a plugin native with a true string return. Better just use the reference way, its better style anways. If you really need direct return you could still wrap it in a pawn function, just like people sometimes do for GetPlayerName.
Reply
#11

But then a char vector is never possible or ? Because you ever need a buffer which have a defined size
Reply
#12

At least in pawn it isnt possible, because after all youll always end up with a fixed-size array.
You can have a char vector in a plugin, but when returning it to pawn youll also have to write it into an array with fix size.
Reply
#13

How to wrap it without an array in pawn ?
Reply
#14

pawn Код:
stock GetDirectArrayReturn() {
    new array[ARRAY_SIZE];
    Native_GetSomeArray(array);
    return array;
}
Something like that. Its pretty pointless to do that, but a many people do it anyways, just to safe that one line of code.
Reply
#15

Strings (arrays) in PAWN are basicly references of 32 bit array objects, so you have to allocate that array in your plugin and return its reference.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)