Trunk system
#1

How to check if the vehicle near the player is his car so he can do /trunk ?
Reply
#2

Quote:
Originally Posted by MP2
Посмотреть сообщение
You could make use of the new GetVehicleModelInfo and the custom GetXYBehindVehicle function. This is a function I use:

pawn Код:
stock GetPosBehindVehicle(vehicleid, &Float:x, &Float:y, &Float:z, Float:offset=0.5)
{
    new Float:vehicleSize[3], Float:vehiclePos[3];
    GetVehiclePos(vehicleid, vehiclePos[0], vehiclePos[1], vehiclePos[2]);
    GetVehicleModelInfo(GetVehicleModel(vehicleid), VEHICLE_MODEL_INFO_SIZE, vehicleSize[0], vehicleSize[1], vehicleSize[2]);
    GetXYBehindVehicle(vehicleid, vehiclePos[0], vehiclePos[1], (vehicleSize[1]/2)+offset);
    x = vehiclePos[0];
    y = vehiclePos[1];
    z = vehiclePos[2];
    return 1;
}

GetXYBehindVehicle(vehicleid, &Float:q, &Float:w, Float:distance)
{
    new Float:a;
    GetVehiclePos(vehicleid, q, w, a);
    GetVehicleZAngle(vehicleid, a);
    q += (distance * -floatsin(-a, degrees));
    w += (distance * -floatcos(-a, degrees));
}
Then just check if they are in range of 1.0 unit, and it will check if they are at the back of the vehicle, not at the sides like just using IsPlayerInRangeOfPoint would do.
Use the 'search' button next time...
Reply
#3

I think you miss understood me, i mean i want to know how to check if the vehicle near the player is owned by him or not.
Reply
#4

You could try this out.

pawn Код:
//When creating a car use.... V
//VehID[playerid] = CreateVehicle(vehid, X, Y, Z, 0.0, random(130), random(130), 0);

new VehID[MAX_PLAYERS]; //Let's store the vehicle ID of the player

public OnPlayerDisconnect(playerid)
{
    VehID[playerid] = -1;
    return 1;
}

public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(strfind(cmdtext, "trunk", true) != -1)
    {
        new vehid2 = VehID[playerid];
        if(IsPlayerNearVehicle(playerid, vehid2, 5.0) && vehid2 != -1) //The player is near his vehicle
        {
            SendClientMessage(playerid, 0xFFFFFF, "User used command /trunk and is near his car!");
            return 1;
        }
    }
    return 1;
}

IsPlayerNearVehicle(playerid, vehicleid, float:range) //Is player near the vehicle *range
{
    new Float:X, Y, Z;
    GetVehiclePos(vehicleid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, X, Y, Z, range) return 1;
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)