29.06.2018, 18:20
(
Последний раз редактировалось Sibuscus; 30.06.2018 в 08:12.
)
I found this cool stock that lets you get the ID of any vehicle that is within a radius of the player
Now I have some rental cars that I want the players to be able to lock:
My code is working fine, but the stock code always gives me vehicle IDs of 0. I have a problem when I use the /lockrent and at RentedCarID I get the correct value, but at Vehicle I always get 0. So the closest vehicle is always with ID: 0, whereas It should be 7 at my testing case.
RentCarNo is the vehicle ID of the car that is being rented (is working correctly)
lockedRentCar - 0=unlocked 1=locked
vehicle - the vehicle ID of the closest car (not worknig correctly, always shows ID: 0)
Код:
stock GetClosestVehicle(playerid, Float: fRadius) // by RyDeR` { new iClosestID = INVALID_VEHICLE_ID, Float: fFinalDistance, Float: fDistance, Float: fX, Float: fY, Float: fZ; GetPlayerPos(playerid, fX, fY, fZ); fFinalDistance = fRadius; for(new i; i != MAX_VEHICLES; i++) { if((fDistance = GetVehicleDistanceFromPoint(i, fX, fY, fZ)) < fFinalDistance) { fFinalDistance = fDistance; iClosestID = i; } } return iClosestID; }
Код:
CMD:lockrent(playerid, params[]) { new str[128]; new vehicle = GetClosestVehicle(playerid, 20); format(str, sizeof(str), "VehicleID: %d RentedCarId: %d ",vehicle, PlayerInfo[playerid][rentCarNo]); SendClientMessage(playerid, COLOR_DARKCORAL, str);//THIS IS FOR TESTING if(PlayerInfo[playerid][rentCarNo] != vehicle) { SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You don't have any vehicles nearby."); } else if(PlayerInfo[playerid][lockedRentCar] == 0 && PlayerInfo[playerid][rentCarNo] == vehicle) { SetVehicleParamsForPlayer(vehicle, playerid, 0, 1); SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You've locked your rental car."); } else if(PlayerInfo[playerid][lockedRentCar] == 1 && PlayerInfo[playerid][rentCarNo] == vehicle) { SetVehicleParamsForPlayer(vehicle, playerid, 0, 0); SendClientMessage(playerid, COLOR_DARKCORAL,"[BS] {AFAFAF}You've unlocked your rental car."); } return 1; }
RentCarNo is the vehicle ID of the car that is being rented (is working correctly)
lockedRentCar - 0=unlocked 1=locked
vehicle - the vehicle ID of the closest car (not worknig correctly, always shows ID: 0)