Lock & unlock vehicle
#1

Hi,

Why this command doesn't working correctly? I always got message "Vehicle is locked". I want to make, if vehicle is locked - unlock it and if unlocked - lock.

Код:
COMMAND:asd(playerid, params[])
{
	new
		Tekstas[ 50 ],
		vehicleid = GetPlayerVehicleID( playerid ),
		engine,
		lights,
		alarm,
		doors,
		bonnet,
		boot,
		objective
	;
	GetVehicleParamsEx( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective );

	if( doors == VEHICLE_PARAMS_ON ) // Jeigu uћrakinta - atrakinam
	{
	    for( new i; i < MAX_PLAYERS; i++ )
	    {
			SetVehicleParamsForPlayerEx( vehicleid, i, 0, VEHICLE_PARAMS_OFF );
	    }
	    Tekstas = "Vehicle is unlocked";
	}
	else // Jeigu atrakinta - uћrakinam
	{
	    for( new i; i < MAX_PLAYERS; i++ )
	    {
			SetVehicleParamsForPlayerEx( vehicleid, i, 0, VEHICLE_PARAMS_ON );
	    }
	    Tekstas = "Vehicle is locked";
	}
	SendClientMessage( playerid, -1, Tekstas );
	return 1;
}
Код:
new
	VehiclesObj[ MAX_VEHICLES ][ MAX_PLAYERS ],
	VehiclesLock[ MAX_VEHICLES ][ MAX_PLAYERS ]
;
Код:
stock SetVehicleParamsForPlayerEx( vehicleid, playerid, objective, doors )
{
	VehiclesObj[ vehicleid ][ playerid ] = objective;
	VehiclesLock[ vehicleid ][ playerid ] = doors;
	if( IsVehicleStreamedIn( vehicleid, playerid ) )
	    return SetVehicleParamsForPlayer( vehicleid, playerid, objective, doors );
	return 1;
}
Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
	SetVehicleParamsForPlayer( vehicleid, forplayerid, VehiclesObj[ vehicleid ][ forplayerid ], VehiclesLock[ vehicleid ][ forplayerid ] );
	return 1;
}
Thanks!
Reply
#2

pawn Код:
COMMAND:asd(playerid, params[])
{
    new
        vehicleid = GetPlayerVehicleID( playerid ),
        engine,
        lights,
        alarm,
        doors,
        bonnet,
        boot,
        objective
    ;
    GetVehicleParamsEx( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective );

    if( doors == VEHICLE_PARAMS_ON ) // Jeigu uћrakinta - atrakinam
    {
        for( new i; i < MAX_PLAYERS; i++ )
        {
            SetVehicleParamsForPlayerEx( vehicleid, i, 0, VEHICLE_PARAMS_OFF );
        }
        SendClientMessage( playerid, -1, "Vehicle is unlocked!" );
        return true; // The fix for your problem. You have to stop here, because now the doors are locked,
                   // the script continues. Since the doors are locked, the script will unlock them below,
                   // because you didn't stop the function when you locked them. Hope this makes sense.
    }
    else // Jeigu atrakinta - uћrakinam
    {
        for( new i; i < MAX_PLAYERS; i++ )
        {
            SetVehicleParamsForPlayerEx( vehicleid, i, 0, VEHICLE_PARAMS_ON );
        }
        SendClientMessage( playerid, -1, "Vehicle is locked!" );
        return true;
    }
}
Reply
#3

Hmmm, your variant doesn't working too... I always get message "Vehicle is locked!".
Reply
#4

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Hmmm, your variant doesn't working too... I always get message "Vehicle is locked!".
Have you tried using SetVehicleParamsEx?
Reply
#5

Ups... Sorry for wasting your time. SetVehicleParamsEx work.
Reply
#6

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Ups... Sorry for wasting your time. SetVehicleParamsEx work.
I'm glad i helped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)