SA-MP Forums Archive
lock distance from driver's door - 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: lock distance from driver's door (/showthread.php?tid=607104)



lock distance from driver's door - thaKing - 14.05.2016

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

PHP код:
new FloatxFloatyFloatz;
GetVehicleModelInfo(car[id][carModel], VEHICLE_MODEL_INFO_FRONTSEATxyz);
if (!
IsPlayerInRangeOfPoint(playerid2.0xyz))
    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.


Re: lock distance from driver's door - AndreT - 14.05.2016

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.


Re: lock distance from driver's door - thaKing - 14.05.2016

found a solution!
PHP код:
#function
GetVehicleRelativePos(vehicleid, &Float:x, &Float:y, &Float:zFloat:xoff0.0Float:yoff0.0Float:zoff0.0)
{
    new 
Float:rot;
    
GetVehicleZAngle(vehicleidrot);
    
rot 360 rot;
    
GetVehiclePos(vehicleidxyz);
    
floatsin(rotdegrees) * yoff floatcos(rotdegrees) * xoff x;
    
floatcos(rotdegrees) * yoff floatsin(rotdegrees) * xoff y;
    
zoff z;
}
#vars
x,y,and x2y2z2
#getting door pos
GetVehicleModelInfo(car[id][carModel], VEHICLE_MODEL_INFO_FRONTSEATcXcYcZ);
GetVehicleRelativePos(car[id][carVehicleID], cX2cY2cZ2, -cX 0.5cYcZ);
#checking if near driver's door
if (!IsPlayerInRangeOfPoint(playerid1.0cX2cY2cZ2))    
    return 
SendErrorMsg(playerid"You are not near driver's door.");