Skip to content

Tiaansu/samp-cron

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SampCRON

A cron plugin for samp/open.mp in Rust. Made using this library

Installation

  • Download suitable binary files from releases for your operating system.
  • Add it to your plugins folder
  • Add samp_cron to server.cfg (config.json if you're using open.mp) or samp_cron.so (for linux)
  • Add samp_cron.inc in includes folder

Building

  • Clone the repo
git clone https://github.com/Tiaansu/samp-cron.git
  • Install Rust
rustup update stable-i686 --no-self-update && rustup default stable-i686
  • Build using cargo build
cargo build --release

Important

Here's the scheduling format

You must follow it to work

sec   min   hour   day of month   month   day of week   year
*     *     *      *              *       *             *

API

  • cron_new(const pattern[], const callback[], const args[] = "", {Float, _}:...)

    • pattern[] - cron pattern
    • callback[] - callback to execute every call
    • args[] - custom arguments

    Returns
    the cron job id

    Example

    new CRON:cron_id = INVALID_CRON_ID;
    main()
    {
        cron_id = cron_new("* * * * * *", "SecondTimer", "i", 5);
    }
    
    forward SecondTimer();
    public SecondTimer()
    {
        printf("Hi! I am called by cron id: %i and I also have a custom args: %i!", _:cron_id, num);
    }
  • bool:cron_is_valid(CRON:id)

    • id - id of cron job

    Returns
    true - valid
    false - invalid

    Example

    new CRON:cron_id = INVALID_CRON_ID;
    main()
    {
        printf("Is cron job id %i valid? %i", _:cron_id, cron_is_valid(cron_id));
    }
  • bool:cron_delete(CRON:id)

    • id - id of cron job

    Returns
    true - succeed
    false - failed

    Example

    new CRON:cron_id = INVALID_CRON_ID, current = 0;
    main()
    {
        cron_id = cron_new("* * * * * *", "SecondTimer");
    }
    
    forward SecondTimer();
    public SecondTimer()
    {
        if (++ current <= 10)
        {
            printf("%i/10", current + 1);
        }
        else
        {
            printf("Is cron job id %i deleted? %i", _:cron_id, cron_delete(cron_id));
        }
    }

Note

Most of the part of this README is from/based on samp-bcrypt
I'm open for suggestions and corrections as I'm still learning Rust.