SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 02/07/2012, 10:42 AM   #1
Glint
Guest
 
Posts: n/a
Default Random Messages Using y_timers

Create Random Messages Using y_timers

YSI contains libraries that has more functions then what you think, these functions are designed to save us time and speed up our script, one of these libraries is the y_timers library, when i first begun scripting about 2 years ago i was still using normal timers which is a performance issue if you have more then 10 timers, why ? well because this big amount of timers has a very HUGE impact on you Gamemode's performance, nevertheless i wasn't aware of y_timers until 2 days ago i was looking around the YSI topic and found, because my work was based on using, y_ini, y_commands, so i forgot about the others and how handy the come if you use them wisely. However in this tutorial i am going to teach you how to save time and a little bit of space by using the tasks function in the y_timers, you may now wonder what is tasks, well tasks are simply functions that Gets called at the amount of time you specify, enough talking, let's get working.
What Do We Need ?

Before we start the tutorial we need y_timers, which can be found in the YSI library which can be found Here
Let's Get Started

Step 1
Open a new clean .pwn document and add the followings on top :
pawn Code:
#include    <a_samp>
#include    <YSI\y_timers>
these are the includes the a_samp is the ordeal SA:MP functions that we get (must be included in every script you make), and the y_timers include that we are going to use, note that there is YSI in front of it meaning load y_timers from the YSI folder in your includes folder
Step 2
Now under your includes define the color that will be used when sending the Random Messages to the players, simply add.
pawn Code:
#define Red 0xFF0000AA
Under Your Includes
Step 3
Now we are going to create an array for our Random Messages, that will contain the random messages, like the following
pawn Code:
new randomMessages[][] =
{
    "Random Message 1",
    "Random Message 2",
    "Random Message 3"
};
you can add as many as messages as you want.
Step 4
Now anywhere in your script add the following function (the task function)
pawn Code:
task RandomMessages[1000]()
{
    new randomMsg = random(sizeof(randomMessages));
    SendClientMessageToAll(Red, randomMessages[randomMsg]);
    print(randomMessages[randomMsg]);
}
as you can see here this is a task that is used by y_timers, the 1000 is the time that this function repeats itself in our case every second, change the time to any time you want.

That is it you now have the simplest Random Message system.
Credits


Y_Less - YSI & y_timers
  Reply With Quote
Old 02/07/2012, 10:51 AM   #2
mehdi-jumper
High-roller
 
mehdi-jumper's Avatar
 
Join Date: Sep 2011
Location: New-Zealand
Posts: 1,894
Reputation: 51
Default Re : Random Messages Using y_timers

I didn't understand why do you need y_timers include? you can make it without that.
mehdi-jumper is offline   Reply With Quote
Old 02/07/2012, 10:55 AM   #3
Glint
Guest
 
Posts: n/a
Default Re: Re : Random Messages Using y_timers

Quote:
Originally Posted by mehdi-jumper View Post
I didn't understand why do you need y_timers include? you can make it without that.
Yes you can by using the old classic way this uses tasks which is a function of y_timers you can read more about it Here
  Reply With Quote
Old 02/07/2012, 11:24 AM   #4
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 17,546
Reputation: 2438
Default Re: Re : Random Messages Using y_timers

Quote:
Originally Posted by mehdi-jumper View Post
I didn't understand why do you need y_timers include? you can make it without that.
You can also write commands without sscanf, stream objects without the plugin, work around problems without fixes.inc, save files without an ini script, and ban people without an anti-cheat script! These all must build on top of the default functions so you don't NEED any of them, but that doesn't mean they don't have advantages. So yes you CAN do it without, but why would you?
Y_Less is offline   Reply With Quote
Old 02/07/2012, 11:48 AM   #5
Mr.Fames
Huge Clucker
 
Join Date: Oct 2011
Posts: 350
Reputation: 24
Default Re: Random Messages Using y_timers

Good job on the tutorial, and thanks for the information i honestly didn't know that you can make functions with integrated timer's so easily
Mr.Fames is offline   Reply With Quote
Old 02/07/2012, 12:12 PM   #6
Saad_
Big Clucker
 
Saad_'s Avatar
 
Join Date: Feb 2012
Posts: 67
Reputation: 10
Default Re: Random Messages Using y_timers

Good tutorial
Saad_ is offline   Reply With Quote
Old 04/07/2012, 06:16 PM   #7
MdeRooy
Big Clucker
 
MdeRooy's Avatar
 
Join Date: Mar 2011
Posts: 63
Reputation: 0
Default Re: Random Messages Using y_timers

Well made tutorial! Easy to follow and well written!
MdeRooy is offline   Reply With Quote
Old 04/07/2012, 06:38 PM   #8
Glint
Guest
 
Posts: n/a
Default Re: Random Messages Using y_timers

Quote:
Originally Posted by MdeRooy View Post
Well made tutorial! Easy to follow and well written!
Thank you.
  Reply With Quote
Old 04/07/2012, 07:16 PM   #9
Kathleen
Huge Clucker
 
Join Date: May 2012
Location: Netherland
Posts: 212
Reputation: 18
Default Re: Random Messages Using y_timers

Very easy and nice
__________________
dsd
Kathleen is offline   Reply With Quote
Old 04/07/2012, 07:26 PM   #10
Glint
Guest
 
Posts: n/a
Default Re: Random Messages Using y_timers

Quote:
Originally Posted by Kathleen View Post
Very easy and nice
I am happy you like it thanks.
  Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Random Messages (Yes another one) FireCat Tutorials 16 09/01/2013 04:39 AM
need help with random messages Woozie® Help Archive 6 26/07/2011 03:23 PM
[HELP] Random Messages Monster[HD] Help Archive 2 16/04/2011 08:32 PM
[FilterScript] P-Messages [Random Messages system] Pooh7 Filterscripts 5 30/11/2010 04:43 PM
How Can i put random messages [SU]CHRiS Help Archive 8 03/02/2010 10:27 PM


All times are GMT. The time now is 04:23 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.