[Tutorial] Making a Level and Experience System( With Paydays)
#1

Introduction

Well, First of all hello to everyone, This is a tutorial on making a level and exp system with paydays, good for RP servers. This is not recommended for beginners.
Second this is my FIRST TUTORIAL so If there's something wrong, Please Do tell me.


Requirements

Here's what you'll need :
sscanf ( Credits goes to ******.)
Zcmd ( Goes to Zeex. )
y_ini ( To ******)
WARNING : MAKE SURE YOU HAVE THE REGISTER/LOGIN SYSTEM AND SAVING/LOADING.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Lets Get Started

On top of the script :
pawn Code:
#include <a_samp> // Credits goes to SA-MP team.
#include <YSI\y_ini>          
#include <sscanf2>        
#include <zcmd>
Now.. You'll need these defines :
pawn Code:
#define LIME  0x88AA62FF
#define PATH "/Users/%s.ini" // the path where EXP and LEVEL data will be stored.
Okay.. Lets add some forwards..
pawn Code:
forward ScoreUpdate();
forward PayDay(playerid);  
forward PlayerPlayMusic(playerid);
forward StopMusic();
Now lets create some enums.. If you do not know what it is, Here's a link to it - Click!

pawn Code:
enum pInfo
{
  Level,
  Exp
};
new PlayerInfo[MAX_PLAYERS][pInfo]; // //We create a variable that stores our enumerator info for each player.
new ScoreOld; // Old Score/Level of player.
new levelexp = 1; // Sets to 1.
Real Coding starts.
Now.. Add this Under " Public OnGameModeInIt " -- I hope so far you have understood all that.
pawn Code:
SetTimer("PayDay",360000,1);// 360000 = 1 hr.. you can change it.
SetTimer("ScoreUpdate", 1000, 1); // Do not change it.
Now.. Add this under " Public OnPlayerConnect(playerid)" Make sure you already have the register/login system since I won't be doing the register/login system..
pawn Code:
PlayerInfo[playerid][Level] = 1; // As soon as player connects,  It will set his/her level to 1.
PlayerInfo[playerid][Exp] = 0; // Exp to 0.
Before proceeding.. Make sure you have the register/login system already done.. We'll be using Y_INI for saving/loading data.

Okay.. lets head on..Go to OnPlayerDisconnect and add this ( If you already have it, just add those both exp, level )
pawn Code:
new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Level",PlayerInfo[playerid][Level]);
    INI_WriteInt(File,"Exp",PlayerInfo[playerid][Exp]);
    INI_Close(File);
Okay.. now the levelup command..
pawn Code:
COMMAND:levelup(playerid,params[])
{
        new string[30]; // String.
        if(IsPlayerConnected(playerid) == 1) // Checks if player is connected.
        {
            new points[248]; // Points.
            new nxtlevel = PlayerInfo[playerid][Level]+1; // As soon as its executed, It adds +1 to your score.
            new expamount = nxtlevel*levelexp; // Exp amount, Its 2 CURRENTLY but you can raise it by adding +number after levelexp
            if(PlayerInfo[playerid][Exp] < expamount) // Checks if player's exp amount is above the required one or not.
            {
                format(points,sizeof(points)," You need [%d] Exp Points in order to level up, You currently have [%d]",expamount,PlayerInfo[playerid][Exp]); // Format, This is pretty obvious.
                SendClientMessage(playerid,LIME,points); // Sends the message.
                return 1;
            }
            else
            {
                PlayerInfo[playerid][Exp] = 0; //  Sets the EXP amount to 0 as you level'd up.
                PlayerInfo[playerid][Level]++; // Adds a level.
                format(string,sizeof(string),"~g~Your now level:[%d]",PlayerInfo[playerid][Level]); // Format.
                GameTextForPlayer(playerid,string,6000,1); // Sends gametext about his new level'ing up.
                return 1;
            }
        }
        return 1;
}
Now to check your level and exp.. here's a /stats command..
pawn Code:
COMMAND:stats(playerid,params[])
{
new string2[200];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string2,sizeof(string2),"Name: %s \nLevel: %d\nExp: %d",name,PlayerInfo[playerid][Level],PlayerInfo[playerid][Exp]);
ShowPlayerDialog(playerid,DIALOG_STATS,DIALOG_STYLE_MSGBOX,"Player Stats",string2,"Close","");
return 1;
}
Okay.. If you already have the LoadUser Data thing.. IGNORE THIS..
pawn Code:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Level",PlayerInfo[playerid][Level]);
    INI_Int("Exp",PlayerInfo[playerid][Exp]);
    return 1;
}
A stock that will fetch the data.
pawn Code:
stock UserPath(playerid)
{
    new string[128],playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(string,sizeof(string),PATH,playername);
    return string;
}
Now.. the Timers!
pawn Code:
public ScoreUpdate()
{
    new Score;
    new name[MAX_PLAYER_NAME];
    //new string[256];
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof(name));
            Score = PlayerInfo[i][Level];
            SetPlayerScore(i, Score);
            if (Score > ScoreOld)
            {
                ScoreOld = Score;
            }
        }
    }
}
public PayDay(playerid)
{
    for (new i; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            new nxtlevel = PlayerInfo[playerid][Level];
            new payday = nxtlevel*0;
            GivePlayerMoney(i,payday);
            PlayerInfo[playerid][Exp]++;
            GameTextForPlayer(i,"  ~p~ PayDay",6,5000);
            PlayerPlayMusic(playerid);
        }
    }
}
public PlayerPlayMusic(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            SetTimer("StopMusic", 5000, 0);
            PlayerPlaySound(i, 1068, 0.0, 0.0, 0.0);
        }
    }
}
public StopMusic()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            PlayerPlaySound(i, 1069, 0.0, 0.0, 0.0);
        }
    }
}


