OnPlayerExitVehicle
#1

Hello. I'm trying to make a code that will put a player back into their vehicle if they try and exit within 3 seconds of just recently entering it. I seem to be having some trouble with it though as it does not execute PutPlayerInVehicle.

Код:
new RecentEnterExit[MAX_PLAYERS];


forward RecentEnterExitt(playerid);
public RecentEnterExitt(playerid)
{
	RecentEnterExit[playerid] = 0;
	return 1;
}
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{

	RecentEnterExit[playerid] = 1;
	SetTimerEx("RecentEnterExitt", 3000, false, "i", playerid);
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	new carid = GetPlayerVehicleID(playerid);
    if(RecentEnterExit[playerid] == 1)
    {
		PutPlayerInVehicle(playerid, carid, 0);
		SendClientMessage(playerid, COLOR_ERROR, "Error: You cannot exit so soon.");
    }
	return 1;
}
Any solutions or alternatives?
Reply
#2

You getplayervehicleid when he exit so i think it counts as INVALID_VEHICLE_ID not sure
and also why getid if you allready got in the callback

PHP код:
public OnPlayerExitVehicle(playeridvehicleid)
{
    if(
RecentEnterExit[playerid] == 1)
    {
        
PutPlayerInVehicle(playeridvehicleid0);
        
SendClientMessage(playeridCOLOR_ERROR"Error: You cannot exit so soon.");
    }
    return 
1;

Reply
#3

I managed to fix the problem. I probably posted this prematurely.

It appears that the player is still registered as being inside the vehicle when OnPlayerExitVehicle is called due to the time it takes for the player to actually get out (animnation), therefore I simply removed the player from the vehicle and then PutPlayerInVehicle.


Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(RecentEnterExit[playerid] == 1)
    {
        new Float:Pos[4];
        GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    	SetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]+10);
		PutPlayerInVehicle(playerid, vehicleid, 0);
		SendClientMessage(playerid, COLOR_ERROR, "Error: You cannot exit so soon.");
    }
	return 1;
}


Quote:
Originally Posted by Lokii
Посмотреть сообщение
why getid if you allready got in the callback
I was just tinkering with the code, in an attempt to get it to work. Thanks for your response/support anyway!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)