Portal SAMP
[Ajuda] Verificar se há motorista no carro. - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Área de suporte (https://portalsamp.com/forumdisplay.php?fid=6)
+--- Tópico: [Ajuda] Verificar se há motorista no carro. (/showthread.php?tid=2504)



Verificar se há motorista no carro. - Seck - 22/06/2022

Opa, galera... Preciso de uma ajuda.
Preciso que, qnd um player der dano em outro, se ele estiver em um veículo como passageiro, verifique se há um motorista, se caso eles estiver no carro como passageiro sem um motorista, ejetar ele do carro.

Na public OnPlayerGiveDamage coloquei isso:

if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        new Float:x,Float:y,Float:z;
GetPlayerPos(playerid, x, y, z);
      SetPlayerPos(playerid, x, y, z+0.5);
        return SendClientMessage(playerid, COR_ERRO, "| INFO | O Seu veículo não tem motorista!");
    }


Só que não sei como fazer pra verificar se o veículo tem motorista... 
Se puderem me ajudar, ficarei grato. Tmj


RE: Verificar se há motorista no carro. - MarcosBrazz - 22/06/2022

Altere para:
Código:
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER && !VehicleAsDriver(GetPlayerVehicleID(playerid)))
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);
    SetPlayerPos(playerid, x, y, z+0.5);
    return SendClientMessage(playerid, COR_ERRO, "| INFO | O Seu veículo não tem motorista!");
}
Coloque fora de callbacks:
Código:
stock VehicleAsDriver(vehicleid){
    new stats = 0;
    for(new i; i < MAX_PLAYERS; i++){
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) {
            stats = 1;
            break;
        }
    }
    return stats;
}
OBS: É recomendado a utilização do foreach para esse tipo de loop.


RE: Verificar se há motorista no carro. - Seck - 23/06/2022

(22/06/2022 23:45)MarcosBrazz Escreveu: Altere para:
Código:
if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER && !VehicleAsDriver(GetPlayerVehicleID(playerid)))
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);
    SetPlayerPos(playerid, x, y, z+0.5);
    return SendClientMessage(playerid, COR_ERRO, "| INFO | O Seu veículo não tem motorista!");
}
Coloque fora de callbacks:
Código:
stock VehicleAsDriver(vehicleid){
    new stats = 0;
    for(new i; i < MAX_PLAYERS; i++){
        if(IsPlayerInVehicle(i, vehicleid) && GetPlayerState(i) == PLAYER_STATE_DRIVER) {
            stats = 1;
            break;
        }
    }
    return stats;
}
OBS: É recomendado a utilização do foreach para esse tipo de loop.
Show de bola, funcionou perfeitamente, muito obrigado de verdade irmão! Tmj