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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)