PDA

View Full Version : Skills help...


DarK_FeneR
06/06/2014, 08:03 PM
Hello guys, I need to save and load the variables:
Killz[playerid];
Skillz_Pt[playerid];
Skillz_Weap[playerid];
Skillz_Armour[playerid];
How can i do this? Help Me PLS :(


// Weapon skills by DarK_FeneR
#define FILTERSCRIPT

#include <a_samp>
#include <dini>

#define COLOR_RED 0xFF0000FF
#define COLOR_BLUE 0x0004FFFF
#define COLOR_GREEN 0x00FF55FF
#define COLOR_YELLOW 0xEAFF00FF
#define COLOR_ORANGE 0xFFB300FF
#define COLOR_BLACK 0x000000FF
#define COLOR_WHITE 0xFFFFFFFF

#define DIALOG_SKILLS 53

#define SAVE_SKILLS "Skills/%s.ini" //save skills folder

new Killz[MAX_PLAYERS]; //kills count
new Skillz_Pt[MAX_PLAYERS]; //skill points
new Skillz_Weap[MAX_PLAYERS]; //Level weapon skill
new Skillz_Armour[MAX_PLAYERS]; //Level armour skill

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
print("\n--------------------------------------");
print("Weapon Skill FS by DarK_FeneR LOADED");
print("--------------------------------------\n");
return 1;
}

public OnFilterScriptExit()
{
print("\n--------------------------------------");
print("Weapon Skill FS by DarK_FeneR UNLOADED");
print("--------------------------------------\n");
return 1;
}

#endif

public OnPlayerConnect(playerid)
{
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
return 1;
}

public OnPlayerSpawn(playerid)
{
if(Killz[playerid]==10)//every 10 kills, give you 1 skill point
{
Skillz_Pt[playerid] ++; //give +1 skill point
Killz[playerid]=0; //reset kills to 0
}
if(Skillz_Weap[playerid]>=1) //if you have got level 1 of Weapon Skill
{
GivePlayerWeapon(playerid,42,100); //give fire exting with 100 ammo, too
if(Skillz_Weap[playerid]>=2) //if you have got level 2 of Weapon Skill
{
GivePlayerWeapon(playerid,39,15); //give C4 with 15 ammo, too
if(Skillz_Weap[playerid]==3) //if you have got level 3 of Weapon Skill
{
GivePlayerWeapon(playerid,35,15); //give bazooka with 15 ammo
}
}
}
if(Skillz_Armour[playerid]>=1) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,10); //give 10% armour
}
if(Skillz_Armour[playerid]>=2) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,20); //give 20% armour
}
if(Skillz_Armour[playerid]>=3) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,30); //give 30% armour
}
if(Skillz_Armour[playerid]>=4) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,40); //give 40% armour
}
if(Skillz_Armour[playerid]>=5) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,50); //give 50% armour
}
if(Skillz_Armour[playerid]>=6) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,60); //give 60% armour
}
if(Skillz_Armour[playerid]>=7) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,70); //give 70% armour
}
if(Skillz_Armour[playerid]>=8) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,80); //give 80% armour
}
if(Skillz_Armour[playerid]>=9) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,90); //give 90% armour
}
if(Skillz_Armour[playerid]>=10) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,100); //give 100% armour
}
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/skills", true) == 0)
{
ShowPlayerDialog(playerid,DIALOG_SKILLS,DIALOG_STY LE_LIST,"Skill Menu","Armi\nVita","OK","ANNULLA"); //skills dialog
return 1;
}
if(strcmp(cmdtext, "/skillspt", true) == 0)
{
if(IsPlayerAdmin(playerid))//if you are rcon admin
{
Skillz_Pt[playerid] = Skillz_Pt[playerid] + 5; //give you +5 skill points
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai ricevuto 5 Punti SKill"); //skill point received
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Devi essere Rcon Admin per questo comando"); //Message "haven't permission to use this command"
}
return 1;
}
return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(listitem == 0)
{
if(Skillz_Pt[playerid]>=1)//if you have got 1 or more skill points
{
if(Skillz_Weap[playerid]<=2)//if weapon skill are < or = 2
{
Skillz_Pt[playerid] --; //take 1 skill point
Skillz_Weap[playerid] ++; //Weapon skill level increase
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai uppato la Skill Armi di 1 livello"); //success upgrade
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai gia la Skill al Massimo!"); //Maximum Skill
}
}
else
{
SendClientMessage(playerid,COLOR_RED,"[SKILL]Non hai abbastanza Punti Skill per Uppare!");//Haven't got enough Skill point
}
}
if(listitem == 1)
{
if(Skillz_Pt[playerid]>=1)//If they have more or equal to the price.
{
if(Skillz_Armour[playerid]<=9)
{
Skillz_Pt[playerid] --; //take 1 skill point
Skillz_Armour[playerid] ++; //Armour skill level increase
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai uppato la Skill Armatura di 1 livello"); //success upgrade
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai gia la Skill al Massimo!");//Maximum Skill
}
}
else
{
SendClientMessage(playerid,COLOR_RED,"[SKILL]Non hai abbastanza Punti Skill per Uppare!"); //haven't got Enough Skill point
}
}
return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{
Killz[killerid] ++; // The killer value will be increased
return 1;
}

