Timer question
#1

Is it possible to save the timer into my mysql database and make it continue going down for a command like this. How so?
pawn Код:
CMD:dropcar(playerid,params[])
{
    if(!IsPlayerInDynamicCP(playerid,exportcp)) return SCM(playerid,red,"ERROR: You are not in the Export CP, use /dropcarcp");
    if(dropcartime[playerid] == 1) return SCM(playerid,red,"You must wait 2 minutes to export again");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playerid,red,"ERROR: You are not driving a vehicle");
    for(new i = 0;i<MAX_ORGS;i++)
    {
        if(IsPlayerInVehicle(playerid,OrgInfo[i][Car1])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car2])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car3])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car4])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car5])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car6])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car7])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
        else if(IsPlayerInVehicle(playerid,OrgInfo[i][Car8])) return SCM(playerid,red,"ERROR: You cannot export an organization vehicle");
    }
    for(new i = 0;i<MAX_JOBS;i++)
    {
        if(IsPlayerInVehicle(playerid,JobInfo[i][Car1])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car2])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car3])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car4])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car5])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car6])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car7])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
        else if(IsPlayerInVehicle(playerid,JobInfo[i][Car8])) return SCM(playerid,red,"ERROR: You cannot export a job vehicle");
    }
    foreach(Player,i)
    {
        if(IsPlayerInVehicle(playerid,CarSystem[i][vID])) return SCM(playerid,red,"ERROR: You can't give a vehicle that's owned by someone.");
    }
    if(PlayerData[playerid][DropCarAmount] == 9)
    {
        SCM(playerid,lightyellow,"You have increased your Drop Car Level to 1");
        PlayerData[playerid][DropCarLevel] = 1;
    }
    if(PlayerData[playerid][DropCarAmount] == 19)
    {
        SCM(playerid,lightyellow,"You have increased your Drop Car Level to 2");
        PlayerData[playerid][DropCarLevel] = 2;
    }
    if(PlayerData[playerid][DropCarAmount] == 29)
    {
        SCM(playerid,lightyellow,"You have increased your Drop Car Level to 3");
        PlayerData[playerid][DropCarLevel] = 3;
    }
    if(PlayerData[playerid][DropCarAmount] == 49)
    {
        SCM(playerid,lightyellow,"You have increased your Drop Car Level to 4");
        PlayerData[playerid][DropCarLevel] = 4;
    }
    if(PlayerData[playerid][DropCarAmount] == 99)
    {
        SCM(playerid,lightyellow,"You have increased your Drop Car Level to 5");
        PlayerData[playerid][DropCarLevel] = 5;
    }
    if(PlayerData[playerid][DropCarLevel] == 0)
    {
        new randmon = 1000 + random(4000);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
        SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
    }
    if(PlayerData[playerid][DropCarLevel] == 1)
    {
        new randmon = 1500 + random(4500);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
        SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
    }
    if(PlayerData[playerid][DropCarLevel] == 2)
    {
        new randmon = 2000 + random(5000);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
        SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
    }
    if(PlayerData[playerid][DropCarLevel] == 3)
    {
        new randmon = 2500 + random(6500);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
        SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
    }
    if(PlayerData[playerid][DropCarLevel] == 4)
    {
        new randmon = 3000 + random(6000);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
        SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
    }
    if(PlayerData[playerid][DropCarLevel] == 5)
    {
        new randmon = 5000 + random(10000);
        if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
        PlayerData[playerid][DropCarAmount] += 1;
        dropcartime[playerid] = gettime() + 120;
        format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
        SCM(playerid,COLOR_YELLOW,str);
        GivePlayerMoney(playerid,randmon);
        SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        exported[playerid] = 1;
    }
    return 1;
}
Reply
#2

bump
Reply
#3

bump
Reply
#4

Figure out how many seconds there is left and save that, then when they relog dropcartime[playerid] = gettime() + secondsleft; also, you have a lot of copy and paste code you can save a lot of lines here doing the following.

pawn Код:
new randmon;
    if(PlayerData[playerid][DropCarLevel] == 0) randmon = 1000 + random(4000);
    if(PlayerData[playerid][DropCarLevel] == 1) randmon = 1500 + random(4500);
    if(PlayerData[playerid][DropCarLevel] == 2) randmon = 2000 + random(5000);
    if(PlayerData[playerid][DropCarLevel] == 3) randmon = 2500 + random(6500);
    if(PlayerData[playerid][DropCarLevel] == 4) randmon = 3000 + random(6000);
    if(PlayerData[playerid][DropCarLevel] == 5) randmon = 5000 + random(10000);
   
    if(dropcartime[playerid] > - 1) return SCM(playerid,red,"ERROR: You still need to wait to give a vehicle again.");
    PlayerData[playerid][DropCarAmount] += 1;
    dropcartime[playerid] = gettime() + 120;
    format(str,sizeof(str),"You have exported this vehicle and got $%d",randmon);
    SCM(playerid,COLOR_YELLOW,str);
    GivePlayerMoney(playerid,randmon);
    SetVehicleToRespawn(GetPlayerVehicleID(playerid));
    exported[playerid] = 1;
    if(PlayerData[playerid][DropCarLevel] < 5) SCM(playerid,COLOR_LIMEGREEN,"Use /dropcarlevels to see how many vehicles you need to give to level up your skill");
Was 77 lines now 18 for the exact same thing.

Avoid copy/paste it's a terrible practice.
Reply
#5

Or, use a timestamp...
Reply
#6

i want to time to continue going on if they quit the server, how i use timestamp?
Reply


Forum Jump:


Users browsing this thread: