Portal SAMP
[Lançamento] cruise Control mobile - Versão de Impressão

+- Portal SAMP (https://portalsamp.com)
+-- Fórum: SA-MP (https://portalsamp.com/forumdisplay.php?fid=5)
+--- Fórum: Lançamentos (https://portalsamp.com/forumdisplay.php?fid=26)
+---- Fórum: Gamemodes (https://portalsamp.com/forumdisplay.php?fid=8)
+---- Tópico: [Lançamento] cruise Control mobile (/showthread.php?tid=5064)



cruise Control mobile - ANDREX - 28/07/2025

fala povo criei esse script chamado de cruise Control , oq ele faz? simplesmente ao usar o comando /cruise ele e ativado ao aperta o acelerador no Android conhecido por KEY_SPRINT ele lhe dará uma velocidade aocaoertar novamente outra coloquei 5 velocidades iguais aos carros dos npc que dirige pelas ruas no GTA offline isso uma fs você não precisa ficar segurando o botão de acelerar apertou um vez o veículo já anda automaticamente espero q gostem se quiserem modificar a velocidade fiquem a vontade , ah lembrando para reduzir e só usar o botão do freio conhecido por KEY_JUMP 
caso alguém queira modificar para Pc e só mudar as teclas para acelerar KEY_UP conhecido por tecla W e KEY_DOWN conhecido pelo S que geralmente freia 
Código:
#include a_samp
#include zcmd

main() {
    printf("Cruise Control v1.0 criado por ANDREX\n");
}

new bool:CruiseControlActive[MAX_PLAYERS];
new CruiseSpeedLevel[MAX_PLAYERS];
new Float:CruiseSpeeds[] = {
    0.0, // Parado
    0.16, // devagar, como IA no trânsito lento
    0.26, // urbano normal
    0.36, // média
    0.46, // rápido (rodovia)
    0.56 // bem rápido (máximo comum)
};

new bikeModels[] = {448, 461, 462, 463, 468, 521, 522, 581, 586};
stock IsBike(modelid) {
    for (new i = 0; i < sizeof(bikeModels); i++) {
        if (modelid == bikeModels[i]) {
            return 1;
        }
    }
    return 0;
}

CMD:cruise(playerid, params[]) {
    if (CruiseControlActive[playerid]) {
        CruiseControlActive[playerid] = false;
        GameTextForPlayer(playerid, "~r~Cruzeiro desativado", 2000, 3);
    } else {
        CruiseControlActive[playerid] = true;
        GameTextForPlayer(playerid, "~g~Cruzeiro ativado", 2000, 3);
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    if (CruiseControlActive[playerid]) {
        if (newkeys & KEY_SPRINT && !(oldkeys & KEY_SPRINT)) {
            if (CruiseSpeedLevel[playerid] < sizeof(CruiseSpeeds) - 1) {
                CruiseSpeedLevel[playerid]++;
                new msg[64];
                format(msg, sizeof msg, "~g~Cruise: %.0f km/h", CruiseSpeeds[CruiseSpeedLevel[playerid]] * 120.0);
                GameTextForPlayer(playerid, msg, 2000, 3);
            }
        } else if (newkeys & KEY_JUMP && !(oldkeys & KEY_JUMP)) {
            if (CruiseSpeedLevel[playerid] > 0) {
                CruiseSpeedLevel[playerid]--;
                new msg[64];
                format(msg, sizeof msg, "~r~Cruise: %.0f km/h", CruiseSpeeds[CruiseSpeedLevel[playerid]] * 120.0);
                GameTextForPlayer(playerid, msg, 2000, 3);
            } else {
                CruiseControlActive[playerid] = false;
                GameTextForPlayer(playerid, "~r~Cruzeiro desativado", 2000, 3);
            }
        }
    }
    return 1;
}

public OnPlayerUpdate(playerid) {
    if (CruiseControlActive[playerid]) {
        new vehicleid = GetPlayerVehicleID(playerid);
        new Float:z;
        GetVehicleZAngle(vehicleid, z);
        new Float:speed = CruiseSpeeds[CruiseSpeedLevel[playerid]];
        new Float:velx, Float:vely, Float:velz;
        GetVehicleVelocity(vehicleid, velx, vely, velz);
       
        new Float:x = floatsin(-z, degrees) * speed;
        new Float:y = floatcos(-z, degrees) * speed;
        SetVehicleVelocity(vehicleid, x, y, velz);
       
        new Float:health;
        GetVehicleHealth(vehicleid, health);
        if (health < 900.0) {
            CruiseControlActive[playerid] = false;
            CruiseSpeedLevel[playerid] = 0;
            SetVehicleVelocity(vehicleid, 0.0, 0.0, 0.0);
            GameTextForPlayer(playerid, "~r~Cruzeiro desativado devido a danos", 2000, 3);
        }
    }
    return 1;
}

public OnVehicleDamageStatusUpdate(vehicleid) {
    for (new i = 0; i < MAX_PLAYERS; i++) {
        if (GetPlayerVehicleID(i) == vehicleid) {
            if (IsBike(GetVehicleModel(vehicleid))) {
                if (CruiseControlActive[i]) {
                    CruiseControlActive[i] = false;
                    CruiseSpeedLevel[i] = 0;
                    SetVehicleVelocity(vehicleid, 0.0, 0.0, 0.0);
                    GameTextForPlayer(i, "~r~Cruzeiro desativado devido a danos", 2000, 3);
                }
            }
        }
    }
    return 1;
}