MattTucker
06/06/2014, 09:49 PM
OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME],file[64];
GetPlayerName(playerid, name,sizeof(name));
format(file, sizeof(file), "Users/%s.ini",name);
if(dini_Exists(file))
{
Killz[playerid] = dini_Int(file, "Killz");
Shillz_Weap[playerid] = dini_Int(file, "Skillz_Weap");
Skillz_Armour[playerid] = dini_Int(file, "Skillz_Armour");
Skillz_Pt[playerid] = dini_Int(file, "Skillz_Pt");
}
else
{
dini_Create(file);
}
return 1;
}
OnPlayerDisconnect(playerid,reason)
{
new name[MAX_PLAYER_NAME], file[64];
GetPlayerName(playerid,name,sizeof(name));
format(file, sizeof(file), "Users/%s.ini",name);
if(dini_Exists(file))
{
dini_IntSet(file, "Kills",Killz[playerid]);
dini_IntSet(file, "Skillz_Weap", Skillz_Weap[playerid]);
dini_IntSet(file, "Skillz_Armour", Skillz_Armour[playerid]);
dini_IntSet(file, "Skillz_Pt", Skillz_Pt[playerid]);
}
return 1;
}
Haven't tested but it should work, if you find any errors just tell me. (Make sure the names of the variables are correct as I'm kinda sleepy)
Okay so, I noticed you have dini included, which is a saving system, so I used it.

Fast explanation: first, I got the players name, formated into something called 'file' (which indicates where the user files would be saved at, Scriptfiles folder -> Users -> player's data - their file will be printed as their name)

Second, I checked if the file exists using dini_Exist(file), and checking = if statement mostly, so yeah, if it does exist, we will load, so we set the variables you have to the numbers in the .ini files created, by using dini_Int(file, "name of the line you want to load");

Otherwise, if it doesn't exist, we will just create with nothing assigned.

Then when he disconnects, we save his variables by using dini_IntSet(file /*the place where you want to set the info for - which file*/, "Killz" /* name of the line which we will save the number/value assigned in the variable to */ , Killz[playerid] /* the variable which we will get our number/value from*/);

If you can't understand it, it's okay, not so well explained but you can go on ****** and type "dini samp tutorial" and check some tutorials.

(Advice: dini is kind of slow, try upgrading it)

DarK_FeneR
06/06/2014, 10:46 PM
The FS you posted don't give errors/warnings (afrer i fixed some your little distraction errors)but in game not load/create/save the .ini, so i've tried too 2 day ago, it create and save but it not load variables...

MattTucker
06/06/2014, 10:58 PM
Do you have folder named "Users" inside the "scriptfiles" folder?

DarK_FeneR
07/06/2014, 06:44 AM
Yes i've crate it, try you, if FS load and save give me pls...

DarK_FeneR
07/06/2014, 11:12 AM
I've change some function of Skills but not save and load... (fixed problem not receive skill pt when kill)

// Weapon skills by DarK_FeneR
#define FILTERSCRIPT

#include <a_samp>
#include <Dini>
#include <Dutils>
#include <Dudb>

#define COLOR_RED 0xFF0000FF
#define COLOR_BLUE 0x0004FFFF
#define COLOR_GREEN 0x00FF55FF
#define COLOR_YELLOW 0xEAFF00FF
#define COLOR_ORANGE 0xFFB300FF
#define COLOR_BLACK 0x000000FF
#define COLOR_WHITE 0xFFFFFFFF

#define DIALOG_SKILLS 15

#define savefolder "Skills/%s.ini" //save skills folder

#pragma unused ret_memcpy

new Killz[MAX_PLAYERS]; //kills count
new Skillz_Pt[MAX_PLAYERS]; //skill points
new Skillz_Weap[MAX_PLAYERS]; //Level weapon skill
new Skillz_Armour[MAX_PLAYERS]; //Level armour skill

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
print("\n--------------------------------------");
print("Weapon Skill FS by DarK_FeneR LOADED");
print("--------------------------------------\n");
return 1;
}

public OnFilterScriptExit()
{
print("\n--------------------------------------");
print("Weapon Skill FS by DarK_FeneR UNLOADED");
print("--------------------------------------\n");
return 1;
}

#else

main()
{
print("\n----------------------------------");
print("Weapon Skill FS by DarK_FeneR");
print("----------------------------------\n");
}

#endif