Summing up all.
Well, Now you got a Working Level/exp system with Paydays! You can edit it to your style, Remember.. you need a Working REGISTER/LOGIN SYSTEM ..

Also :
I didn't added a LoadUser thing in OnPlayerConnect, please do that manually.


With Kind Regards,
- Benzke.
Reply
#2

Junk, you just copied some pieces from others tutorial's and made up yours. pretty lame.
Reply
#3

LMFAO.
Copy ?
oh shit
"Devilxz97: Kick his ass out from this Topic."
Reply
#4

Quote:
Originally Posted by leonardo1434
View Post
Junk, you just copied some pieces from others tutorial's and made up yours. pretty lame.
You failed, there's no tutorial based on level and exp system and I never did so, I do have taken some parts from my OWN gm but I didn't copied it.
Reply
#5

Damn, nice tutorial.
Reply
#6

Nice system.
Reply
#7

Quote:
Originally Posted by StupidGuyLikeMe
View Post
Nice system.
Quote:
Originally Posted by JustinAn
View Post
Damn, nice tutorial.
Thank you!
Reply
#8

c'mon, just check the codes. you must be on crack to say that's right.

And Benzke, don't pm me saying you're right, you aren't.
Reply
#9

Its right! I created it myself and I PM'ed you only because you were calling me a " copy paste " scripter..
I dislike the fact your calling my tutorial bad.
Reply
#10

I support leonardo's oppinion here, it seems to me that you have copy pasted due to the "good" explanation of the functions... You've just wrote "a stock to fetch data" Wow, what a great tutorial.. Try harder next time mate!
Reply
#11

I never said I wrote the stock -.-
Just check around SA:MP related to that kind of system and tell me if there's any explaination done..
Also, This is my first tutorial.
Reply
#12

IF you think this is a bad tutorial then why are you reading / commenting in the first place just don't open it, easy as that.
Reply
#13

Quote:
Originally Posted by Lexi'
View Post
IF you think this is a bad tutorial then why are you reading / commenting in the first place just don't open it, easy as that.
As a dedicated user of this forum i'm supposed to make sure that other users are told which tutorial is good or not. In my opinion this tutorial will not only confuse the users ( don't take me wrong, i'm sure the script works. ) but it will halt the progress in becoming a good independent user. And at that point this tutorial has failed.

When you write a tutorial make sure you know 150% how the script works, so you can explain every single little bit of the script.
Reply
#14

Quote:
Originally Posted by Cameltoe
View Post
As a dedicated user of this forum i'm supposed to make sure that other users are told which tutorial is good or not. In my opinion this tutorial will not only confuse the users ( don't take me wrong, i'm sure the script works. ) but it will halt the progress in becoming a good independent user. And at that point this tutorial has failed.

When you write a tutorial make sure you know 150% how the script works, so you can explain every single little bit of the script.
I completely agree with you Quote from Y_Less's how to write a tutorial topic :
Quote:

If you write a tutorial people will assume you know what you're talking about - why write a whole tutorial on something you don't know about? If they're doing something a different way they very rarely check which way is better, they simply assume the tutorial way is because it's in a tutorial!

As you can see he states that you must write a tutorial on something you know about, like you said you must be assured of 150% of how the script works.

But the thing that makes me angry TBH, the people around here (not you, because you just said bad :P) especially high-rollers, their most comments on the tutorials are "crap" "WTF is this shit" "my mother scripts better then you".

Why not be like Y_Less if he doesn't like a tutorial he just states what to fix, and why he hates it.

However.... :P
Reply
#15

Nyc...
Reply
#16

No explanation provided.
Reply
#17

Please tell me how i can make cmd givexp.I wanna this cmd to give "x" exp to all players.
Reply
#18

Quote:
Originally Posted by Hugoca
View Post
Please tell me how i can make cmd givexp.I wanna this cmd to give "x" exp to all players.
pawn Code:
new PlayerEXP[MAX_PLAYERS];

command(giveexp, playerid, params[])
{
     new pID, Amount;
     if(sscanf(params, "ui", pID, Amount)) return SendClientMessage(playerid, 0x0, "Usage: /giveexp [ PlayerID ] [ Amount ]");
     PlayerEXP[pID] = Amount; // To set the amount
     PlayerEXP[pID] = ( PlayerEXP[pID] + Amount ); // To give the amount
     // Remove either of these to change wether to set or give exp.
     return 1;
}
Reply
#19

Quote:
Originally Posted by Cameltoe
View Post
pawn Code:
new PlayerEXP[MAX_PLAYERS];

command(giveexp, playerid, params[])
{
     new pID, Amount;
     if(sscanf(params, "ui", pID, Amount)) return SendClientMessage(playerid, 0x0, "Usage: /giveexp [ PlayerID ] [ Amount ]");
     PlayerEXP[pID] = Amount; // To set the amount
     PlayerEXP[pID] = ( PlayerEXP[pID] + Amount ); // To give the amount
     // Remove either of these to change wether to set or give exp.
     return 1;
}
How i can make it for rcon admins ?

Edit:When i use command i didn't get the exp
Reply
#20

Nice tutorial
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)