CMD:loadtruck(playerid, params[])
{
new vehicleid = GetPlayerVehicleID(playerid);
new truckid = GetClosestCar(playerid);
new Float:X,Float:Y,Float:Z;
GetVehiclePos(truckid, X,Y,Z);
if(IsAForklift(vehicleid))
{
if(ForkliftLoaded[vehicleid] == 0) return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}There is no cargo on this forklift.");
if(!IsATruck(truckid) && IsPlayerInRangeOfPoint(playerid, 10, X,Y,Z))
{
if(TruckLoaded[truckid] == 0)
{
DestroyObject(ForkliftObject[vehicleid][vObject]);
TruckObject[truckid][vObject] = CreateObject(964, 0, 0.9, -0.12, 0, 0, 0);
AttachObjectToVehicle(TruckObject[truckid][vObject], truckid, 0.000000, -3.890041, 0.120000, 0.000000, 0.000000, 0.000000);
TruckLoaded[truckid] = 1;
ForkliftLoaded[vehicleid] = 0;
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}This truck can't carry more cargo.");
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You aren't near any cargo truck.");
}
else return SendClientMessage(playerid, COLOR_DARKRED,"[SERVER] {FFFFFF}You must be a driver of a forklift to load a forklift.");
return 1;
}
|
Obviously you need a positive value on your y coordinate.
-3.890041 |
|
Its because most vehicle positions are the Center of the Vehicle. Let me explain. [ x ] Truck [ x ] Forklift. [x] Box Now I havn't read you code but I am assuming your using the Box position to find the closest vehicle however that wouldn't work is your cars are arranged like this: [ x ][x][ x ] In this example the Center of the box is closest to the forklift therefore the Fork Lift is the closet vehicle according to the Game Engine. Whereas the truck is 7 spaces away the fork lift is 3. Reading your code and then i will alter this post. |