thanks matey , already had the facing angle that kept changing if i wasn't looking right anyways got it to work its almost perfect script nearly there need a few touches there is 1 bug when car is locked and the car respawns and your at the same co ords as vehicle respawns and it still detects as locked when you face and press enter it will go over to it then look another direction and carry on running with a loop and wont stop until you press a button ermmm
also if you go over to the right hand side of vehicle it will use LHS door locked anim will need to find a way around this
![Huh?](images/smilies/confused.gif)
anyways if any one wants a basic script for car lock with animation here it is
PHP код:
stock IsPlayerFacingVehicle(playerid, vehicleid)
{
new Float:pX,Float:pY,Float:pZ,Float:X,Float:Y,Float:Z,Float:ang;
GetVehiclePos(vehicleid, X, Y, Z);
GetPlayerPos(playerid, pX, pY, pZ);
if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
else ang = (floatabs(ang) - 180.0);
new Float:russia;
GetPlayerFacingAngle(playerid,russia);
if(ang-russia<-130 || ang-russia>130) return 0;
else return 1;
}
stock IsVehicleOccupied(vehicleid, seatid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(GetPlayerVehicleID(i) == vehicleid && GetPlayerVehicleSeat(i) == seatid)
{
return 1;
}
}
return 0;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new playerstate = GetPlayerState(playerid);
if(playerstate == PLAYER_STATE_ONFOOT)
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(!IsVehicleOccupied(i, 0))
{
new Float:X, Float:Y, Float:Z, Float:Zangle;
new Float:Angle, Float:Pos[3];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
GetVehiclePos(i, X, Y, Z);
GetPlayerFacingAngle(playerid, Angle);
GetVehicleZAngle(i, Zangle);
if(PRESSED(KEY_SECONDARY_ATTACK))
{
if(IsPlayerInRangeOfPoint(playerid, 10, X, Y, Z))
{
if(IsPlayerFacingVehicle(playerid,i))
{
ApplyAnimation(playerid,"PED","RUN_PLAYER",4.1,0,1,1,0,1000,0);
if(IsPlayerInRangeOfPoint(playerid, 1.56, X, Y, Z))
{
if(VehicleInfo[i][Lock] == 1)
{
SetPlayerFacingAngle(playerid, Zangle);
ApplyAnimation(playerid,"PED","CAR_doorlocked_LHS" ,4.1,0,0,0,0,0,1);
}
}
}
}
}
}
}
}
return 1;
}