[HELP]: Vehicle Range problem
#1

Hey guys,

I'm currently working on a new trunk saving system. Anyhow, here's a little bit of my code which detects whether the player is in a 3.5 radius of the vehicle and if the vehicle is an ownable car which then stores it in an array. Although it's only supposed to do it in a 3.5 radius of ownable cars, it does it globally for every car so when you do /trunk info it shows the trunk for every car.

pawn Код:
for(new i; i != MAX_VEHICLES; i++)
                {
                    new Float:PosX,Float:PosY,Float:PosZ;
                    GetVehiclePos(i,PosX,PosY,PosZ);
                    if(IsPlayerInRangeOfPoint(playerid, 3.5, PosX,PosY,PosZ))
                    {
                        if(IsAnOwnableCar(i))
                        {
                            result = i;
                        }
                    }
                }
Anyone got any ideas?

~ Mike.
Reply
#2

pawn Код:
forward VehicleToPlayer(playerid,vehicleid);
public VehicleToPlayer(playerid,vehicleid)
{
    new Float:pX,Float:pY,Float:pZ,Float:cX,Float:cY,Float:cZ,Float:distance;
    GetPlayerPos(playerid,pX,pY,pZ);
    GetVehiclePos(vehicleid,cX,cY,cZ);
    distance = floatsqroot(floatpower(floatabs(floatsub(cX,pX)),2) + floatpower(floatabs(floatsub(cY,pY)),2) + floatpower(floatabs(floatsub(cZ,pZ)),2));
    return floatround(distance);
}

forward GetClosestVehicle(playerid);
public GetClosestVehicle(playerid)
{
    new Float:distance = 99999.000+1,Float:distance2,result = -1;
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        distance2 = VehicleToPlayer(playerid,i);
        if(distance2 < distance)
        {
            distance = distance2;
            result = i;
        }
    }
    return result;
}
stock GetXYBehindOfVehicle(vehicleid, &Float:x, &Float:y, Float:distance)
{
    new
        Float:a;
    GetVehiclePos( vehicleid, x, y, a );
    GetVehicleZAngle( vehicleid, a );
    x += ( distance * floatsin( -a+180, degrees ));
    y += ( distance * floatcos( -a+180, degrees ));
}
A few functions I didn't make them tho.
Reply
#3

Alright bud, thanks for those functions they came in handy though I found the problem
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)