SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 24/07/2012, 07:22 PM   #1
electrux
Big Clucker
 
electrux's Avatar
 
Join Date: May 2012
Posts: 105
Reputation: 6
Default Making a very simple VIP system with /setvip command using dini+sscanf+ZCMD

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

Last edited by electrux; 25/07/2012 at 10:03 AM.
electrux is offline   Reply With Quote
Old 25/07/2012, 07:31 AM   #2
alpha500delta
High-roller
 
alpha500delta's Avatar
 
Join Date: Feb 2010
Posts: 1,301
Reputation: 91
Default Re: Making a very simple VIP system with /setvip command using dini+sscanf+ZCMD

It's good, but why not use something faster like Y_ini or DJson?
__________________
Skype: Alpha500delta | Steam: Alpha500delta
alpha500delta is offline   Reply With Quote
Old 25/07/2012, 09:00 AM   #3
electrux
Big Clucker
 
electrux's Avatar
 
Join Date: May 2012
Posts: 105
Reputation: 6
Default Re: Making a very simple VIP system with /setvip command using dini+sscanf+ZCMD

because dini and sscanf are veryyy easy to use

Last edited by electrux; 25/07/2012 at 09:59 AM.
electrux is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Making a simple PM system with ZCMD & sscanf Toni Tutorials 27 18/05/2013 05:10 PM
[Tutorial] Making /vw (virtualworld) command using ZCMD and sscanf electrux Tutorials 19 24/07/2012 10:51 AM
[Tutorial] How to make a easy /setvip command (zcmd & sscanf) Tanush123 Tutorials 18 23/07/2012 12:59 PM


All times are GMT. The time now is 03:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.