public OnPlayerConnect(playerid)
{
new pname[128];
new file[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), savefolder,pname);
if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file, "Kills", Killz[playerid]);
dini_IntSet(file, "Skill_Pt", Skillz_Pt[playerid]);
dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]);
dini_IntSet(file, "Skill_Armo", Skillz_Armour[playerid]);
}
else
{
Killz[playerid] = dini_Int(file, "Kills");
Skillz_Pt[playerid] = dini_Int(file, "Skill_Pt");
Skillz_Weap[playerid] = dini_Int(file, "Skill_Weap");
Skillz_Armour[playerid] = dini_Int(file, "Skill_Armo");
}
return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
new pname[128];
new file[128];
GetPlayerName(playerid, pname, sizeof(pname));
format(file, sizeof(file), savefolder,pname);
if(!dini_Exists(file))
{
}
else
{
dini_IntSet(file, "Kills", Killz[playerid]);
dini_IntSet(file, "Skill_Pt", Skillz_Pt[playerid]);
dini_IntSet(file, "Skill_Weap", Skillz_Weap[playerid]);
dini_IntSet(file, "Skill_Armo", Skillz_Armour[playerid]);
}
return 1;
}

public OnPlayerSpawn(playerid)
{
if(Killz[playerid]==10)//every 10 kills, give you 1 skill point
{
Skillz_Pt[playerid] ++; //give +1 skill point
Killz[playerid]=0; //reset kills to 0
}
if(Skillz_Weap[playerid]>=1) //if you have got level 1 of Weapon Skill
{
GivePlayerWeapon(playerid,42,100); //give fire exting with 100 ammo, too
if(Skillz_Weap[playerid]>=2) //if you have got level 2 of Weapon Skill
{
GivePlayerWeapon(playerid,39,15); //give C4 with 15 ammo, too
if(Skillz_Weap[playerid]==3) //if you have got level 3 of Weapon Skill
{
GivePlayerWeapon(playerid,35,15); //give bazooka with 15 ammo
}
}
}
if(Skillz_Armour[playerid]>=1) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,10); //give 10% armour
}
if(Skillz_Armour[playerid]>=2) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,20); //give 20% armour
}
if(Skillz_Armour[playerid]>=3) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,30); //give 30% armour
}
if(Skillz_Armour[playerid]>=4) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,40); //give 40% armour
}
if(Skillz_Armour[playerid]>=5) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,50); //give 50% armour
}
if(Skillz_Armour[playerid]>=6) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,60); //give 60% armour
}
if(Skillz_Armour[playerid]>=7) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,70); //give 70% armour
}
if(Skillz_Armour[playerid]>=8) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,80); //give 80% armour
}
if(Skillz_Armour[playerid]>=9) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,90); //give 90% armour
}
if(Skillz_Armour[playerid]>=10) //if you have got level 1 of Armour Skill
{
SetPlayerArmour(playerid,100); //give 100% armour
}
return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/skills", true) == 0)
{
ShowPlayerDialog(playerid,DIALOG_SKILLS,DIALOG_STY LE_LIST,"Skill Menu","Armi\nVita","OK","ANNULLA"); //skills dialog
return 1;
}
if(strcmp(cmdtext, "/skillspt", true) == 0)
{
if(IsPlayerAdmin(playerid))//if you are rcon admin
{
Skillz_Pt[playerid] = Skillz_Pt[playerid] + 5; //give you +5 skill points
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai ricevuto 5 Punti SKill"); //skill point received
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Devi essere Rcon Admin per questo comando"); //Message "haven't permission to use this command"
}
return 1;
}
return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(listitem == 0)
{
if(Skillz_Pt[playerid]>=1)//if you have got 1 or more skill points
{
if(Skillz_Weap[playerid]<=2)//if weapon skill are < or = 2
{
Skillz_Pt[playerid] --; //take 1 skill point
Skillz_Weap[playerid] ++; //Weapon skill level increase
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai uppato la Skill Armi di 1 livello"); //success upgrade
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai gia la Skill al Massimo!"); //Maximum Skill
}
}
else
{
SendClientMessage(playerid,COLOR_RED,"[SKILL]Non hai abbastanza Punti Skill per Uppare!");//Haven't got enough Skill point
}
}
if(listitem == 1)
{
if(Skillz_Pt[playerid]>=1)//If they have more or equal to the price.
{
if(Skillz_Armour[playerid]<=9)
{
Skillz_Pt[playerid] --; //take 1 skill point
Skillz_Armour[playerid] ++; //Armour skill level increase
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai uppato la Skill Armatura di 1 livello"); //success upgrade
}
else
{
SendClientMessage(playerid,COLOR_GREEN,"[SKILL]Hai gia la Skill al Massimo!");//Maximum Skill
}
}
else
{
SendClientMessage(playerid,COLOR_RED,"[SKILL]Non hai abbastanza Punti Skill per Uppare!"); //haven't got Enough Skill point
}
}
return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{
Killz[killerid] ++; // The killer value will be increased
if(Killz[killerid]>=10)//every 10 kills, give you 1 skill point
{
SendClientMessage(killerid,COLOR_RED,"[SKILL]Hai ricevuto 1 Punto Skill!");
Skillz_Pt[killerid] ++; //give +1 skill point
Killz[killerid]=0; //reset kills to 0
} // The killer value will be increased
return 1;
}