SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 16/03/2016, 07:28 AM   #161
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 259
Reputation: 116
Default Re: Plugin development guide

Here you go.

Code:
typedef cell(*AMX_NATIVE_CALL pfn_SetPlayerHealth)(AMX*, cell*);
cell AMX_NATIVE_CALL Test(AMX* amx, cell* params)
{
	pfn_SetPlayerHealth SetPlayerHealth_t = (pfn_SetPlayerHealth)0x47A6D0; //address of SetPlayerHealth native
	SetPlayerHealth_t(amx, params);
	return 1;
}
codectile is offline   Reply With Quote
Old 16/03/2016, 01:09 PM   #162
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,046
Reputation: 184
Default Re: Plugin development guide

Quote:
Originally Posted by codectile View Post
Here you go.

Code:
typedef cell(*AMX_NATIVE_CALL pfn_SetPlayerHealth)(AMX*, cell*);
cell AMX_NATIVE_CALL Test(AMX* amx, cell* params)
{
	pfn_SetPlayerHealth SetPlayerHealth_t = (pfn_SetPlayerHealth)0x47A6D0; //address of SetPlayerHealth native
	SetPlayerHealth_t(amx, params);
	return 1;
}
Oh hell no! No memory addresses, whole idea is to automatize hooking process...Guess i will have to make public inside include and call it instead of native itself...
__________________
Путин 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
Old 21/06/2016, 01:23 PM   #163
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 879
Reputation: 313
Default Re: Plugin development guide

Code:
new str2[] = "test string two, STRING TWO_2 !TWO!";
new str3[35];
strncpy(str3, str2, 10);
print(str3);
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("%c", *(source));
			*dest++ = *source++;
		}
		*dest = 0;
		return 0;
 }
Code:
[18:40:19]  <------- NOTHING HERE wtf?
[18:40:19] e
[18:40:19] s
[18:40:19] t
[18:40:19]  
[18:40:19] s
[18:40:19] t
[18:40:19] r
[18:40:19] i
[18:40:19] n
[18:40:19] (null)
If I increase the str3 size to 36 (or more than 36), I get
Code:
[18:40:00] t
[18:40:00] e
[18:40:00] s
[18:40:00] t
[18:40:00]  
[18:40:00] s
[18:40:00] t
[18:40:00] r
[18:40:00] i
[18:40:00] n
[18:40:00] test strin
Code:
native strncpy(destination[], const source[], num, sizedest = sizeof(destination),  sizesrc = sizeof(source));
What does the array size got to do here? -_-
Yashas is offline   Reply With Quote
Old 21/06/2016, 01:59 PM   #164
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 609
Reputation: 15
Default Re: Plugin development guide

Is possible to make gamemode as plugin(s) ?
vannesenn is offline   Reply With Quote
Old 21/06/2016, 02:05 PM   #165
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 259
Reputation: 116
Default Re: Plugin development guide

Yashas, convert the strings from pawn to C/++ format.
vannesenn, see sampGDK by Zeex.
codectile is offline   Reply With Quote
Old 21/06/2016, 02:34 PM   #166
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 879
Reputation: 313
Default Re: Plugin development guide

Quote:
Originally Posted by codectile View Post
Yashas, convert the strings from pawn to C/++ format.
vannesenn, see sampGDK by Zeex.
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?
Yashas is offline   Reply With Quote
Old 21/06/2016, 04:04 PM   #167
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 259
Reputation: 116
Default Re: Plugin development guide

Quote:
Originally Posted by Yashas View Post
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?
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?
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) ?
codectile is offline   Reply With Quote
Old 22/06/2016, 07:10 AM   #168
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 879
Reputation: 313
Default Re: Plugin development guide

Quote:
Originally Posted by codectile View Post
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?
Srtings are arrays so what is so different? Each character is stored in each cell linearly in PAWN (unpacked strings) so I can treat it as it was an array but with a null at the end?

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:
Originally Posted by codectile View Post
Try using amx_GetString and check whether you get same results or not.
And SetString again? will reply after doing it...

Quote:
Originally Posted by codectile View Post
EDIT:

Shouldn't this: string_strncpy(AMX amx, cell params)
be: string_strncpy(AMX* amx, cell* params) ?
Yea, I asked about it with few people in skype and copied the code from the skype chat which is why few * are missing.

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
Yashas is offline   Reply With Quote
Old 22/06/2016, 08:52 AM   #169
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 259
Reputation: 116
Default Re: Plugin development guide

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.
codectile is offline   Reply With Quote
Old 05/12/2016, 08:30 PM   #170
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,374
Reputation: 626
Default Re: Plugin development guide

Hi guys!

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]);

Does it looks good? I'm waiting for other people's opinion
__________________
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
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 08:41 AM.


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