small /engine bug
#1

My /engine command can get spammed, you can use it several times, but I'd like to have a timer on it, for example 5 seconds to attempt to start it again.

pawn Код:
if(strcmp(cmd, "/engine", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
            {
                SendClientMessage(playerid,COLOR_GREY," You are not even inside a vehicle.");
                return 1;
            }
            if (IsNotAEngineCar(idcar))
            {
                SendClientMessage(playerid,COLOR_GREY," This vehicle doesn't even have a Engine.");
                return 1;
            }
            if(idcar >= 33 && idcar <= 38)
            {
                if(HireCar[playerid] != idcar)
                {
                    return 1;
                }
            }
            if(idcar >= 1 && idcar <= 9)
            {
                if(HireCar[playerid] != idcar)
                {
                    return 1;
                }
            }
            if(IsAnOwnableCar(idcar))
            {
                if(veh1[playerid] == VehicleOwned[idcar]) { }
                else if(veh2[playerid] == VehicleOwned[idcar]) { }
                else if(veh3[playerid] == VehicleOwned[idcar]) { }
                else if(veh4[playerid] == VehicleOwned[idcar]) { }
                else if(veh5[playerid] == VehicleOwned[idcar]) { }
                else { return 1; }
            }
            GetPlayerName(playerid, sendername, sizeof(sendername));
            GiveNameSpace(sendername);
            if(PlayerInfo[playerid][pMaskUse] == 1) { format(sendername, sizeof(sendername), "Stranger_%d", RandMask[playerid]); }
            ReduceTime[playerid] = 3;
            if (VehicleEngine[idcar] == 0)
            {
                format(string, sizeof(string), "%s spins the %s's key into the ignition and tries to turn on the engine.", sendername, VehicleName[GetVehicleModel(idcar)-400]);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                SetTimerEx("vehEngine", 2000, 0, "d", playerid);
                return 1;
            }
            else if (VehicleEngine[idcar] == 1)
            {
                VehicleEngine[idcar] = 0;
                format(string, sizeof(string), "%s spins the %s's key into the ignition and turns the engine off.", sendername, VehicleName[GetVehicleModel(idcar)-400]);
                ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                TogglePlayerControllable(playerid,false);
                VehAsk[playerid] = 1;
                return 1;
            }
        }
        return 1;
    }
Reply
#2

Hello!

You have to add at TOP of your code:
pawn Код:
new LastTimeEngine[MAX_PLAYERS];
at OnPlayerConnect:
pawn Код:
LastTimeEngine[playerid] = 0;
Command:
pawn Код:
if(strcmp(cmd, "/engine", true) == 0)
{
    if(LastTimeEngine[playerid]+5000 > GetTickCount()) //The last saved tick + 5 seconds must not be higher than the current tick
    {
        SendClientMessage(playerid,COLOR_GREY," You can only use this command every 5 seconds.");
        return 1;
    }
    if(IsPlayerConnected(playerid))
    {
        if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)
        {
            SendClientMessage(playerid,COLOR_GREY," You are not even inside a vehicle.");
            return 1;
        }
        if (IsNotAEngineCar(idcar))
        {
            SendClientMessage(playerid,COLOR_GREY," This vehicle doesn't even have a Engine.");
            return 1;
        }
        if(idcar >= 33 && idcar <= 38)
        {
            if(HireCar[playerid] != idcar)
            {
                return 1;
            }
        }
        if(idcar >= 1 && idcar <= 9)
        {
            if(HireCar[playerid] != idcar)
            {
                return 1;
            }
        }
        if(IsAnOwnableCar(idcar))
        {
            if(veh1[playerid] == VehicleOwned[idcar]) { }
            else if(veh2[playerid] == VehicleOwned[idcar]) { }
            else if(veh3[playerid] == VehicleOwned[idcar]) { }
            else if(veh4[playerid] == VehicleOwned[idcar]) { }
            else if(veh5[playerid] == VehicleOwned[idcar]) { }
            else { return 1; }
        }
        GetPlayerName(playerid, sendername, sizeof(sendername));
        GiveNameSpace(sendername);
        if(PlayerInfo[playerid][pMaskUse] == 1) { format(sendername, sizeof(sendername), "Stranger_%d", RandMask[playerid]); }
        ReduceTime[playerid] = 3;
        LastTimeEngine[playerid] = GetTickCount();  //We get the current tick count.
        if (VehicleEngine[idcar] == 0)
        {
            format(string, sizeof(string), "%s spins the %s's key into the ignition and tries to turn on the engine.", sendername, VehicleName[GetVehicleModel(idcar)-400]);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            SetTimerEx("vehEngine", 2000, 0, "d", playerid);
            return 1;
        }
        else if (VehicleEngine[idcar] == 1)
        {
            VehicleEngine[idcar] = 0;
            format(string, sizeof(string), "%s spins the %s's key into the ignition and turns the engine off.", sendername, VehicleName[GetVehicleModel(idcar)-400]);
            ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
            TogglePlayerControllable(playerid,false);
            VehAsk[playerid] = 1;
            return 1;
        }
    }
    return 1;
}
I hope this helps you.

Jeffry
Reply
#3

gettime() would be a better solution.
Reply
#4

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
gettime() would be a better solution.
Yes, you are right.

@freshOrange:
If you want to use gettime() then:

Change GetTickCount() to gettime() and
+5000 to +5

I've just read @ GetTickCount that it might cause problems if the server runs for more than 24 days.

Jeffry
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)