Jump to content

[REZOLVAT] AJUTOR /closestcar


Gaby
 Share

Recommended Posts

stock GetClosestVehicle2(playerid, Float:dis)
{
    new Float:X,
        Float:Y,
        Float:Z;
    if(GetPlayerPos(playerid, X, Y, Z))
    {
        new vehicleid = INVALID_VEHICLE_ID;
        for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++)
        {
            if(GetVehiclePos(v, VX, VY, VZ))
            {
                VX -= X, VY -= Y, VZ -= Z;
                temp = VX * VX + VY * VY + VZ * VZ;
                if(temp < dis) dis = temp, vehicleid = v;
            }
        }
        dis = floatpower(dis, 0.5);
        return vehicleid;
    }
    return INVALID_VEHICLE_ID;
}

Luata din GM Bigzone.

Respecta si vei fi respectat.

 

BigInt Pawn:

Pacman C++: 

Snake C++:

Minesweeper C++:

 

mattbb.cash

leaks.ro

Link to comment
Share on other sites


 
YCMD:closestcar(playerid, params[], help) {
	if(!PlayerInfo[playerid][pAdmin]) return SCM(playerid, -1, AdminOnly);

	new vehicle = GetClosestVehicle2(playerid); gString[0] = (EOS);
	if(vehicle == INVALID_VEHICLE_ID) return SCM(playerid, COLOR_GREY, "Nu e nici un vehicul in apropierea ta.");
	PutPlayerInVehicleEx(playerid, vehicle, 0);
	return 1;
}

stock GetClosestVehicle2(playerid) {
	new Float: Distance;
	if(!Distance) Distance = 200.0;
	new Float:X[2], Float:Y[2], Float:Z[2], Float:NearestPos = floatabs(Distance), NearestVehicle = INVALID_VEHICLE_ID;
	GetPlayerPos(playerid, X[0], Y[0], Z[0]);
	for(new i; i < MAX_VEHICLES; i++) {
		if(!IsVehicleStreamedIn(i, playerid) || IsPlayerInVehicle(playerid, i)) continue;
		GetVehiclePos(i, X[1], Y[1], Z[1]);
		if(NearestPos > GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1])) NearestPos = GetDistanceBetweenPoints(X[0], Y[0], Z[0], X[1], Y[1], Z[1]), NearestVehicle = i;
	}
	return NearestVehicle;
}
Quote

 

 

Edited by TwEnzY.VALOARE

      

Link to comment
Share on other sites

CMD:closestcar(playerid, params[])
{
	if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to log in first.");
	if(PlayerInfo[playerid][pAdmin] > 0)
	{
		if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
		{
			new VehicleID = GetClosestVehicle(playerid), string[128];

			if(doesVehicleExist(VehicleID)) 
			{
				PutPlayerInVehicle(playerid, VehicleID, 0);
				format(string, sizeof(string), "You have teleported into a %s (vehicle ID %d).", aVehicleNames[GetVehicleModel(VehicleID) - 400], VehicleID);
				SendClientMessage(playerid, COLOR_WHITE, string);
			}
			else SendClientMessage(playerid, COLOR_GREY, "No vehicles are in range.");
		}
		else SendClientMessage(playerid, COLOR_GREY, "You can only use this command while on foot.");
	}
	else return SendClientMessage(playerid, COLOR_LIGHTGREEN3, AdminOnly);
	return 1;
}
stock GetClosestVehicle(playerid, exception = INVALID_VEHICLE_ID) {
    new
		Float:Distance,
		target = -1;

    for(new v; v < MAX_VEHICLES; v++) if(doesVehicleExist(v)) {
        if(v != exception && (target < 0 || Distance > GetDistancePlayerVeh(playerid, v))) {
            target = v;
            Distance = GetDistancePlayerVeh(playerid, v);
        }
    }
    return target;
}

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...