[Tutorial] How make a simple Level & XP System ! - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (
https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How make a simple Level & XP System ! (
/showthread.php?tid=543071)
How make a simple Level & XP System ! -
HY - 24.10.2014
Introduction:
- Hello !
- I will show you, how to make a simple Level & XP System !
- Isn't a hard tutorial, I think it's simple !
We need... :
- After start this tutorial, you need one include !
- This include it's ZCMD, if you don't have him, don't download him, if you don't have him, you can download "ZCMD" include from below link :
• ZCMD
Let's start:
- First, we need to add includes at the top of script. Under <a_samp> we will add:
- This #include, will help us to make a command, wich help all people enter in another level !
- We need to add some enums ! This enums, will help us to define "Level & Exp" . If you don't add this enums, you will get some errors with "Underfined Symbol : ...etc. This enums is needed to put under includes :
pawn Code:
enum pInfo // This is our enum
{ // open brackelet
Level, // This will define "Level" variable .
Exp, // This will define "Experience" variable. I took "Exp" because it's more easy .
} // close brackelet to show we finished !
- Under enums, we will need to define some "new" . Else not, you will get errors.
pawn Code:
new levelexp = 1; // This is our level & exp. Will set exp after Level Up to 1.
new PlayerInfo[MAX_PLAYERS][pInfo]; // We will define our PlayerInfo, else not you will get some errors. "Underfined Symbol : PlayerInfo !"
- We made Level & XP System. But we don't finished. We need to make a command, wich when a player type : "/LevelUp" [for example] will go to another level. We need ZCMD to make this command [download from first description] or you can convert to Y_ini, or Dini, etc. So we scroll down, scroll down, and we will make our "/LevelUp" command !
pawn Code:
CMD:levelup(playerid,params[]) // This is our Command ! Change this command to your wanted command !
{ // open brackelet
new string[30]; // This is a new "String" variable !
if(IsPlayerConnected(playerid) == 1) // Checks if player is connected.
{ // Open brackelet
new points[248]; // This are a new variable with Experience Points !
new nxtlevel = PlayerInfo[playerid][Level]+1; // Will add +1 Score and Level to his/her stats !
new expamount = nxtlevel*levelexp; // This is our "levelexp" new defined !
if(PlayerInfo[playerid][Exp] < expamount) // Checks if player's exp amount is above the required one or not.
{
format(points,sizeof(points)," {FF0000}You need {0066CC}%d {FF0000}exp. points. You currently have {15FF00} %d",expamount,PlayerInfo[playerid][Exp]); // Format, to send to that player message
SendClientMessage(playerid,-1,points); // Sends that message
return 1; // Return a value !
} // close brackelet !
else // If he have experience neccesarry !
{ // Open brackelet !
PlayerInfo[playerid][Exp] = 0; // Setting his Experience to 0 after level up !
PlayerInfo[playerid][Level]++; // Will set to a player next player's level !
format(string,sizeof(string),"~g~Your now level: ~r~%d",PlayerInfo[playerid][Level]); // This is format, to send message to player "Your now level : *Player LEVEL*
GameTextForPlayer(playerid,string,6000,1); // Sends Format message "Your now level: *Player Level*
return 1; // We add "return 1;", else you will get errors !
} // Close brackelet ! *1
} // Close brackelet ! *2
return 1; // We add "return 1;", to show we finished command, else you will get errors !
} // Close last brackelet !
- Now, when he type : "/LevelUp" In-Game, if he have experience points necessary, he will get +1 Level to his Stats . Else not, he will receive a message, wich he cannot go to level up because he isn't having necessary experience .
Only If You Want !
- This is only if you want to add a command like: "/Level" wich will shows players level ! If you don't want, you can compile, and enter In-Game to test it, but, if you want, add this command under last "/LevelUp" command !
pawn Code:
CMD:level(playerid,params[]) // Our /Level Command
{ // Open brackelet !
new string2[200]; // Our string, we have 1, so we rename it to "String2"
new name[MAX_PLAYER_NAME]; // This is players name !
GetPlayerName(playerid, name, sizeof(name)); // Will Get player's name to put him in Dialog. This will be better in a stock, but works and like this !
format(string2,sizeof(string2),"{FF0000}Name: {15FF00}%s \n{FF0000}Level: {15FF00}%d\n{FF0000}Exp: {15FF00}%d\n\n{FF0000}This is your {15FF00}Level Stats!",name,PlayerInfo[playerid][Level],PlayerInfo[playerid][Exp]); // This it's format dialog message, wich he will saw his Name,Level,Experience !
ShowPlayerDialog(playerid,0,DIALOG_STYLE_MSGBOX,"{15FF00}Level",string2,"Close",""); // This is dialog, wich will show to player with the last format message !
return 1; // Returns a value, to show we finished command !
} // Close brackelet !
- Now, we finished all command !
Last Words !
* You can see all command made by us at Pastebin ! !
* Else, you can made a Free Level command like :
pawn Code:
CMD:freelevel(playerid,params[])
{
PlayerInfo[playerid][Level]++;
SendClientMessage(playerid,-1,"{FF0000}You are now at a new Level");
return 1;
}
* Else, you can made a Free Experience command like :
pawn Code:
CMD:freeexp(playerid,params[])
{
PlayerInfo[playerid][Experiencel]++;
SendClientMessage(playerid,-1,"{FF0000}You got +1 Experience");
return 1;
}
* This was all tutorial
* I hope you understanded !
* If you don't like tutorial, I'm sorry !
* Cheers !