SA-MP Forums Archive
Help needed - 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: Help needed (/showthread.php?tid=445127)



Help needed - HaiderABbas - 19.06.2013

How can i add a Trunk open and Bonnet hood

Like the front part and back one

OnPLayerKeyState "Y" opens the trunk and "N" opens honnet/hood what its called idk the back one

front one and back one


Re: Help needed - Scenario - 19.06.2013

That's pretty simple...

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(!IsPlayerInAnyVehicle(playerid))
    {
        new
            vehicleid = GetClosestVehicle(playerid);
       
        if(vehicleid != INVALID_VEHICLE_ID)
        {
            new
                engine,
                lights,
                alarm,
                doors
                bonnet,
                boot,
                objective;

            GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
               
            if(newkeys & KEY_YES) // if they pushed Y, open/close the bonnet/hood
            {
                if(bonnet) == 1) SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, 0, boot, objective);
                else SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, 1, boot, objective);
            }
            else if(newkeys & KEY_NO) // if they pushed N, open/close the boot/trunk
            {
                if(boot) == 1) SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 0, objective); // if the boot is opened, close it
                else SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, 1, objective); // if the boot is closed, open it
            }
        }
    }
    return 1;
}

stock GetCloestVehicle(playerid)
{
    new
        Float:X,
        Float:Y,
        Float:Z,
        Float:distance,
        Float:lastdistance = 20.0,
        vehicleid = INVALID_VEHICLE_ID;
   
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        GetVehiclePos(v, X, Y, Z);
        distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
       
        if(distance < lastdistance)
        {
            lastdistance = distance;
            vehicleid = v;
        }
    }
    return vehicleid;
}
I'm not sure if the GetClosestVehicle function will work or not, I just wrote that up. It looks like it will though!