Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] YSI Logic user-incomprehension and usage

 
  • 0 Vote(s) - 0 Average
Pawn YSI Logic user-incomprehension and usage
hastlaking
Offline

Burgershot Member
Posts: 25
Threads: 9
Joined: Apr 2019
Reputation: 0
#1
2019-12-17, 04:17 PM
Hello Community, i have this odd incomprehension with the YSI Libraries and most-partial of the documentation is missing or not yet implemented (explanation) into github repository i might say.
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#2
2019-12-17, 08:58 PM
Tell us more about the parts of YSI you are having issues with?
Remember to always refer to J0sh as `J0sh...`

@ Networks/Servers
San Andreas Gaming Network (Owner/Founder)
San Andreas Gaming (Owner/Founder)
Grand Theft Cop's n Robber's (Owner)
Britannia Roleplay (Owner/Founder)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
hastlaking
Offline

Burgershot Member
Posts: 25
Threads: 9
Joined: Apr 2019
Reputation: 0
#3
2019-12-18, 07:17 PM
mainly with timers calling them once on few public callbacks and some to initialize when needed example when player the moment the are logged in
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#4
2019-12-18, 07:39 PM (This post was last modified: 2019-12-18, 07:46 PM by JustMichael.)
Okay, so timers come in two forms, one being a regular timer and another being a repeater. A regular timer has a keyword associated with it called `defer` which means to delay a call to a function, now you can defer a function for n times, n being the number of milliseconds you wish to delay.

An example of this would go as follows:
Code:
main()
{
    // uses the 'defer' keyword to associated it with YSI,
    // and a function name and it's parameters is required afterwards 
    defer CheckPlayer(12);

    // You can override the delay set on the timer function, which is enclosed
    // in square brackets `[500]` by also putting square brackets with a new timer
    // delay inbetween 
    defer CheckPlayer[1000](12); // this will override the delay in the function and instead wait 1 second
    
}

// The 'timer' is a keyword that YSI uses to associated this function with YSI
// The number enclosed within square brackets `[500]` is the number of seconds the timer
// will be delayed for
timer CheckPlayer[500](playerid)
{
    // Perform some checks, or what you would normally do if this was a standard timer (SetTimer(Ex))
    if(IsPlayerConnected(playerid)) {
        printf("The player is connected");
    }
}

We than have repeatable timers. These timers run until manually stopped, and they can be stopped by using the `stop` keyword. To create a repeatable timer, you instead use the `repeat` keyword instead of the `defer` keyword. Here is an example:

Code:
static Timer: repeatable_timer;

main()
{
    // Here we are storing the timer globally, so it can later be stopped else
    // where in the script. Though this is only needed if the timer is to ever be stopped
    // timers are generally managed internally to YSI, so will be stopped when the server exits
    // or when the gamemode ends.
    repeatable_timer = repeat CheckPlayer(12);

    // We can also override the default delay for the function
    repeatable_timer = repeat CheckPlayer[1000](12); // The delay value is overridden to run every 1 second
}

// The 'timer' is a keyword that YSI uses to associated this function with YSI
// The number enclosed within square brackets `[500]` is the number of seconds the timer
// will be delayed for
timer CheckPlayer[500](playerid)
{
    // Perform some checks, or what you would normally do if this was a standard timer (SetTimer(Ex))
    if(IsPlayerConnected(playerid)) {
        printf("The player is connected");
    }

    // Lets now stop the repeatable timer just as an example
    stop repeatable_timer;
}

I hope this is enough to make you understand when to use them and how to use them. Feel free to ask anymore questions :)
Remember to always refer to J0sh as `J0sh...`

@ Networks/Servers
San Andreas Gaming Network (Owner/Founder)
San Andreas Gaming (Owner/Founder)
Grand Theft Cop's n Robber's (Owner)
Britannia Roleplay (Owner/Founder)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode