[Tutorial] How to make a easy /setvip command (zcmd & sscanf)
#1

How to make a easy /setvip command (zcmd & sscanf)
Well hello everyone, i will teach you how to make /setvip and well this is like almost same as my other tutorial how to make a easy /setadmin command (zcmd & sscanf) but in this tutorial i will try to explain the best i can.

What is this?
Well this is a command that is called /setvip, you can decide what commands you can add for vips in this server and you can also set other people vip by using /setvip [playerid / partofname] [level]. You will need this required things to do this.

Zcmd - By Zeex
Sscanf - By ******

The reason i picked to use Zcmd and Sscanf because they are more easier to use if your coding commands like /ban [playerid / partofname], /sethealth [playerid / partofname] or many more.

How to make this
Well first you will need to log in your rcon in order to make this work (so players cannot set their self vip and do stupid stuff)

Under your includes add
pawn Код:
enum pData
{
    vip
};
new PlayerData[MAX_PLAYERS][pData];
- The reason you will need this is because you won't get error like Undefined PlayerData.

Under that add
pawn Код:
new vlevel,Nam[MAX_PLAYER_NAME],pname[MAX_PLAYER_NAME],str[128],ID;
- The reason you will also need this is,
vlevel: so you can set the other player levels
Nam[MAX_PLAYER_NAME]: So it will define the playerid Nam
pname[MAX_PLAYER_NAME]: This will define the ID name
str[128]: A String that will send to you and the other person
ID: The other person your using /setvip on

Now lets get to the command, i will explain what it means with // so you guys can read

pawn Код:
CMD:setvip(playerid, params[])
    {
        if(!IsPlayerAdmin(playerid)) return 0;//This will make the command work for rcon, if your not rcon it will do SERVER: Unknown Command
        if(sscanf(params,"ui",ID,vlevel)) return SendClientMessage(playerid,0xFF9900AA, "USAGE: /setvip [playerid / partofname] [Level 1-3]");//If you do not use the format /setvip properly it will show how to
        if(ID == INVALID_PLAYER_ID) return SendClientMessage(playerid,0xFF0000FF, "That user is not connected.");//if its an unknown ID, it will show that person is not connected
        if(vlevel > 3) return SendClientMessage(playerid,0xFF0000FF,"AVAILABLE VIP LEVELS 1-3!"); //If you add a number over 3 for /setvip, ex: /setvip Tanush 1000, it will show that message
        if(vlevel == 0)//if you select vip level 0
        {
            if(PlayerData[ID][vip] == 0) return SendClientMessage(playerid,0xFF0000FF,"ERROR: That person is already level 0 vip!");// If the person you attempt to /setvip that is already level 0 vip, it will show that
            GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//Defines the playerid name
            GetPlayerName(ID,pname,MAX_PLAYER_NAME);//Defines the other player name
            format(str, sizeof(str),"%s has set your VIP Level to 0!",Nam);//string
            SendClientMessage(ID,0xFF9900AA,str);//It will send the other person a message that %s has set your vip level to 0
            format(str,sizeof(str),"You had set %s VIP Level to 0!",pname);//string
            SendClientMessage(playerid,0xFF9900AA,str);//This will send you that you had set %s vip level to 0
            PlayerData[ID][vip] = 0;//Sets the other person vip level to 0
        }
        if(vlevel == 1)//if you select vip level 1
        {
            if(PlayerData[ID][vip] == 1) return SendClientMessage(playerid,0xFF0000FF,"ERROR: That person is already level 1 vip!");//If the person you attempt to /setvip that is already level 1 vip, it will show that
            GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//defines the playerid name
            GetPlayerName(ID,pname,MAX_PLAYER_NAME);//defines the other player name
            format(str, sizeof(str),"%s has set your VIP Level to 1 (BRONZE VIP)!",Nam);//string
            SendClientMessage(ID,0xFF9900AA,str);//Sends the other person a message
            format(str, sizeof(str),"You had set %s VIP Level to 1 (BRONZE VIP)!",pname);//string
            SendClientMessage(playerid,0xFF9900AA,str);//Sends you a message
            PlayerData[ID][vip] = 1;//Sets the other person vip level to 1
        }
        if(vlevel == 2)//if you select vip level 2
        {
            if(PlayerData[ID][vip] == 2) return SendClientMessage(playerid,0xFF0000FF,"ERROR: That person is already level 2 vip!");//If the person you attempt to /setvip that is already level 2 vip, it will show that
            GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//defines playerid name
            GetPlayerName(ID,pname,MAX_PLAYER_NAME);//defines other person name
            format(str, sizeof(str),"%s has set your VIP Level to 2 (SILVER VIP)!",Nam);//string
            SendClientMessage(ID,0xFF9900AA,str);// Sends the other person a message
            format(str, sizeof(str),"You had set %s VIP Level to 2 (SILVER VIP)!",pname);//string
            SendClientMessage(playerid,0xFF9900AA,str);//sends you a message
            PlayerData[ID][vip] = 2;//sets the other person vip level to 2
        }
        if(vlevel == 3)// if you select vip level 3
        {
            if(PlayerData[ID][vip] == 3) return SendClientMessage(playerid,0xFF0000FF,"ERROR: That person is already level 3 vip!");//if the person you attempt to /setvip that is already level 3 vip, it will show that
            GetPlayerName(playerid,Nam, MAX_PLAYER_NAME);//defines playerid name
            GetPlayerName(ID,pname,MAX_PLAYER_NAME);//defines the other person name
            format(str, sizeof(str),"%s has set your VIP Level to 3 (GOLD VIP)!",Nam);//string
            SendClientMessage(ID,0xFF9900AA,str);//sends the other person a message
            format(str, sizeof(str),"You had set %s VIP Level to 3 (GOLD VIP)!",pname);//String
            SendClientMessage(playerid,0xFF9900AA,str);//Sends you a message
            PlayerData[ID][vip] = 3;//sets the other person vip level to 3
        }
        return 1;
    }
