Portal SAMP
[Tutorial] Ligar edesligar veículo por tecla - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Guias e Tutoriais (https://portalsamp.com/forumdisplay.php?fid=7)
+--- Tópico: [Tutorial] Ligar edesligar veículo por tecla (/showthread.php?tid=5022)



Ligar edesligar veículo por tecla - Jean_Rocha - 26/05/2025

Tutorial ligar e desligar o veículo por tecla
Obrigado portal samp por poder compartilhar esse momento.



1° Etapa
(Criando as variáveis do sistema)
Vamos criar as seguintes variáveis para a funcionalidade do veículo
Código:
new Motor[MAX_VEHICLES];
new engine,lights,alarm,doors,bonnet,boot,objective;
2° Etapa
(Criando motor para seu veículo)
Vamos começar criando a seguinte public Engine. Essa função será responsável por verificar se o "Motor" do veículo está ligado ou desligado. Essas duas funções chamadas LigandoMotor DesligandoMotor. Obs: Quando você for ligar ou desligar veículo você terá que esperar 1 segundo
Código:
forward Engine(playerid);
public Engine(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return 1;
    if(Motor[vehicleid] == 0)
    {
        SendClientMessage(playerid, -1, "Ligando veículo...");
        SetTimerEx("LigandoMotor",1000, false, "d",playerid);
    }
    else
    {
        SendClientMessage(playerid, -1, "Desligando veículo...");
        SetTimerEx("DesligandoMotor",1000, false, "d",playerid);
    }
    return 1;
}
3° Etapa
(Ligando motor do veículo)
Muito bem! Vamos criar a função public LigandoMotor para ligar o veículo
Código:
forward LigandoMotor(playerid);
public LigandoMotor(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
    SendClientMessage(playerid, -1, "Você ligou o seu veículo.");
    Motor[vehicleid] = 1;
    return 1;
}
4° Etapa
(Desligando motor do veículo)
Muito bem! Vamos criar a função public DesligandoMotor para desligar o veículo
Código:
forward DesligandoMotor(playerid);
public DesligandoMotor(playerid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
    SendClientMessage(playerid, -1, "Você desligou o seu veículo.");
    Motor[vehicleid] = 0;
    return 1;
}
5° Etapa
(Pressione a tecla 2 para ligar ou desligar o veículo)
Ligue e desligue o veículo por tecla
Código:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_LOOK_BEHIND) return Engine(playerid);
    return 1;
}
Resultado
(Vídeo)
Sistema de ligar e desligar o veículo por tecla



RE: Sistema de ligar/desligar veículo por tecla - xbruno1000x - 26/05/2025

Bom tutorial!


RE: Sistema de ligar/desligar veículo por tecla - Jean_Rocha - 27/05/2025

Obrigado xbruno1000x