GetPlayerNearestVehicle(vehicleid) or GetPlayerNearestVehiclePos(vehicleid,pos)?
#1

So i want to make an script that puts the player in the nearest vehicle but i am stuck at getting the nearest vehicle id.
for now I have this that needs to be done:
Code:
#include <a_samp>
#include <strtok>

public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256], idx = 0;
	cmd = strtok(cmdtext, idx);
	if(!strcmp(cmd, "/nearest-car", true))
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
			SendClientMessage(playerid, 0xFF0000FF, "* You are already in a Vehicle!");
		}
		else
		{
		  if(!IsVehicleInUse(vehicleid))
  		{
			  GetNearestVehicleDistance(playerid,vehposx,vehposy,vehposz);
				SetPlayerPos(playerid,vehposx,vehposy,vehposz);
				SendClientMessage(playerid, 0xA8FF36FF, "* You have been teleported to the nearest vehicle!");
			}else{
			  SendClientMessage(playerid, 0xA8FF36FF, "* Unable to find a nearest empty car!");
			}
		}
		return 1;
	}
	return 0;
}
stock GetNearestVehicleDistance(playerid,vehposx,vehposy,vehposz)
{
  new Float:vehposx,Float:vehposy,Float:vehposz;
  GetVehiclePos(nearestvehicleid,vehposx,vehposy,vehposz);
  /*if(!IsVehicleInUse(vehicleid))
  {
    PutPlayerInVehicle(playerid,nearestvehicleid,0);
	}*/
	return 1;
}
IsVehicleInUse(vehicleid)
{
	new temp;
	for(new i=0;i<200;i++)
	{
		if(IsPlayerConnected(i) && IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i)==PLAYER_STATE_DRIVER)
		{
			temp++;
		}
	}
	if(temp > 0){ return true; } else return false;
}
So if anybody can help thanks!
Reply
#2

Try combining with the PlayerToPoint function
Reply
#3

em ok i got maybe an idea..but now how to do that lol xD?...
Reply
#4

Look at the GetClosestPlayer function. I'm sure after looking at it you'll be able to make up a GetClosestVehicle function
Reply
#5

Quote:
Originally Posted by Swift_
Look at the GetClosestPlayer function. I'm sure after looking at it you'll be able to make up a GetClosestVehicle function
is this in a_player.inc or where? I think i can't find it ;l
Edit: eh lol undefinied.. k i search for it xD
Reply
#6

Search for it.
Reply
#7

okay i got an idea but instead of
GetDistanceBetweenPlayers(x,p1);
I need
GetDistanceToVehicle(x,v1);
...
EDIT : ok got it now i need to create it and .. test :P
EDIT: YEEEEEES, it works now only some stuff.. for ex !isvehicleinuse ...
next step.. Atach veh to veh xD
you can expect i ask help :]
thank you all.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)