lock distance from driver's door
#1

well, i tried to make a function that checks if player is near driver's door.

PHP код:
new Float: x, Float: y, Float: z;
GetVehicleModelInfo(car[id][carModel], VEHICLE_MODEL_INFO_FRONTSEAT, x, y, z);
if (!
IsPlayerInRangeOfPoint(playerid, 2.0, x, y, z))
    return 
SendErrorMsg(playerid, "You are not near car driver's door."); 
somehow it's not working.
/lock command by itself works - also car can be locked, but cannot be unlock - doesn't work.
Reply
#2

Hi!

Looking at the documentation here: https://sampwiki.blast.hk/wiki/Vehicle_information_types

GetVehicleModelInfo with the info type VEHICLE_MODEL_INFO_FRONTSEAT returns X Y Z offsets from the center of the vehicle model.

What you want is GetVehiclePos, which returns the vehicle's position in the game world.
Reply
#3

found a solution!
PHP код:
#function
GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:z, Float:xoff= 0.0, Float:yoff= 0.0, Float:zoff= 0.0)
{
    new 
Float:rot;
    
GetVehicleZAngle(vehicleid, rot);
    
rot = 360 - rot;
    
GetVehiclePos(vehicleid, x, y, z);
    
x = floatsin(rot, degrees) * yoff + floatcos(rot, degrees) * xoff + x;
    
y = floatcos(rot, degrees) * yoff - floatsin(rot, degrees) * xoff + y;
    
z = zoff + z;
}
#vars
x,y,z and x2, y2, z2
#getting door pos
GetVehicleModelInfo(car[id][carModel], VEHICLE_MODEL_INFO_FRONTSEAT, cX, cY, cZ);
GetVehicleRelativePos(car[id][carVehicleID], cX2, cY2, cZ2, -cX - 0.5, cY, cZ);
#checking if near driver's door
if (!IsPlayerInRangeOfPoint(playerid, 1.0, cX2, cY2, cZ2))    
    return 
SendErrorMsg(playerid, "You are not near driver's door."); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)