GetClosestCar problem.
#1

Hey guys, so I created this command and it works fine except for one thing. So the system is all about loading and delivery, so a forklift is loaded and it's on his way to load the truck, once someone uses the command /loadtruck the object won't attach to the truck but on the back of the forklift however I don't understand why. Here are the codes.
pawn Код:
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;
}
Reply
#2

Bump
Reply
#3

Anyone :@
Reply
#4

Obviously you need a positive value on your y coordinate.

-3.890041
Reply
#5

Removed:Completely invalid due to him having IsATruck
Reply
#6

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Obviously you need a positive value on your y coordinate.

-3.890041
But what does that have to do with attaching the object to the forklift instead of the truck?
Reply
#7

Is the forklift ID in (IsATruck)? That would be the only cause for the reason i removed:
Quote:

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.

Thats what I originally posted.
Reply
#8

if(!IsATruck(truckid) && IsPlayerInRangeOfPoint(playerid, 10, X,Y,Z))

This migth need to be without the !... I cant tell due to poor indentation of your code.
(Sorry for double post yet I get a 404 when I press the pencil)
Reply
#9

The forklift ID is not in the IsATruck stock, this is pretty confusing
*EDIT
I did add the ! later on, I had the same results without it.
Reply
#10

In which case unless you undent your code properly I cant help; this isn;t me being picky but my brian being unable to read code that poorly indented.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)