SA-MP Forums Archive
[HELP] Relative coordinates - 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: [HELP] Relative coordinates (/showthread.php?tid=566289)



[HELP] Relative coordinates - SirPotato - 04.03.2015

Hello!


I just started scripting, and I've been watching a lot of tutorials and they all say that with practise you get better, so I decided to script some minor things so I can get the hang of it..
I'm doing a simple script, when a player does "/vehicle" a car would spawn infront of them, but I've encounter a problem wich I hope you guys can help me figure out.
I don't know if it's possible to make the car spawn relativetly to the player, and if not, how do I do this?

Feel free to leave suggestions and comments below

Here's what I got so far

Код:
  public OnPlayerCommandText(playerid, cmdtext[])
{
	
     if (strcmp("/vehicle", cmdtext, true, 8) ==0)
	{
	  AddStaticVehicle()
		
	}
	return 0;
}



Re: [HELP] Relative coordinates - Vince - 04.03.2015

Great example on this page that I added a few days ago: https://sampwiki.blast.hk/wiki/Floatsin


Re: [HELP] Relative coordinates - X337 - 05.03.2015

You can use this function to get XY coordinate in front of player.
Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
	// Created by ******

	new Float:a;

	GetPlayerPos(playerid, x, y, a);
	GetPlayerFacingAngle(playerid, a);

	if (GetPlayerVehicleID(playerid)) {
	    GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	}

	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
And for the command :
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	
    if (strcmp("/vehicle", cmdtext, true, 8) ==0)
	{
		new Float:x, Float:y, Float:z, Float:angle;
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid, angle);
		GetXYInFrontOfPlayer(playerid, x, y, 10.0); // GetXYInFrontOfPlayer(playerid, x coordinate, y coordinate, distance)
		AddStaticVehicle(436, x, y, z, angle, 255, 255);
		return 1;
	}
	return 0;
}