Now let me show you how to make a basic vip command, you can skip this step if you want to or watch if you want to learn how to make vip commands, first let me teach you how to make /healme, also know that // will explain what it means
pawn Код:
CMD:healme(playerid,params[])//command
{
    if(PlayerData[playerid][vip] < 1) return 0;//well i entered 1 so it will work for vip level 1 and above, if somebody that uses /healme and is under vip level 1 (thats obviously 0), it will send them SERVER: Unknown Command.
    SetPlayerHealth(playerid,100);//just heals the player
    SendClientMessage(playerid,0xFF9900AA,"You have healed your self");//a nice message :)
    return 1;
}
Download
These are the includes i used for this

Zcmd - By Zeex
Sscanf - By ******

And here is pastebin

pastebin

Sorry about the indention , for some reason all my pawn files just indented.
Reply
#2

Good job, like always, Tanush
As a suggestion, you could save this to a file so that the player gets it when he logs in too.
Reply
#3

Nice Work +rep
Reply
#4

Quote:
Originally Posted by CookieJar
Посмотреть сообщение
Good job, like always, Tanush
As a suggestion, you could save this to a file so that the player gets it when he logs in too.
umm maybe i might plan to make a register/login FS later on when im not busy from school works
Reply
#5

nice work
Reply
#6

nice tutorial
Reply
#7

I'd recommend making use of the switch statement in this case, also, be sure to check the ordering of your command. (Example: Why create the variable before checking if they're an administrator?)

Example:

pawn Код:
CMD:setvip(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return 0; //Check if they're an admin BEFORE you create the variables.
       
    new
        p_ID, //Player ID
        p_vLevel, //Player VIP Level
        p_Name[MAX_PLAYER_NAME], //Player Name
        a_Name[MAX_PLAYER_NAME] //Administrator Name
    ;  
       
    if(sscanf(params, "ui", p_ID, p_vLevel))
        return SendClientMessage(playerid, 0xFFFFFFFF, "<USAGE> /setvip <player id> <vip level (0-3)>");
       
    if(p_ID == INVALID_PLAYER_ID)
        return 0; //They entered an invalid ID, so may aswell stop it.
   
    new
        s_message[128];
       
    switch(p_vLevel)
    {
        case 0:
        {
            if(PlayerData[p_ID][VIP] == 0)
                return 0; //They're already a normal user.
           
            GetPlayerName(playerid, a_Name, sizeof(a_Name)); //sizeof gets the size defined by your variable above. (MAX_PLAYER_NAME = 24)
                                                              //Meaning, this is basically saying to format p_Name with the size of 24 cells.
                                                             
            GetPlayerName(p_ID, p_Name, sizeof(p_Name));
           
            format(s_message, sizeof(s_message), "<ATN> %s has set your VIP level to 0.", a_Name);
            SendClientMessage(p_ID, 0xFFFFFFFF, s_message);
           
            format(s_message, sizeof(s_message), "<ATN> You have set %s's VIP level to 0.", p_Name);
            SendClientMessage(playerid, 0xFFFFFFFF, s_message);
        }
        case default: //If they entered anything other than zero, it will call this.
        {
            if(PlayerData[p_ID][VIP] == 1)
                return 0; //They're already a VIP.
           
            GetPlayerName(playerid, a_Name, sizeof(a_Name));
                                                             
            GetPlayerName(p_ID, p_Name, sizeof(p_Name));
           
            format(s_message, sizeof(s_message), "<ATN> %s has set your VIP level to 1.", a_Name);
            SendClientMessage(p_ID, 0xFFFFFFFF, s_message);
           
            format(s_message, sizeof(s_message), "<ATN> You have set %s's VIP level to 1.", p_Name);
            SendClientMessage(playerid, 0xFFFFFFFF, s_message);
        }
    }
    return true;
}
Overall though, it's a decently written tutorial. Good job.
Reply
#8

