SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 13/09/2012, 10:46 AM   #1
Benzke
Banned
 
Join Date: Mar 2012
Posts: 134
Reputation: 10
Default Making a Level and Experience System( With Paydays)

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 Y_Less.)
Zcmd ( Goes to Zeex. )
y_ini ( To Y_Less)
WARNING : MAKE SURE YOU HAVE THE REGISTER/LOGIN SYSTEM AND SAVING/LOADING.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Lets Get Started

On top of the script :
Code:
#include <a_samp> // Credits goes to SA-MP team.
#include <YSI\y_ini>          
#include <sscanf2>        
#include <zcmd>

Now.. You'll need these defines :
Code:
#define LIME  0x88AA62FF
#define PATH "/Users/%s.ini" // the path where EXP and LEVEL data will be stored.

Okay.. Lets add some forwards..
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!

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.
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..
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 )
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..
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..
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..
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.
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!
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.
Benzke is offline   Reply With Quote
Old 13/09/2012, 11:00 AM   #2
leonardo1434
High-roller
 
leonardo1434's Avatar
 
Join Date: Mar 2012
Posts: 1,678
Reputation: 179
Default Re: Making a Level and Experience System( With Paydays)

Junk, you just copied some pieces from others tutorial's and made up yours. pretty lame.
__________________
c++
leonardo1434 is offline   Reply With Quote
Old 13/09/2012, 11:35 AM   #3
Devilxz97
Gangsta
 
Devilxz97's Avatar
 
Join Date: Dec 2011
Location: Malaysia
Posts: 759
Reputation: 37
Default Re: Making a Level and Experience System( With Paydays)

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


- Skype Name: ejam.blacklistcrew -
- Facebook Acc: http://www.facebook.com/DevConnection -

Selling Gamemode [DRIFT/FREEROAM/ROLEPLAY] for $9.99
Devilxz97 is offline   Reply With Quote
Old 13/09/2012, 12:57 PM   #4
Benzke
Banned
 
Join Date: Mar 2012
Posts: 134
Reputation: 10
Default Re: Making a Level and Experience System( With Paydays)

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.
Benzke is offline   Reply With Quote
Old 14/09/2012, 01:49 AM   #5
JustinAn
Huge Clucker
 
JustinAn's Avatar
 
Join Date: Apr 2012
Location: stfu
Posts: 250
Reputation: 28
Default Re: Making a Level and Experience System( With Paydays)

Damn, nice tutorial.
__________________
JustinAn is offline   Reply With Quote
Old 14/09/2012, 02:03 AM   #6
StupidGuyLikeMe
Little Clucker
 
StupidGuyLikeMe's Avatar
 
Join Date: Aug 2012
Location: Kuala Lumpur, Malaysia
Posts: 35
Reputation: 1
Default Re: Making a Level and Experience System( With Paydays)

Nice system.
__________________
This is Kelvin a.k.a StupidGuyLikeMe.
I just helped my friend, Romel to host his server.

==Server stats==

Hope you will join the server now!
We are currently hiring administrators in our server.
If you like our server please donate to us for keeping the server alive! (Paypal or OneBip are accepted!)
StupidGuyLikeMe is offline   Reply With Quote
Old 14/09/2012, 06:21 AM   #7
Benzke
Banned
 
Join Date: Mar 2012
Posts: 134
Reputation: 10
Default Re: Making a Level and Experience System( With Paydays)

Quote:
Originally Posted by StupidGuyLikeMe View Post
Nice system.
Quote:
Originally Posted by JustinAn View Post
Damn, nice tutorial.
Thank you!
Benzke is offline   Reply With Quote
Old 14/09/2012, 06:37 AM   #8
leonardo1434
High-roller
 
leonardo1434's Avatar
 
Join Date: Mar 2012
Posts: 1,678
Reputation: 179
Default Re: Making a Level and Experience System( With Paydays)

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.
__________________
c++
leonardo1434 is offline   Reply With Quote
Old 14/09/2012, 06:49 AM   #9
Benzke
Banned
 
Join Date: Mar 2012
Posts: 134
Reputation: 10
Default Re: Making a Level and Experience System( With Paydays)

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.
Benzke is offline   Reply With Quote
Old 14/09/2012, 06:55 AM   #10
Cameltoe
High-roller
 
Cameltoe's Avatar
 
Join Date: Apr 2010
Location: Norway
Posts: 1,780
Reputation: 24
Default Re: Making a Level and Experience System( With Paydays)

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!
__________________

Quote:
Originally Posted by Cameltoe View Post
Share the progress so others who are looking for the same also find's their answer.
Quote:
Originally Posted by teomakedonija View Post
ahaha i don't want
Rep++;
Cameltoe 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
[FilterScript] Experience system + Simple Account System KingHual Filterscripts 72 27/06/2015 09:07 PM
Experience System srcka< Scripting Help 8 22/07/2012 08:10 AM
[HELP] Experience and level system anito Scripting Help 1 02/07/2012 02:07 PM
Need help with level making Dominiks Help Archive 5 08/07/2009 07:15 PM


All times are GMT. The time now is 02:53 AM.


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