SA-MP Forums Archive
Porblem with ranges. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Porblem with ranges. (/showthread.php?tid=635336)



FIXED: Porblem with ranges. - AroseKhanNiazi - 05.06.2017

I am trying to check if player in point of range of the dropped weapon;
Код:
if(IsPlayerInRangeOfPoint(playerid,2.5,DropsInfo[i][wp_x][k],DropsInfo[i][wp_y][k],DropsInfo[i][wp_z][k]))
				{
					print("Player Is in range.");
This doesn't work.
I tried some debugging and I get odd results;
Код:
FUNCTION Drops_ReplaceIt(playerid)
{
	new Float:x,Float:y,Float:z;
	GetPlayerPos(playerid,x,y,z);
	printf("Replace weapon called for %d",playerid);
	for(new i=0,j=GetPlayerPoolSize(); i<=j; i++)
	{
		if(!IsPlayerConnected(i)) continue;
		printf("Checking player %d's drops",i);
		for(new k=0; k<13; k++)
		{
			printf("Checking the info of Dropped (%b) %0.2f %0.2f %0.2f",DropsInfo[i][wp_Dropped][k],DropsInfo[i][wp_x][k],DropsInfo[i][wp_y][k],DropsInfo[i][wp_z][k]);
			
			if(DropsInfo[i][wp_Dropped][k])
			{
				print("Drop is dropped.");
				printf("Player pos %0.2f %0.2f %0.2f",x,y,z);
				printf("Distance is %0.2f",GetPlayerDistanceFromPoint(playerid, DropsInfo[i][wp_x][k],DropsInfo[i][wp_y][k],DropsInfo[i][wp_z][k]));
				
				if(((x+2.5 >= DropsInfo[i][wp_x][k] && x+2.6 <= DropsInfo[i][wp_x][k]) || (x-2.5 >= DropsInfo[i][wp_x][k] && x-2.6 <= DropsInfo[i][wp_x][k])) && ((y+2.5 >= DropsInfo[i][wp_y][k] && y+2.6 <= DropsInfo[i][wp_y][k]) || (y-2.5 >= DropsInfo[i][wp_y][k] && y-2.6 <= DropsInfo[i][wp_y][k])) && ((z+2.5 >= DropsInfo[i][wp_z][k] && z+2.6 <= DropsInfo[i][wp_z][k]) || (z-2.5 >= DropsInfo[i][wp_x][k] && z-2.6 <= DropsInfo[i][wp_z][k])))
				{
					printf("Fucking Shit works somehow");
				}
				
				if(IsPlayerInRangeOfPoint(playerid,2.5,DropsInfo[i][wp_x][k],DropsInfo[i][wp_y][k],DropsInfo[i][wp_z][k]))
				{
					print("Player Is in range.");
result:
Код:
Replace weapon called for 0
[18:01:10]
 Checking player 0's drops
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking player 1's drops
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
[18:01:10]
 Checking the info of Dropped (1) 2901.58 2097.20 10.82
[18:01:10]
 Drop is dropped.
[18:01:10]
 Player pos 2901.48 2097.05 10.82
[18:01:10]
 Distance is 1970902656.00
[18:01:10]
 Checking the info of Dropped (0) 0.00 0.00 0.00
//....
Other info;
Код:
enum wpdrops_enum {
	bool:wp_Dropped,
	wp_id,
	wp_weapon,
	wp_ammo,
	Float:wp_x,
	Float:wp_y,
	Float:wp_z,
	wp_slot
};

new DropsInfo[MAX_PLAYERS][wpdrops_enum][13];



Re: Porblem with ranges. - TonyII - 05.06.2017

Do you break your loops when the result is true?

Код:
if(((x+2.5 >= DropsInfo[i][wp_x][k] && x+2.6 <= DropsInfo[i][wp_x][k]) || (x-2.5 >= DropsInfo[i][wp_x][k] && x-2.6 <= DropsInfo[i][wp_x][k])) && ((y+2.5 >= DropsInfo[i][wp_y][k] && y+2.6 <= DropsInfo[i][wp_y][k]) || (y-2.5 >= DropsInfo[i][wp_y][k] && y-2.6 <= DropsInfo[i][wp_y][k])) && ((z+2.5 >= DropsInfo[i][wp_z][k] && z+2.6 <= DropsInfo[i][wp_z][k]) || (z-2.5 >= DropsInfo[i][wp_x][k] && z-2.6 <= DropsInfo[i][wp_z][k])))
				{
					printf("Fucking Shit works somehow");
                                        break;
				}
				
				if(IsPlayerInRangeOfPoint(playerid,2.5,DropsInfo[i][wp_x][k],DropsInfo[i][wp_y][k],DropsInfo[i][wp_z][k]))
				{
					print("Player Is in range.");
                                        break;



Re: Porblem with ranges. - AroseKhanNiazi - 05.06.2017

Yes i use break


Re: Porblem with ranges. - AroseKhanNiazi - 05.06.2017

Fixed: Thanks to MichaelBelgium
changed new DropsInfo[MAX_PLAYERS][wpdrops_enum][13];
to new DropsInfo[MAX_PLAYERS][13][wpdrops_enum];