Nice but, can you make a tutorial for save this in a .ini file ? For the player when reconnect have the same vip level.
Reply
#9

Quote:
Originally Posted by 2KY
Посмотреть сообщение
I'd recommend making use of the switch statement in this case, also, be sure to check the ordering of your command. (Example: Why create the variable before checking if they're an administrator?)

Example:

pawn Код:
CMD:setvip(playerid, params[])
{
    if(!IsPlayerAdmin(playerid))
        return 0; //Check if they're an admin BEFORE you create the variables.
       
    new
        p_ID, //Player ID
        p_vLevel, //Player VIP Level
        p_Name[MAX_PLAYER_NAME], //Player Name
        a_Name[MAX_PLAYER_NAME] //Administrator Name
    ;  
       
    if(sscanf(params, "ui", p_ID, p_vLevel))
        return SendClientMessage(playerid, 0xFFFFFFFF, "<USAGE> /setvip <player id> <vip level (0-3)>");
       
    if(p_ID == INVALID_PLAYER_ID)
        return 0; //They entered an invalid ID, so may aswell stop it.
   
    new
        s_message[128];
       
    switch(p_vLevel)
    {
        case 0:
        {
            if(PlayerData[p_ID][VIP] == 0)
                return 0; //They're already a normal user.
           
            GetPlayerName(playerid, a_Name, sizeof(a_Name)); //sizeof gets the size defined by your variable above. (MAX_PLAYER_NAME = 24)
                                                              //Meaning, this is basically saying to format p_Name with the size of 24 cells.
                                                             
            GetPlayerName(p_ID, p_Name, sizeof(p_Name));
           
            format(s_message, sizeof(s_message), "<ATN> %s has set your VIP level to 0.", a_Name);
            SendClientMessage(p_ID, 0xFFFFFFFF, s_message);
           
            format(s_message, sizeof(s_message), "<ATN> You have set %s's VIP level to 0.", p_Name);
            SendClientMessage(playerid, 0xFFFFFFFF, s_message);
        }
        case default: //If they entered anything other than zero, it will call this.
        {
            if(PlayerData[p_ID][VIP] == 1)
                return 0; //They're already a VIP.
           
            GetPlayerName(playerid, a_Name, sizeof(a_Name));
                                                             
            GetPlayerName(p_ID, p_Name, sizeof(p_Name));
           
            format(s_message, sizeof(s_message), "<ATN> %s has set your VIP level to 1.", a_Name);
            SendClientMessage(p_ID, 0xFFFFFFFF, s_message);
           
            format(s_message, sizeof(s_message), "<ATN> You have set %s's VIP level to 1.", p_Name);
            SendClientMessage(playerid, 0xFFFFFFFF, s_message);
        }
    }
    return true;
}
Overall though, it's a decently written tutorial. Good job.
Dude, why case its just the same thing. If you use
pawn Код:
new
        p_ID, //Player ID
        p_vLevel, //Player VIP Level
        p_Name[MAX_PLAYER_NAME], //Player Name
        a_Name[MAX_PLAYER_NAME] //Administrator Name
every command, you will get the cell warning...
Reply
#10

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
Dude, why case its just the same thing. If you use
pawn Код:
new
        p_ID, //Player ID
        p_vLevel, //Player VIP Level
        p_Name[MAX_PLAYER_NAME], //Player Name
        a_Name[MAX_PLAYER_NAME] //Administrator Name
every command, you will get the cell warning...
You really won't, and a switch statement is more efficient when talking in terms of different statements.

E.G:

pawn Код:
if(blahblah == 1) {
..
}

else if(blahblah == 2) {
..
}
Rather than:

pawn Код:
switch(blahblah)
{
case 1: {
..
}
case 2: {
..
}
}
(No indentation due to me writing this in firefox..)
Reply
#11

What about the command /makevip, instead of /setvip. Because I use an admin's script which has an vip system on it but its useless. I can't edit the Admin Script cause it will crash so I was hoping to create one myself. So how to do with /makevip ?
Reply
#12

Quote:
Originally Posted by RTR12
Посмотреть сообщение
What about the command /makevip, instead of /setvip. Because I use an admin's script which has an vip system on it but its useless. I can't edit the Admin Script cause it will crash so I was hoping to create one myself. So how to do with /makevip ?
You serious?

