[HELP] Relative coordinates
#1

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;
}
Reply
#2

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)