SA-MP Forums Archive
CMD /oldcar(your last car) and i want /lastdriver(player's last car) - 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: CMD /oldcar(your last car) and i want /lastdriver(player's last car) (/showthread.php?tid=647871)



CMD /oldcar(your last car) and i want /lastdriver(player's last car) - JulianWilliams - 12.01.2018

PHP код:
CMD:oldcar(playeridparams[])
{
    new 
string[128];
    if(!
gLastCar[playerid]) return SendClientMessageEx(playeridCOLOR_GREY"You have not driven a vehicle yet.");
    
format(stringsizeof(string), "Your last driven vehicle was a %s (Model: %d -- ID: %d)"GetVehicleName(gLastCar[playerid]), GetVehicleModel(gLastCar[playerid]), gLastCar[playerid]);
    
SendClientMessageEx(playeridCOLOR_GREYstring);
    return 
1;

This is the cmd /oldcar to check the last vehicle you used.

I want a cmd that can check the last driver that used the car /lastdriver.


Re: CMD /oldcar(your last car) and i want /lastdriver(player's last car) - Rolux - 12.01.2018

Its only works when you are sitting in a vehicle.
I didn't test it.
Код:
new lastDriver[MAX_VEHICLES] = -1; //-1 will mean that nobody used that car bafore.

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        lastDriver[vehicleid] = playerid;
    }
    return 1;
}

CMD:lastdriver(playerid)
{
	if(IsPlayerInAnyVehicle(playerid)) return 0;
	new
		vehicleid = GetPlayerVehicleID(playerid),
		lastString[MAX_PLAYER_NAME],
		_str[52];
	
	if(lastDriver[vehicleid] != -1)// Someone already used that car:
	{
    	GetPlayerName(lastDriver[vehicleid], lastString, sizeof(lastString));
		format(_str,sizeof(_str),"This vehicle was used by: %s",lastString);
		SendClientMessage(playerid,-1,_str);
	}else{
		SendClientMessage(playerid,-1,"Nobody has driven that car before.");
	}
	return 1;
}



Re: CMD /oldcar(your last car) and i want /lastdriver(player's last car) - Lucases - 12.01.2018

Quote:
Originally Posted by Rolux
Посмотреть сообщение
Its only works when you are sitting in a vehicle.
I didn't test it.
Код:
new lastDriver[MAX_VEHICLES] = -1; //-1 will mean that nobody used that car bafore.

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        lastDriver[vehicleid] = playerid;
    }
    return 1;
}

CMD:lastdriver(playerid)
{
	if(IsPlayerInAnyVehicle(playerid)) return 0;
	new
		vehicleid = GetPlayerVehicleID(playerid),
		lastString[MAX_PLAYER_NAME],
		_str[52];
	
	if(lastDriver[vehicleid] != -1)// Someone already used that car:
	{
    	GetPlayerName(lastDriver[vehicleid], lastString, sizeof(lastString));
		format(_str,sizeof(_str),"This vehicle was used by: %s",lastString);
		SendClientMessage(playerid,-1,_str);
	}else{
		SendClientMessage(playerid,-1,"Nobody has driven that car before.");
	}
	return 1;
}

Inefficient code. You store only the id and don't check if it's connected. Also if that player logs out and someone else joins with the same ID you'll receive wrong informations.You shouuld store the name in an array so you won't have problems.


Re: CMD /oldcar(your last car) and i want /lastdriver(player's last car) - Rolux - 12.01.2018

Yeah, you are right!
+ If you enter a vehicle you will become the last driver,so this command is useless.


Re: CMD /oldcar(your last car) and i want /lastdriver(player's last car) - Lucases - 12.01.2018

Quote:
Originally Posted by Rolux
Посмотреть сообщение
Yeah, you are right!
+ If you enter a vehicle you will become the last driver,so this command is useless.
Infact the last should be update only when the player exites the vehicle, not when he enters.