SA-MP Forums Archive
Time Functions Help for REP + - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Time Functions Help for REP + (/showthread.php?tid=359020)



Time Functions Help for REP + - WinterAce - 12.07.2012

How do I make a time function for a command I have /loadpackages, so if someone loads packages into their vehicle for the trucker job it doesn't allow them to load any more until 30 minutes later, and on server restart or player re connect the timer stays set?


Re: Time Functions Help for REP + - clarencecuzz - 12.07.2012

pawn Код:
new HasAttemptedToLoadPackagesRecently[MAX_PLAYERS]; //Under Includes - Global

public OnGameModeInit() //Or FilterScriptInit() if you're using a FilterScript
{
    SetTimer("Check", 1000, true);
    return 1;
}

//LOADPACKAGES COMMAND HERE
{
//Add other code here
if(HasAttemptedToLoadPackagesRecently[playerid] > 0)
return SendClientMessage(playerid, 0xFF0000AA, "You must wait 30 minutes before attempting to load packages again.");

//When player loads the packages
HasAttemptedToLoadPackagesRecently[playerid] = 1800000;
}

forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(HasAttemptedToLoadPackagesRecently[i] >= 1)
            {
                HasAttemptedToLoadPackagesRecently[i] --;
            }
        }
    }
    return ;
}
EDIT: Can't do it fully unless you can supply me with your LoadPackages command.


Re: Time Functions Help for REP + - WinterAce - 12.07.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
pawn Код:
new HasAttemptedToLoadPackagesRecently[MAX_PLAYERS]; //Under Includes - Global

public OnGameModeInit() //Or FilterScriptInit() if you're using a FilterScript
{
    SetTimer("Check", 1000, true);
    return 1;
}

//LOADPACKAGES COMMAND HERE
{
//Add other code here
if(HasAttemptedToLoadPackagesRecently[playerid] > 0)
return SendClientMessage(playerid, 0xFF0000AA, "You must wait 30 minutes before attempting to load packages again.");

//When player loads the packages
HasAttemptedToLoadPackagesRecently[playerid] = 1800000;
}

forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(HasAttemptedToLoadPackagesRecently[i] >= 1)
            {
                HasAttemptedToLoadPackagesRecently[i] --;
            }
        }
    }
    return ;
}
EDIT: Can't do it fully unless you can supply me with your LoadPackages command.
I tried setting it to 60000 milliseconds (1 minute) but the timer doesn't refresh. Here's what I have so far:

pawn Код:
new PackageLoading[MAX_PLAYERS]; // Beginning of mode with other 'new' variables

SetTimer("Check", 1000, true); // I added this under another SetTimer under OnGameModeInIt

CMD:loadpackages(playerid, params[]) // This is my /loadpackages command, everything is fine here.
{
    new string[128], packages;
    // L1: 0 | L2: 100 | L3: 300 | L4: 700 | L5: 1200
    if(PlayerInfo[playerid][pJobSkill][JOB_TRUCKER] < 100) packages = 5; //If under level 2
    else if(PlayerInfo[playerid][pJobSkill][JOB_TRUCKER] < 300) packages = 10; //If under level 3
    else if(PlayerInfo[playerid][pJobSkill][JOB_TRUCKER] < 700) packages = 15; //If under level 4
    else if(PlayerInfo[playerid][pJobSkill][JOB_TRUCKER] < 1200) packages = 20; //If under level 5
    else if(PlayerInfo[playerid][pJobSkill][JOB_TRUCKER] >= 1200) packages = 25; //If equals to or over level 5
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to login first before using this command.");
    if(PlayerInfo[playerid][pJob] != JOB_TRUCKER && PlayerInfo[playerid][pVIPJob] != JOB_TRUCKER) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not a Trucker.");
    if(!IsPlayerInAnyVehicle(playerid) || !IsTruckerVehicle(GetPlayerVehicleID(playerid)) || !IsTrailerAttachedToVehicle(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not in a Trucker vehicle or you have no trailer attached.");
    if(!IsPlayerInRangeOfPoint(playerid, 5, -1037.3890,-629.9038,32.0078)) return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not near a packages pickup.");
    if(PlayerInfo[playerid][pMoney] < packages*3) return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have any cash on you.");
    if(PackageLoading[playerid] > 0)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "You need to wait for upto 30 minutes before loading more packages.");
        return 1;
    }
    PlayerInfo[playerid][pTPackages] ++;
    GiveZaiatMoney(playerid, -(packages*3));
    PlayerInfo[playerid][pDeliverTruck] = GetPlayerVehicleID(playerid);
    TruckPackages[GetPlayerVehicleID(playerid)] = playerid;
    format(string, sizeof(string), "%s has loaded %d product packages from the pickup into the truck.", RPN(playerid), packages);
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    format(string, sizeof(string), "You have loaded {FF6347}%d product{33CCFF} packages for {FF6347}$%d{33CCFF}, deliver them to the drop off. (Checkpoint)", packages, packages*5);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    if(PlayerInfo[playerid][pTPackages] >= 1)
    {
        PackageLoading[playerid] = 60000;
    }
    SetPlayerCheckpoint(playerid, 2488.9246,-2080.2800,13.5469, 2);
    return 1;
}

// Then..

forward Check(); // I have this under where it checks if pay check is done
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PackageLoading[i] >= 1)
            {
                PackageLoading[i] --;
            }
        }
    }
    return ;
}
I haven't tested it yet for whether the timer stays set for when a player restarts or the game mode resdtarts, but I also need it for if the timer is on like 30 seconds left, I want it to pause until the player re connects and the timer carries on from where it left off.


Re: Time Functions Help for REP + - clarencecuzz - 12.07.2012

You would have to save it to the player's file if you want to save it.
Here's how you would do it though.

pawn Код:
public OnPlayerDisconnect(playerid)
{
    //Save to user file (PackageLoading[playerid])
    return 1;
}

public OnPlayerConnect(playerid)
{
    PackageLoading[playerid] = //Get Players User file and read.
    return 1;
}
EDIT: Whatever you set PackageLoading[playerid] to, that's the amount of time the player has to wait. Example: 60000 is wait 60 seconds. I'm sure you already knew this but just letting you know.


Re: Time Functions Help for REP + - WinterAce - 12.07.2012

You're the man, perfect. Rep.