g only works if its locked how ever if your press enter to enter the car while its locked doesn't do anything
![]() so I need to basically calculate distance to vehicle set the animation to walk set player to walk to nearest vehicle x y z location stop when reached and then apply the lock animation ![]() |
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;
}
lol there is no efficient way to do this... i dont think its possible.
|