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 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.
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: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.");