SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 02/01/2012, 06:26 PM   #1
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Random Servermessages

Hello SAMP Community!

Today i want to show you, a tutorial how you create random Servermessages

What we need:
1. Pawno

2. Brain

3. A little bit of your lifetime

So Let`s go!

At first we define a forward at the top of the script:

Code:
forward Servermessage();
Then you go to

Code:
public OnGameModeInit
and create a Timer

Code:
SetTimer("Servermessage",1800000,1);
Explanations:

SetTimer = CreateTimer
Servermessage= function of the timer
1 = [true] Is for repeating [2=[false] Is for not repeating]

So, we have created a Timer, but he isn`t helpfull!

You make in your Script a new public, like that:

Code:
public Servermessage()
{
 return 1;
}
Now it comes the random function.

We add this (
Code:
new rand = random(2);
) to our public :

Code:
public Servermessage()
{
 new rand=random(2);
 return 1;
}
Explanations:

new rand mean, that we create a new variable
random(2) , because Pawno select the case 0 or case 1!

Now it`s look like this:

Code:
public Servernachricht()
{
new rand=random(2);
return 1;
}
The random select case 0 or case 1, but we haven`t case 0 or case 1....Let`s make it!

Code:
switch(rand) 
{
case 0: //If random select case 0
{
SendClientMessageToAll(-1,"Your Message!");
}
case 1: //If Random select case 1
{
 SendClientMessageToAll(-1,"Your Message!");
}
Now....It`s all that you have to do, to make random Servermessages

It look`s now like this:

Code:
public Servernachricht()
{
new rand=random(2);
switch(rand) 
{
case 0:
{
SendClientMessageToAll(-1,"Your Message!");
}
case 1:
{
 SendClientMessageToAll(-1,"Your Message!");
}
return 1;
}
This is my first Tutorial! Please don`t be hard with me :'D. And I`m German, sorry for the bad english!

Feedback is Welcome!


Greetz,

#Pwn.
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 02/01/2012, 06:37 PM   #2
Littlehelper
Gangsta
 
Littlehelper's Avatar
 
Join Date: Nov 2011
Location: 420
Posts: 972
Reputation: 178
Default Re: Random Servermessages

Hello,
It has some bugs + SendClientMessageToAll(playerid? it must not have playerid only SendClientMessageToAll(-1, " Welcome To My Server");
kthxbai
EDIT: No, but atleast test the code before posting.
__________________
Quote:
<Norsehawk> If pigs flew, we'd need stronger umbrellas
<Norsehawk> and if my cat shat gold, I would be rich...

Last edited by Littlehelper; 02/01/2012 at 07:24 PM.
Littlehelper is offline   Reply With Quote
Old 02/01/2012, 06:39 PM   #3
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default AW: Random Servermessages

Hello,

Thanks (: I edit it!

Is it bad for my first Tutorial?
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 02:40 AM   #4
[Nikk]
High-roller
 
[Nikk]'s Avatar
 
Join Date: Jun 2011
Location: Argentina.
Posts: 1,522
Reputation: 52
Default Respuesta: Random Servermessages

Good tutorial, but are diferent ways of do this, more short and easy
__________________
[Nikk] is offline   Reply With Quote
Old 03/01/2012, 09:04 AM   #5
[SP]Mr.Kakashi[WP]
Little Clucker
 
[SP]Mr.Kakashi[WP]'s Avatar
 
Join Date: Oct 2011
Location: Philippines
Posts: 33
Reputation: 1
Default Re: Random Servermessages

This is good tutorial but like Nikk says theres more short and easy code for this. but i prefer this is good.
__________________
If i ever help you please click in the left side.

Xtreme Roleplay is current underconstruction. but the server is
hosted in Hamachi we current need Administrator/Scripter/Mapper
if you want to associate with me or became one of our scripter/mapper please PM me.
we current doing our best to finish the server in time
[SP]Mr.Kakashi[WP] is offline   Reply With Quote
Old 03/01/2012, 09:52 AM   #6
#Pwn.
Little Clucker
 
#Pwn.'s Avatar
 
Join Date: Jan 2012
Location: Oberbayern
Posts: 31
Reputation: 3
Default Re: Random Servermessages

Thanks ! Its my first tutorial
__________________
#Pwn. what else?
Progress of [SAL]San Andreas Live

5%/100 %

HP: www.sal-roleplay.de

My Tutorials :
Yes, I am German :3
#Pwn. is offline   Reply With Quote
Old 03/01/2012, 10:56 AM   #7
luckie12
Huge Clucker
 
Join Date: Mar 2009
Posts: 312
Reputation: 0
Default Re: Random Servermessages

Getting a error @ Return 1;

error 002: only a single statement (or expression) can follow each "case"
__________________
luckie12 is offline   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
[Include] Insanity Random Lists(generate a random number from your list) CyNiC Includes 10 23/07/2011 01:45 PM
Random payment to Random player ViruZZzZ_ChiLLL Help Archive 1 01/05/2010 05:43 PM
Random location + Random skin Naruto4 Help Archive 2 03/12/2009 05:07 PM
new mode = random(1); lets pawno crash + mode = random number FOR all public's hipy Help Archive 3 23/07/2009 08:50 PM


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


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