SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 03/12/2015, 11:45 AM   #151
SkittlesAreFalling
Big Clucker
 
Join Date: Oct 2013
Posts: 155
Reputation: 14
Default Re: Plugin development guide

Quote:
Originally Posted by Neavorce View Post
Add HAVE_STDINT_H preprocessor definition to your project settings and try recompile again.
That worked, thank you.
SkittlesAreFalling is offline   Reply With Quote
Old 02/02/2016, 06:45 PM   #152
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,374
Reputation: 626
Default Re: Plugin development guide

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 &param1, &param2, &param3)
{
if(param1 > 10) param1 = 15;
param2 = 0;
return 1;
}
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.
kurta999 is offline   Reply With Quote
Old 02/02/2016, 08:17 PM   #153
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,836
Reputation: 1607
Default Re: Plugin development guide

Of course (that's how strings are passed), just make sure to place them on the heap (unlike some samp callbacks...).
Slice is offline   Reply With Quote
Old 13/02/2016, 03:20 PM   #154
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,374
Reputation: 626
Default Re: Plugin development guide

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

pawn Code:
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);
}

Any ideas how to solve this problem?
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.
kurta999 is offline   Reply With Quote
Old 13/02/2016, 03:46 PM   #155
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 879
Reputation: 313
Default Re: Plugin development guide

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.
Code:
#emit LOAD.S.pri limitglobalchat
#emit ADD.C 4
#emit MOVE.alt
#emit CONST.pri 2000
#emit STOR.I
But using the globalchatradius argument, I guess the assembly output would be
Code:
#emit CONST.pri 2000
#emit SREF.S.pri globalchatradius
I don't understand what will the globalchatradius be pointing to.
Yashas is offline   Reply With Quote
Old 14/02/2016, 07:47 AM   #156
xeeZ
Huge Clucker
 
Join Date: Feb 2013
Posts: 319
Reputation: 382
Default Re: Plugin development guide

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).
xeeZ is offline   Reply With Quote
Old 14/02/2016, 08:48 AM   #157
maddinat0r
Banned
 
Join Date: Jun 2010
Location: Germany
Posts: 848
Reputation: 482
Default Re: Plugin development guide

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);
}
maddinat0r is offline   Reply With Quote
Old 14/02/2016, 12:28 PM   #158
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,374
Reputation: 626
Default Re: Plugin development guide

Yashas, Zeex: Thanks for help, it worked. U will see the result in next version of YSF xD

Quote:
Originally Posted by maddinat0r View Post
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);
}
Thanks, but function crashed for me.
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.
kurta999 is offline   Reply With Quote
Old 14/02/2016, 02:28 PM   #159
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,374
Reputation: 626
Default Re: Plugin development guide

E:

Thanks for help, result: https://github.com/kurta999/YSF/comm...d34b8ef3bda2e5
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.

Last edited by kurta999; 23/02/2016 at 10:20 PM.
kurta999 is offline   Reply With Quote
Old 16/03/2016, 06:59 AM   #160
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,047
Reputation: 184
Default Re: Plugin development guide

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)
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SA-MP 0.3c in development Kalcor News and Updates 883 19/09/2014 04:39 PM
0.3b Development bar gone WackoX General 94 02/08/2010 10:17 PM
A guide to install Jacob's IRC plugin? Celson Server Support 5 09/06/2009 07:06 AM


All times are GMT. The time now is 03:54 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.