03.12.2015, 11:18
[Tutorial] Plugin development guide
03.12.2015, 11:37
Add HAVE_STDINT_H preprocessor definition to your project settings and try recompile again.
03.12.2015, 11:45
02.02.2016, 18:45
It's possible to pass variable by reference to callback?
I would like to do something like this to call a callback from plugin, and get them after function call.
public OnPlayerDoSomething(playerid ¶m1, ¶m2, ¶m3)
{
if(param1 > 10) param1 = 15;
param2 = 0;
return 1;
}
I would like to do something like this to call a callback from plugin, and get them after function call.
public OnPlayerDoSomething(playerid ¶m1, ¶m2, ¶m3)
{
if(param1 > 10) param1 = 15;
param2 = 0;
return 1;
}
02.02.2016, 20:17
Of course (that's how strings are passed), just make sure to place them on the heap (unlike some samp callbacks...).
13.02.2016, 15:20
My dick is out of with this fucking AMX. I've tried to do this what I mentioned before, for first argument it works, but for more not.
My code
Printed result should be:
szőrцs fasz 0, 2000
But it:
szőrцs fasz 0, 150 <- setting second parameter doesn't work
Any ideas how to solve this problem?
My code
Printed result should be:
szőrцs fasz 0, 2000
But it:
szőrцs fasz 0, 150 <- setting second parameter doesn't work
pawn Код:
void CCallbackManager::OnPlayerClientGameInit(WORD playerid, bool* limitglobalchat, float* globalchatradius, float* nametagdistance, bool* disableenterexits)
{
int idx = -1;
cell ret = 1;
for (std::vector<AMX*>::const_iterator iter = m_vecAMX.begin(); iter != m_vecAMX.end(); ++iter)
{
if (!amx_FindPublic(*iter, "OnPlayerClientGameInit", &idx))
{
cell addr = NULL, amx_addr, *phys_ptr;
cell data[2];
data[0] = static_cast<cell>(*limitglobalchat);
data[1] = static_cast<cell>(*globalchatradius);
//data[2] = amx_ftoc(*nametagdistance);
//data[3] = static_cast<cell>(*disableenterexits);
amx_PushArray(*iter, &amx_addr, &phys_ptr, data, 2);
//*globalchatradius = reinterpret_cast<cell*>(phys_ptr);
//cell limitglobalchat_ = 1;
//amx_PushArray(*iter, &amx_addr, &phys_ptr, reinterpret_cast<cell*>(&limitglobalchat), 1);
//amx_PushString(*iter, &addr, NULL, str.c_str(), NULL, NULL);
amx_Push(*iter, static_cast<cell>(playerid));
amx_Exec(*iter, &ret, idx);
amx_Release(*iter, amx_addr);
//*limitglobalchat = !!*phys_ptr;
logprintf("szőrцs fasz %d, %d", phys_ptr[0], phys_ptr[1]);
//logprintf("globalchat: %d, %f", *limitglobalchat, *globalchatradius);
}
}
}
forward OnPlayerClientGameInit(playerid, &limitglobalchat, &globalchatradius);
public OnPlayerClientGameInit(playerid, &limitglobalchat, &globalchatradius)
{
limitglobalchat = 0;
globalchatradius = 2000;
// nametagdistance = -50.2;
// disableenterexits = false;
printf("lуfasz - %d", limitglobalchat);
}
13.02.2016, 15:46
You should use PushArray with singleton array two times (once for each variable).
PushArray will allocate memory for your 2-element array in the heap. Your callback will receive the 'whole array' in limitglobalradius argument but since its just a reference variable not an array, only the first element of the array which you pushed will be pointed by limitglobalchat.
I don't even know what globalchatradius would be point to. The issue is globalchatradius doesn't take up the 2nd index of the array which you passed because of which you are not getting expected results.
Its intuitive that globalchatradius would be pointing to the very next set of 4 bytes after limitglobalchat. The reference variables are modified using SREF.S ([[FRM + offset]] = PRI). So [[]]? How can you say that the arguments are pointing to cells which are next to each other?
I doubt if using PushArray wiht 2-element array is same as using PushArray twice with singleton array.
I believe this is the way to access the second index of your array using the limitglobalchat argument.
But using the globalchatradius argument, I guess the assembly output would be
I don't understand what will the globalchatradius be pointing to.
PushArray will allocate memory for your 2-element array in the heap. Your callback will receive the 'whole array' in limitglobalradius argument but since its just a reference variable not an array, only the first element of the array which you pushed will be pointed by limitglobalchat.
I don't even know what globalchatradius would be point to. The issue is globalchatradius doesn't take up the 2nd index of the array which you passed because of which you are not getting expected results.
Its intuitive that globalchatradius would be pointing to the very next set of 4 bytes after limitglobalchat. The reference variables are modified using SREF.S ([[FRM + offset]] = PRI). So [[]]? How can you say that the arguments are pointing to cells which are next to each other?
I doubt if using PushArray wiht 2-element array is same as using PushArray twice with singleton array.
I believe this is the way to access the second index of your array using the limitglobalchat argument.
Код:
#emit LOAD.S.pri limitglobalchat #emit ADD.C 4 #emit MOVE.alt #emit CONST.pri 2000 #emit STOR.I
Код:
#emit CONST.pri 2000 #emit SREF.S.pri globalchatradius
14.02.2016, 07:47
You need to call amx_PushArray() twice - first for globalchatradius, then once again for limitglobalchat.
For some reason AMX doesn't have a function for pushing references, only arrays. But references may be thought of as a special case of one-dimensional arrays - they look the same in memory, only difference is the number of elements (i.e. references are 1-element arrays).
For some reason AMX doesn't have a function for pushing references, only arrays. But references may be thought of as a special case of one-dimensional arrays - they look the same in memory, only difference is the number of elements (i.e. references are 1-element arrays).
14.02.2016, 08:48
Dan once made a function to push PAWN references/addresses:
Code:
int AMXAPI amx_PushAddress(AMX *amx, cell *address) { AMX_HEADER *hdr; unsigned char *data; cell xaddr; /* reverse relocate the address */ assert(amx != NULL); hdr = (AMX_HEADER *) amx->base; assert(hdr != NULL); assert(hdr->magic == AMX_MAGIC); data = (amx->data != NULL) ? amx->data : amx->base + (int) hdr->dat; xaddr = (cell) ((unsigned char*) address-data); if ((ucell) xaddr >= (ucell) amx->stp) { return AMX_ERR_MEMACCESS; } return amx_Push(amx,xaddr); }
14.02.2016, 12:28
Yashas, Zeex: Thanks for help, it worked. U will see the result in next version of YSF xD
Thanks, but function crashed for me.
Quote:
Dan once made a function to push PAWN references/addresses:
Code:
int AMXAPI amx_PushAddress(AMX *amx, cell *address) { AMX_HEADER *hdr; unsigned char *data; cell xaddr; /* reverse relocate the address */ assert(amx != NULL); hdr = (AMX_HEADER *) amx->base; assert(hdr != NULL); assert(hdr->magic == AMX_MAGIC); data = (amx->data != NULL) ? amx->data : amx->base + (int) hdr->dat; xaddr = (cell) ((unsigned char*) address-data); if ((ucell) xaddr >= (ucell) amx->stp) { return AMX_ERR_MEMACCESS; } return amx_Push(amx,xaddr); } |
14.02.2016, 14:28
(
Last edited by kurta999; 23/02/2016 at 10:20 PM.
)
16.03.2016, 06:59
Guys could someone share snippet for calling native from C++? I would like to avoid GDK or Invoke ( i just need to call one native on plugin load and that's it )
Oh and i need to read returned data (its integer)
Oh and i need to read returned data (its integer)
21.06.2016, 14:05
Yashas, convert the strings from pawn to C/++ format.
vannesenn, see sampGDK by Zeex.
vannesenn, see sampGDK by Zeex.
21.06.2016, 14:34
21.06.2016, 16:04
Quote:
Why is it needed? PAWN cell is 4 bytes and only the first byte stores the character. So copying characters should be same as copying cells?
|
Try using amx_GetString and check whether you get same results or not.
EDIT:
Shouldn't this: string_strncpy(AMX amx, cell params)
be: string_strncpy(AMX* amx, cell* params) ?
22.06.2016, 07:10
Quote:
Yes, each pawn cell is of 4 bytes. But do you really think that strings in the abstract machine are in a such simple format?
|
Of course, that code won't work with packed strings and I don't use packed strings so I won't need to add support for that.
I have many more algorithms which work on arrays which use the exact same method (directly modifying the contents through pointers) and they work.
Quote:
Try using amx_GetString and check whether you get same results or not.
|
Quote:
EDIT:
Shouldn't this: string_strncpy(AMX amx, cell params) be: string_strncpy(AMX* amx, cell* params) ? |
Here is a copy from the actual source.
Code:
cell AMX_NATIVE_CALL string_strncpy(AMX* amx, cell* params) { cell* dest = NULL; cell* source = NULL; amx_GetAddr(amx, params[1], &dest); amx_GetAddr(amx, params[2], &source); int num = static_cast<int>(params[3]); unsigned int size_dest = static_cast<unsigned int>(params[4]); unsigned int size_src = static_cast<unsigned int>(params[5]); while (num-- && size_dest-- && size_src--) { logprintf("%d", *(source)); *dest++ = *source++; } *dest = 0; return 0; }
wtf I sware I did not change the code at all =,= the array size is 11 and it works today -_-
Code:
[13:05:59] t [13:05:59] e [13:05:59] s [13:05:59] t [13:05:59] [13:05:59] s [13:05:59] t [13:05:59] r [13:05:59] i [13:05:59] n [13:05:59] test strin
22.06.2016, 08:52
Yes, it works. I tried out your code yesterday and it worked out for me. I was about to edit my comment but unfortunately had no time.
05.12.2016, 20:30
Hi guys!
I've just created a new way of setting amx parameters from plugin.
Does it looks good? I'm waiting for other people's opinion
I've just created a new way of setting amx parameters from plugin.
pawn Code:
// native GetSpawnInfo(playerid, &teamid, &modelid, &Float:spawn_x, &Float:spawn_y, &Float:spawn_z, &Float:z_angle, &weapon1, &weapon1_ammo, &weapon2, &weapon2_ammo,& weapon3, &weapon3_ammo);
CAMXParameters amxparams(amx, params, 2);
amxparams.Add(pSpawn->byteTeam);
amxparams.Add(pSpawn->iSkin);
amxparams.Add(pSpawn->vecPos);
amxparams.Add(pSpawn->fRotation);
amxparams.Add(pSpawn->iSpawnWeapons[0]);
amxparams.Add(pSpawn->iSpawnWeaponsAmmo[0]);
amxparams.Add(pSpawn->iSpawnWeapons[1]);
amxparams.Add(pSpawn->iSpawnWeaponsAmmo[1]);
amxparams.Add(pSpawn->iSpawnWeapons[2]);
amxparams.Add(pSpawn->iSpawnWeaponsAmmo[2]);
05.12.2016, 20:56
PHP Code:
Loading plugin: EmailSender
Plugin does not conform to architecture.
Failed.
05.12.2016, 21:13
Quote:
PHP Code:
|
« Next Oldest | Next Newest »
Users browsing this thread: 4 Guest(s)