05.11.2012, 20:15
SKILLS SYSTEM
Hi all. I've been a little bored so I decided to create a tutorial on how to make a "Skills System" using the system "Yini" by ****** to save the information of the weapons skills of the players.
Requeriments:-YINI Include by ******: You can find it here:
https://sampforum.blast.hk/showthread.php?tid=321092
-ZCMD Include, You can find it here:
http://www.solidfiles.com/d/d20f/
Ok, Let's start.
Includes:
The first thing, We have to do is, add the includes we are going to need in our script.
pawn Code:
//=======Includes=========\\
#include <a_samp>//Obviously we need that include which contains all the functions we are going to work in.
#include <YSI\y_ini>//YINI to save the player data.
#include <zcmd>//The zcmd include is a command proccesor.
//=======Includes=========//
pawn Code:
//=======Colors=========\\
#define COLOR_RED 0xFF0000C8
#define COLOR_GREEN 0x00FF00C8
#define COLOR_YELLOW 0xFFFF00C8
//=======Colors=========\\
pawn Code:
#define SkillPath "/Skills/%s.ini"//We have defined the Skills PATH now.
Now, We are going to create an enum, What's an enum? An "enum" is a tool that allows us to list items.
At our case we are going to list the weapons to set the skills data.
Let's do the code:
pawn Code:
enum plInfo //It means that the enum name will be "plInfo.
{
Pistol, //They are the weapons names to set the skills.
SPistol,
Desert,
Shotgun,
Sawnoff,
Spas12,
Uzi,
MP5,
AK47,
M4,
Rifle
}
new PlayerInfo[MAX_PLAYERS][plInfo];//What does it mean? It means that we are creating an array to store the weapons skills and it will be for all the players. Our array its name is "PlayerInfo".
A forward is defining a function we are going to do later, if we don't forward a function we'll receive errors while compiling.
So let's make the forwards:
pawn Code:
forward LoadSkills(playerid, name[], value[]);//This will be to load the player skills.
forward SkillsShow(playerid,targedid);//This will be to Show the player skills in each weapon.
First we are going to create the public function to Load the player skills.
pawn Code:
public LoadSkills(playerid, name[], value[])//We are creating the public function.
{
new INI:file = INI_Open(SkillPath(playerid));//This line will create file to save the player skills, this line will open the PATH we defined before.
INI_Int("Pistol", PlayerInfo[playerid][Pistol]);//It means that inside the file will be created all this information about all the weapons.
INI_Int("SPistol", PlayerInfo[playerid][SPistol]);
INI_Int("Desert", PlayerInfo[playerid][Desert]);
INI_Int("Shotgun", PlayerInfo[playerid][Shotgun]);
INI_Int("Sawnoff", PlayerInfo[playerid][Sawnoff]);
INI_Int("Spas12", PlayerInfo[playerid][Spas12]);
INI_Int("Uzi", PlayerInfo[playerid][Uzi]);
INI_Int("MP5", PlayerInfo[playerid][MP5]);
INI_Int("AK47", PlayerInfo[playerid][AK47]);
INI_Int("M4", PlayerInfo[playerid][M4]);
INI_Int("Rifle", PlayerInfo[playerid][Rifle]);
INI_Close(file);//Closing the file.
return 1;
}
pawn Code:
public SkillShow(playerid,targedid)//creating the function
{
new p1 = PlayerInfo[playerid][Pistol];//It means that we are creating an array to store the PlayerSkills
new p2 = PlayerInfo[playerid][SPistol];// = =
new p3 = PlayerInfo[playerid][Desert];
new p4 = PlayerInfo[playerid][Shotgun];
new p5 = PlayerInfo[playerid][Sawnoff];
new p6 = PlayerInfo[playerid][Spas12];
new p7 = PlayerInfo[playerid][Uzi];
new p8 = PlayerInfo[playerid][MP5];
new p9 = PlayerInfo[playerid][AK47];
new p10 = PlayerInfo[playerid][M4];
new p11 = PlayerInfo[playerid][Rifle];
new pName[MAX_PLAYER_NAME];//An array to get the player name.
GetPlayerName(targedid, pName, sizeof(pName));
//Here we are creating messages to show the player skills.
new message[128];
new message2[128];
new message3[128];
new message4[128];
new message5[128];
format (message, sizeof(message), "Player %s Stats",pName );//Here we are giving the format to be shown the Skills
format (message2, sizeof(message2), "Pistol:%i , Silenced Pistol:%i , Desert:%i",p1 , p2 , p3 );
format (message3, sizeof(message3), "Shotgun:%i , SawnOff ShotGun:%i , Spas12 Shotgun:%i",p4 , p5 , p6);
format (message4, sizeof(message4), "Uzi:%i , MP5:%i , AK47:%i",p7 , p8 , p9);
format (message5, sizeof(message5), "M4:%i , Sniper Rifle:%i",p10 , p11);
SendClientMessage(playerid, COLOR_RED, "Player Stats:");
SendClientMessage(playerid, COLOR_YELLOW, message);//Creating the function to send the player message.
SendClientMessage(playerid, COLOR_YELLOW, message2);
SendClientMessage(playerid, COLOR_YELLOW, message3);
SendClientMessage(playerid, COLOR_YELLOW, message4);
SendClientMessage(playerid, COLOR_YELLOW, message5);
return 1;
}
Now let's create a stock to give a name to the file according to the player name:
pawn Code:
stock SkillPath(playerid)
{
new str[128],name[24];
GetPlayerName(playerid,name,24);
format(str,sizeof(str),Skillpath,name);
return str;
}
pawn Code:
public OnPlayerConnect(playerid)
{
INI_ParseFile(SkillPath(playerid),"LoadSkills",.bExtra = true, .extra = playerid);//Calling the function LoadSkills to get the players Skills.
return 1;
}
pawn Code:
public OnPlayerDisconnect(playerid,reason)
{
new sFile[35];
format(sFile, 35, Skillpath, SkillPath(playerid));//Giving a format to the file.
new INI:skillFile = INI_Open(sFile);//We are opening the skill file where the data is stored.
INI_WriteInt(skillFile, "Pistol", PlayerInfo[playerid][Pistol]);
INI_WriteInt(skillFile, "SPistol", PlayerInfo[playerid][SPistol]);
INI_WriteInt(skillFile, "Desert", PlayerInfo[playerid][Desert]);
INI_WriteInt(skillFile, "Shotgun", PlayerInfo[playerid][Shotgun]);
INI_WriteInt(skillFile, "Sawnoff", PlayerInfo[playerid][Sawnoff]);
INI_WriteInt(skillFile, "Spas12", PlayerInfo[playerid][Spas12]);
INI_WriteInt(skillFile, "Uzi", PlayerInfo[playerid][Uzi]);
INI_WriteInt(skillFile, "MP5", PlayerInfo[playerid][MP5]);
INI_WriteInt(skillFile, "AK47", PlayerInfo[playerid][AK47]);
INI_WriteInt(skillFile, "M4", PlayerInfo[playerid][M4]);
INI_WriteInt(skillFile, "Rifle", PlayerInfo[playerid][Rifle]);
INI_Close(skillFile);//Closing the file.
return 1;
}
Just what we do now is create a function so that when the player dies increase the "SKILLS" depending on which weapon did.
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
if(GetPlayerWeapon(killerid) == 22) PlayerInfo[killerid][Pistol]++; /
if(GetPlayerWeapon(killerid) == 23) PlayerInfo[killerid][SPistol]++;
if(GetPlayerWeapon(killerid) == 24) PlayerInfo[killerid][Desert]++;
if(GetPlayerWeapon(killerid) == 25) PlayerInfo[killerid][Shotgun]++;
if(GetPlayerWeapon(killerid) == 26) PlayerInfo[killerid][Sawnoff]++;
if(GetPlayerWeapon(killerid) == 27) PlayerInfo[killerid][Spas12]++;
if(GetPlayerWeapon(killerid) == 28) PlayerInfo[killerid][Uzi]++;
if(GetPlayerWeapon(killerid) == 29) PlayerInfo[killerid][MP5]++;
if(GetPlayerWeapon(killerid) == 30) PlayerInfo[killerid][AK47]++;
if(GetPlayerWeapon(killerid) == 31) PlayerInfo[killerid][M4]++;
if(GetPlayerWeapon(killerid) == 34) PlayerInfo[killerid][Rifle]++;
//Al we did there is get the player weapon of the killerid and increase the skills with ++.
return 1;
}
Just what we do now is create a "ARRAY" getting information out of the "skills" so that when the player "SPAWN" get the "SKILLS" that obtained when disconnected.
pawn Code:
public OnPlayerSpawn(playerid)
{
new p1 = PlayerInfo[playerid][Pistol];
new p2 = PlayerInfo[playerid][SPistol];
new p3 = PlayerInfo[playerid][Desert];
new p4 = PlayerInfo[playerid][Shotgun];
new p5 = PlayerInfo[playerid][Sawnoff];
new p6 = PlayerInfo[playerid][Spas12];
new p7 = PlayerInfo[playerid][Uzi];
new p8 = PlayerInfo[playerid][MP5];
new p9 = PlayerInfo[playerid][AK47];
new p10 = PlayerInfo[playerid][M4];
new p11 = PlayerInfo[playerid][Rifle];
SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL, p1);
SetPlayerSkillLevel(playerid, WEAPONSKILL_PISTOL_SILENCED, p2);
SetPlayerSkillLevel(playerid, WEAPONSKILL_DESERT_EAGLE, p3);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SHOTGUN, p4);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SAWNOFF_SHOTGUN, p5);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SPAS12_SHOTGUN, p6);
SetPlayerSkillLevel(playerid, WEAPONSKILL_MICRO_UZI, p7);
SetPlayerSkillLevel(playerid, WEAPONSKILL_MP5, p8);
SetPlayerSkillLevel(playerid, WEAPONSKILL_AK47, p9);
SetPlayerSkillLevel(playerid, WEAPONSKILL_M4, p10);
SetPlayerSkillLevel(playerid, WEAPONSKILL_SNIPERRIFLE, p11);
return 1;
}
Just what we do there is to call the function "SkillsShow" we had done before to show the "SKILLS".
pawn Code:
CMD:skills(playerid, params[])
{
if(IsPlayerConnected(playerid))
{
SkillShow(playerid,playerid);
}
return 1;
}