SA-MP Forums Archive
Trunk system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Trunk system (/showthread.php?tid=524692)



Trunk system - Xenforox - 08.07.2014

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


Re: Trunk system - Threshold - 08.07.2014

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...


Re : Re: Trunk system - Xenforox - 08.07.2014

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.


Re: Trunk system - ABKPot - 08.07.2014

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;
}