SA-MP Forums Archive
Check if player is near the 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: Check if player is near the door (/showthread.php?tid=623718)



Check if player is near the door - GoldenLion - 04.12.2016

Hello, I've made a command which lets you break a window of a car, but you can only break the driver's window. Is it possible to check if the player is at the driver's door? I need that because it doesn't look too good if you are behind a car, then you do /breakwindow and it breaks the driver's window while you are not even near the driver's door. I've ******d and found that GetVehicleModelInfo function, but I've got no clue what to do with that. Anyways would that be possible to do?


Re: Check if player is near the door - Yaa - 04.12.2016

deleted


Re: Check if player is near the door - Bolex_ - 04.12.2016

http://forum.sa-mp.com/showpost.php?...18&postcount=7

or try to get PlayerPosition and Is payer on driver seat!


Re: Check if player is near the door - lollypap54 - 04.12.2016

Closest thing you can get to driver's door is front seat on GetVehicleModelInfo function, so you can write:

new Float, Float:y, Float:z;
GetVehicleModelInfo(yourvehmodel, VEHICLE_MODEL_INFO_FRONTSEAT, x, y, z);

I have never used this function, I'm just trying to get you on the road, try test that function, what it returns...

https://sampwiki.blast.hk/wiki/Vehicle_information_types
Here's types of that function.

After you get that window position, do IsPlayerInRangeOfPoint.


Re: Check if player is near the door - GoldenLion - 04.12.2016

Well, I don't really know what is sine and cosine, because I haven't learned that yet so I guess I don't know how to do that lol.

EDIT:
Quote:
Originally Posted by lollypap54
Посмотреть сообщение
Closest thing you can get to driver's door is front seat on GetVehicleModelInfo function, so you can write:

new Float, Float:y, Float:z;
GetVehicleModelInfo(yourvehmodel, VEHICLE_MODEL_INFO_FRONTSEAT, x, y, z);

I have never used this function, I'm just trying to get you on the road, try test that function, what it returns...

https://sampwiki.blast.hk/wiki/Vehicle_information_types
Here's types of that function.

After you get that window position, do IsPlayerInRangeOfPoint.
Wait I guess that's exactly what I need... Let me try.


Re: Check if player is near the door - GoldenLion - 04.12.2016

OK, but if I'd use GetVehicleModelInfo and get the position of the front seat, what would I need to do so I could use IsPlayerInRangeOfPoint with it? Like get the coordinates of the vehicle's front seat seat in the world. You got the idea, like you could set player's position to the coordinates and all that stuff.


Re: Check if player is near the door - RyderX - 04.12.2016

Try it?


Re: Check if player is near the door - GoldenLion - 04.12.2016

Try what? It's getting the position of the model's front seat, not the vehicle's.


Re: Check if player is near the door - Vince - 04.12.2016

Yes, you need to translate the relative coordinates to absolute coordinates but you must also take into account the current facing angle of the vehicle.

PHP код:
worldX floatsin(-adegrees) * offset_x;
worldY floatcos(-adegrees) * offset_y;
worldZ offset_z
Where x, y and z are retrieved from GetVehiclePos, a is retrieved from GetVehicleZAngle and offset_x, offset_y and offset_z are the relative coordinates for the drivers seat retrieved from GetVehicleModelInfo. I made some calculations on paper and I think this is correct.


Re: Check if player is near the door - Threshold - 04.12.2016

offset_x would have to be the information retrieved from info types VEHICLE_MODEL_INFO_FRONTSEAT and VEHICLE_MODEL_INFO_SIZE. (Half the vehicle width because you will be calculating from the centre of the vehicle)

Basically
PHP код:
offset_x frontseat_x - (width_x 2); 
Correct me if I'm wrong, but don't you need to account for the other offsets in X and Y calculations?
PHP код:
worldX + (floatsin(-adegrees) * offset_y) + (floatcos(-adegrees) * offset_x);
worldY + (floatcos(-adegrees) * offset_y) - (floatsin(-adegrees) * offset_x);
worldZ offset_z
Or have I completely failed in remembering how maths works? :S