09.05.2011, 23:15
(
Последний раз редактировалось grand.Theft.Otto; 28.06.2011 в 20:57.
)
[BEGINNER] How to Change your Hostname Frequently
Hey guys, I will be showing you how to change your server host name using a timer. I haven't seen another tutorial on this yet, but I have seen many people asking this question. Lets start.
Adding this to a gamemode is very easy and should you have no problem doing this.Hey guys, I will be showing you how to change your server host name using a timer. I haven't seen another tutorial on this yet, but I have seen many people asking this question. Lets start.
Rating Level: Beginner
Now, lets really start...
FIRST OFF...
Lets name the function as: ChangeHostName
Add to the top of the script...
pawn Код:
forward ChangeHostName();
SECOND OFF...
Lets add the timer for our ChangeHostName.Add this under OnGameModeInit...
pawn Код:
SetTimer("ChangeHostName",1000,1);
SetTimer - We are setting the timer/function up.
ChangeHostName - Name of the function we defined at the top of our script
2000 - 2 seconds (in-game and real life time in milliseconds)
1 - Will the timer repeat and change the host name to something different over and over every 2 seconds or will it change once and that's it?
Little more detail...
0 = False - will change the hostname ONCE
1 = True - will change the hostname every 2 seconds
We will obviously use 1 (true) because we want our hostname to change every 2 seconds!
3RD OFF...
pawn Код:
public ChangeHostName()
{
new var = random(3); //(Change the 3 to a different number if you are adding more message or deleting)
switch (var)
{
case 0: SendRconCommand("hostname Message 1"); // WARNING: Do not delete the word 'hostname' from here
case 1: SendRconCommand("hostname Message 2"); // WARNING: Do not delete the word 'hostname' from here
case 2: SendRconCommand("hostname Message 3"); // WARNING: Do not delete the word 'hostname' from here
}
}
public ChangeHostName - Our callback which will hold everything to do with your ChangeHostName function
new messages = random(3) - A new variable we will use to switch/hold our message(s)
switch(messages) - Very similar to if statements, but easier and we can use a case statement
case 0,1,2 - These are a part of the switch statements and will hold our messages
SendRconCommand(hostname) - This will send the remote console command "hostname" to the console which will make our messages change every 2 seconds
WARNING: Do not delete the word 'hostname' from here, else it will not work.
END...
OTHER INFORMATION:
For more information about switches and cases, refer to this link: https://sampwiki.blast.hk/wiki/Control_StructuresIf I am missing anything important or if you do not understand, please let me know below.
Please note: I cannot guarantee you 100% the hostname will change every 2 seconds, it may change every 1 second at times and every 3 or 4 seconds depending on your connection. 2 seconds is the average amount of time it will change.
Remember: You can change 2 seconds to a greater or less amount of time for your host name to change and you may add as many messages you want.
~ ENJOY ~