Simply change
pawn Код:
CMD:setvip(playerid, params[])
    {
to
pawn Код:
CMD:makevip(playerid, params[])
    {
Reply
#13

Ok, thanks. See, I tried that for some already make VIP Script and it always doesn't work. But thanks.
Reply
#14

I followed your wonderful tutorial, but I get two Warning's.
Код:
C:\Program Files\GtaSan\Rockstar Games\GTA San Andreas\Server 0.3d\filterscripts\VIP.pwn(96) : error 017: undefined symbol "makevip"
C:\Program Files\GtaSan\Rockstar Games\GTA San Andreas\Server 0.3d\filterscripts\VIP.pwn(99) : error 017: undefined symbol "sscanf2"
C:\Program Files\GtaSan\Rockstar Games\GTA San Andreas\Server 0.3d\filterscripts\VIP.pwn(96) : warning 203: symbol is never used: "CMD"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
How to fix?
In the tutorial, its sscanf. I downloaded a latest stable version of sscanf, and the name is sscanf2.inc. So it should be sscanf2. I also did #define <zcmd> and #define <sscanf2> under #if defined FILTERSCRIPT.
About the setvip, I made it makevip. I tried both "setvip/makevip", same error. Please help.
Reply
#15

For the CMD Problem, I did this: (Please give the right code if this is wrong.)
Код:
if (strcmp("/makevip", cmdtext, true, 10) == 0)
I used the old way.

I have one problem after that, the sscanf2 thing.
Reply
#16

THis is my /setvip command

Код:
CMD:setvip(playerid, params[])
{
	if (PlayerInfo[playerid][pAdmin] >= 1338 || PlayerInfo[playerid][pShopTech] >= 1)
	{
		new string[128], giveplayerid, level;
		if(sscanf(params, "ud", giveplayerid, level))
		{
			SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /setvip [playerid] [level]");
			SendClientMessageEx(playerid, COLOR_GRAD3, "Available Levels: |0| None |1| Bronze |2| Silver |3| Gold |4| Platinum |5| Moderator");
			return 1;
		}

		if(IsPlayerConnected(giveplayerid))
		{
			if(giveplayerid != INVALID_PLAYER_ID)
			{
				if(level < 0 || level > 5)
				{
					SendClientMessageEx(playerid, COLOR_GRAD1, "VIP Level can not be below 0 or above 5!");
					return 1;
				}
				PlayerInfo[giveplayerid][pDonateRank] = level;
				PlayerInfo[giveplayerid][pTempVIP] = 0;
				PlayerInfo[giveplayerid][pBuddyInvited] = 0;
				new year, month,day;
				getdate(year, month, day);
				new playerip[32];
				GetPlayerIp(giveplayerid, playerip, sizeof(playerip));
				if(level == 0)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to None (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to None (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to None by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);
					PlayerInfo[giveplayerid][pTokens] = 0;

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to None (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
				if(level == 1)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Bronze (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Bronze (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to Bronze by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to Bronze (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
				if(level == 2)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Silver (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Silver (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to Silver by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to Silver (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
				if(level == 3)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Gold (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Gold (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to Gold by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to Gold (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
				if(level == 4)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Platinum (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Platinum (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to Platinum by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);

					// Level 5 Arms Job - Platinum VIP
					PlayerInfo[giveplayerid][pArmsSkill] = 401;

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to Platinum (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
				if(level == 5)
				{
					if (PlayerInfo[playerid][pAdmin] < 1337)
					{
						format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Moderator (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
						SendClientMessageEx(playerid, COLOR_LIGHTRED, string);
					}
					format(string, sizeof(string), "AdmCmd: %s has set %s's VIP level to Moderator (%d).", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), level);
					ABroadCast(COLOR_LIGHTRED,string, 1337);
					format(string, sizeof(string), "Your VIP level has been set to Moderator by Admin %s.", GetPlayerNameEx(playerid));
					SendClientMessageEx(giveplayerid, COLOR_WHITE, string);

					format(string, sizeof(string), "AdmCmd: %s has set %s's (IP:%s) VIP level to Moderator (%d). (%d-%d-%d)", GetPlayerNameEx(playerid), GetPlayerNameEx(giveplayerid), playerip, level, month,day,year);
					Log("logs/setvip.log", string);
					return 1;
				}
			}
		}
	}
	else
	{
		SendClientMessageEx(playerid, COLOR_GRAD1, "You are not authorized to use that command!");
	}
	return 1;
}
Reply
#17

Quote:
Originally Posted by RTR12
Посмотреть сообщение
For the CMD Problem, I did this: (Please give the right code if this is wrong.)
Код:
if (strcmp("/makevip", cmdtext, true, 10) == 0)
I used the old way.

I have one problem after that, the sscanf2 thing.
Can youpost the lines with Errors?
Reply
#18

All if you stop double posting, i am sure that is not allowed. Also you need to download the include ZCMD and the include + plugin sscanf2
Reply
#19

GooD tutorial! Help Me A Bit! Thanx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)