Problem with IsPlayerNearVehicle
#1

Hey, so I'm making a system which does the following: If a player is near a vehicle which is locked and presses the key to enter, it sends a message. This is what I have for now:

At the top of the script:

Код:
stock IsPlayerNearVehicle(playerid, vehicleid, Float:range)
{
    new Float:X, Float:Y, Float:Z;
    GetVehiclePos(vehicleid, X, Y, Z);
    if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
    else return false;
}
At OnGamemodeInIt:

Код:
vt1 = CreateVehicle(431, 822.068603, -1636.192016, 13.390607, 120.873840, -1, -1, 0);
(Then I have the SetVehicleParamsForPlayer etc, which works perfectly, in both OnVehicleSpawn and OnVehicleStreamIn)

And then this:

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if((newkeys & KEY_SECONDARY_ATTACK) && !(oldkeys & KEY_SECONDARY_ATTACK))
	{
	    if(IsPlayerNearVehicle(playerid, 431, 10.0) && SetVehicleParamsForPlayer(vt1, playerid, 0, 1))
	    {
	        SendClientMessage(playerid, WHITE, "El coche estб cerrado. Usa una herramienta para abrirlo.");
		}
		return 1;
	}
	return 1;
}
So, the car is locked and everything, but when I approach it and press Enter to get in, it doesn't show any message. The character doesn't get in the car either which is good. So the problem is in the last part of the script I guess.

Thanks!
Reply
#2

You're probably confusing vehicleid with vehicle model (431).

pawn Код:
if(IsPlayerNearVehicle(playerid, vt1, 10.0) && SetVehicleParamsForPlayer(vt1, playerid, 0, 1))
Reply
#3

Lol what a silly mistake. Worked, thanks!! +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)