[Tutorial] How To Change Your Hostname Frequently
#1

[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.

Rating Level: Beginner

Now, lets really start...

FIRST OFF...
We will make the hostname change every 2 seconds. We must forward the timer which will make it go off every 2 seconds. Note: You may change 2 seconds to whatever you desire, I would recommend 1 second or half a second (500 milliseconds).

Lets name the function as: ChangeHostName

Add to the top of the script...
pawn Код:
forward ChangeHostName();
Since we are forwarding it for everyone, we don't need playerid inside of the brackets above.

SECOND OFF...
Lets add the timer for our ChangeHostName.

Add this under OnGameModeInit...
pawn Код:
SetTimer("ChangeHostName",1000,1);
Lets go through that timer, step by step...

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...
Lets add our public callback. This may go anywhere in your script as long as it not in any other call back, I strongly recommend it goes at the very bottom of your gamemode script. For now, lets have 3 different messages to show for everybody. You can change 3 to a less amount or greater amount if you desire.

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
   }
}
Where it says Message 1, 2, 3, you may add your 3 messages you want to be seen/displayed to everyone who see's your server. Again, let's go through this function:

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...
Well, if you have done it correctly, this should work 100% guarantee.

OTHER INFORMATION:
For more information about switches and cases, refer to this link: https://sampwiki.blast.hk/wiki/Control_Structures

If 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 ~
Reply
#2

Nice tutorial this is very usefull.
Reply
#3

Great, simple, but great!
Reply
#4

Nice easy TuT!


Though I would "//" out a bit.

Код:
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
   }
}
Reply
#5

Thanks guys.
Reply
#6

It's a nice tutorial, I made a stock long time ago...
let me search it up...
pawn Код:
stock HostnameText(hostname[])
{
    new s[128];
    format(s, sizeof(s), "hostname %s", hostname);
    SendRconCommand(s);
}
This is very useful, indeed, I use it for announcements sometimes.
Reply
#7

Nice Tutorial for beginners
Reply
#8

niCe script!
Reply
#9

Nice tutorial!
Reply
#10

i say The Best! WoWWWWWWWWWWW
Man GreAt!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)