[Tutorial] [Revised] Defining your script version and showing it
#1

Hey guys, I made this same tutorial a few weeks ago. However it was my first tutorial and my methods weren't very good. I'm making this one to make sure that whatever I taught you there is erased from your memory. This is the proper way to do things.

GETTING STARTED

You need a brain
You need Pawno


Defining your script Version

First we need to define our script version. Start by typing this under your other defines.

PHP код:
#define gVersion "v1.0" // Don't forget to update this after X amount of updates. 
Explanation
gVersion is where our version string is stored. The quotes before and after our string is absolutely necessary. These quotes tell us that we are in fact calling this as a string and not an integer.

The "g" before our "Version" means that this is a Global Define. This allows us to use it absolutely anywhere in our script. We do not actually need the "g" but it is recommended. In reality you can name this define whatever you want to name it. That doesn't matter, it's how we use it that counts.

Moving on.

Displaying Our Version to the public

Depending on where you want people to see this, you'll need to know where to put it.
We'll be placing this under OnPlayerConnect so that players will see this only when they connect. You can put this under a command if you wish, eg, /version etc.. .

PHP код:
public OnPlayerConnect(playerid)
{
      new 
string[35];
      
format(stringsizeof(string), "Current Version: %s"gVersion);
      
SendClientMessage(playerid0xFFFF00FFstring);
      return 
1;

Explanation
Firstly, we made our string variable which includes a size. This size indicates the length of the string that we are going to send. The %s located right after "Current Version" tells the server that we are including a define or a variable with our message. After that we have our gVersion which is what we defined earlier. This tells our %s that we are going to display the stored string that is stored within our define.

That's it. Please do not copy paste this. Type it out, it's not hard and it isn't long. Copy AND Paste does not teach you anything.

That's it. +rep if i helped, thanks.

EDIT: Also you can define our version to anything, it can even just be a store string. It doesn't have to be defined as our script version. Can define as anything really.
Reply
#2

Macros (defines) don't store anything, they're like a "mask".

Best way to do that (I think):
pawn Код:
#define SERVER_VERSION            "v0.1"

public OnPlayerConnect(playerid) {
    SendClientMessage(playerid, -1, "Current version: "SERVER_VERSION"");
    return 1;
}
Thanks for sharing anyway.

Best regards.
Reply
#3

Quote:
Originally Posted by [DOG]irinel1996
Посмотреть сообщение
Macros (defines) don't store anything, they're like a "mask".

Best way to do that (I think):
pawn Код:
#define SERVER_VERSION            "v0.1"

public OnPlayerConnect(playerid) {
    SendClientMessage(playerid, -1, "Current version: "SERVER_VERSION"");
    return 1;
}
Thanks for sharing anyway.

Best regards.
This +1
Reply
#4

Both ways work. But thanks for the commentary.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)