[Tutorial] Making a very simple VIP system with /setvip command using dini+sscanf+ZCMD
#1

Hey guys I am writing this tutorial of making a VIP system with saving.


First of all I use dini and sscanf because they are veey easy to use.

So we will need dini,ZCMD and sscanf.

You can find them on ****** .

So lets start..

pawn Code:
#include <a_samp>
#include <sscanf>
#include <ZCMD>
#include <dini>


Here is the starting of our script. As you all must be knowing that these are the most important parts of script because these files within the brackets have very inportant functions we will be using.

Now lets begin coding!!


pawn Code:
enum vip
{
   vipdata
};
new name[50],maxlvl,evipdata[MAX_PLAYERS][vip];
new file[40];
format(file,sizeof(file),"/vipsys/settings.ini");


Add this to the to of the script just below the #includes.In this we use enum to have variable-vipdata in one head variable-vip.Then we declare a new variable "name" and evipdata[MAX_PLAYERS][vip] we have used this so that it can be used on all players and [vip] is the main variable as given above.

We then we create a new variable file and format it to the settings file which should be located in /scriptfiles/vipsys/settings.ini


Now,


pawn Code:
public OnGameModeInit()
{
  if(!fexists(file))
    {
      dini_Create(file);
      dini_IntSet(file,"maxlevel",3); // you can change "3" your wish the max vip level to be.
    }
else
   {
       maxlvl=dini_Int(file,"maxlevel");
   }
return 1;
}


In here we first call the OnGamemodeInit function and

then using fexists we check that if the file(defined above) exists.

If it does not, as in first case, we use dini_Create to create that file and then feed the max lvl a vip can be.

If the file already exists then we put the value of maxlevel in the maxlvl variable using dini_Int.Then we return 1; for successful completion of this task.


Now for next part.

pawn Code:
public OnPlayerConnect(playerid)
{
  new ufile[50];
  GetPlayerName(playerid,name,sizeof(name));
  format(ufile,sizeof(ufile),"/vipsys/users/%s.ini",name);
  if(!fexists(ufile))
    {
       dini_Create(ufile);
       dini_IntSet(ufile,"viplevel",0);
    }
  else
    {
evipdata[playerid][vipdata]=dini_Int(ufile,"viplevel");
     }
return 1;
}


So here we have used OnPlayerConnect function.In this we created a new variable "ufile" and formatted it to the player\'s vip file in /scriptfiles/vipsys/users.

Then again using fexists we check if the file exists. If not like this case, we created the file of the player and then feeded the vip level to 0 using dini_Create and dini_IntSet.

If the file exists then we assign the value of vip level to our new variable using dini_Int.


Now the main controlling is done now we will make /setvip command.


pawn Code:
CMD:setvip(playerid,params[])
{
   new targetid,lvl;
   if(!IsPlayerAdmin(playerid)) return 0;
   if(sscanf(params,"ui",targetid,lvl); return SendClientMessage(playerid,-1,"USAGE: /setvip [id] [level]");
   if(lvl > maxlvl) return SendClientMessage(playerid, -1, "Max VIP level is 3");
else
 {
    new name2[50],ufile2[50];
    GetPlayerName(targetid,name2,sizeof(name2));.
    format(ufile2,sizeof(ufile2),"/vipsys/users/%s.ini",name2);
    dini_IntSet(ufile2,"viplevel",lvl);
}


Now we are at the last part of our script.

Here we make 2 more variables.Then we check if the player is rcon admin.

If he is not the script would not show anything.Then we see if he has typed the parameters needed for the comand to work. If he has it will check if the parameter is greater than the max permitted. If it is also true a new variable will be made that is name2 and then it will find the players file and edit it.



Now you guys can try tweaking it. and for this one to work you will need two folders. One inside scriptfiles/vipsys and other in scriptfiles/users..

Have fun and if you find a problem just ask me..


So guys thats it i will update it for more new things.
Reply
#2

It\'s good, but why not use something faster like Y_ini or DJson?
Reply
#3

because dini and sscanf are veryyy easy to use
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)