SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 29/08/2019, 06:46 PM   #1
Mobtiesgangsa
Big Clucker
 
Join Date: Oct 2016
Posts: 131
Reputation: 16
Question Experiance system for player to level up

Hello Community i would be interested on your help for making a XP a.k.a Experience system that increases the players level depending if they have reached certain amount of XP's in order for the level to be effective.

Best Regards: MobtiesgangSA

i don't know where to start.
P.S. I have a variable defined on my script
Mobtiesgangsa is offline   Reply With Quote
Old 29/08/2019, 07:22 PM   #2
darkdrago
Huge Clucker
 
darkdrago's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 290
Reputation: 38
Default Re: Experiance system for player to level up

I'll show you an example so you can have something to start with
Code:
new TimerEXP[MAX_PLAYERS],Exp[MAX_PLAYERS],Level[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
	TimerEXP[playerid] = SetTimerEx("Experience",3600000,1,"i",playerid); //Every 1 Hour
	return 1;
}

public OnPlayerDisconnect(playerid,reason)
{
	KillTimer(TimerEXP[playerid]);
	return 1;
}

forward Experience(playerid);
public Experience(playerid)
{	
	Exp[playerid]++;
	SendClientMessage(playerid,-1,"You gained 1 EXP point");
	if(Exp[playerid] >= Level[playerid] * 2)
	{
		new string[60];
		Level[playerid]++;
		Exp[playerid] = 0;
		format(string,sizeof(string),"Level up, you now need to make %d points to level up",Level[playerid] * 2);
		SendClientMessage(playerid,-1,string);
	}
	return 1;
}
Since you got your variables already i assume you already know how to store those vars to your players, so mine is just a quick example.
It will require always LEVEL*2 exp points, means that if you're level 1 you'll need 2 points, if you're level 2 you'll need 4 etc...
Of course you can change this here:
Code:
if(Exp[playerid] >= Level[playerid] * 2)
__________________
darkdrago is offline   Reply With Quote
Old 29/08/2019, 07:29 PM   #3
Mobtiesgangsa
Big Clucker
 
Join Date: Oct 2016
Posts: 131
Reputation: 16
Default Re: Experiance system for player to level up

Quote:
Originally Posted by darkdrago View Post
I'll show you an example so you can have something to start with
Code:
new TimerEXP[MAX_PLAYERS],Exp[MAX_PLAYERS],Level[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
	TimerEXP[playerid] = SetTimerEx("Experience",3600000,1,"i",playerid); //Every 1 Hour
	return 1;
}

forward Experience(playerid);
public Experience(playerid)
{	
	Exp[playerid]++;
	SendClientMessage(playerid,-1,"You gained 1 EXP point");
	if(Exp[playerid] == Level[playerid] * 2)
	{
		new string[60];
		Level[playerid]++;
		Exp[playerid] = 0;
		format(string,sizeof(string),"Level up, you now need to make %d points to level up",Level[playerid] * 2);
		SendClientMessage(playerid,-1,string);
	}
	return 1;
}
Since you got your variables already i assume you already know how to store those vars to your players, so mine is just a quick example.
It will require always LEVEL*2 exp points, means that if you're level 1 you'll need 2 points, if you're level 2 you'll need 4 etc...
Of course you can change this here:
Code:
if(Exp[playerid] == Level[playerid] * 2)
i have my var for xp to increase OnPlayerDeath if the killerid killed a specific player its xp is increased by 25xp, my plans are to be raised from 0 > 2000 if its reached 2000xp a level will be increased the next level also increases the xp to 2400 and so on and so one
Mobtiesgangsa is offline   Reply With Quote
Old 29/08/2019, 07:29 PM   #4
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 275
Reputation: 22
Default Re: Experiance system for player to level up

Code:
if(Exp[playerid] == Level[playerid] * 2)
Shouldn't this be >=?
If you don't set the default value of Level[playerid] to 1, you can't reach level 1, because
1 != 0*2
Plastikmensch is offline   Reply With Quote
Old 29/08/2019, 07:35 PM   #5
darkdrago
Huge Clucker
 
darkdrago's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 290
Reputation: 38
Default Re: Experiance system for player to level up

Quote:
Originally Posted by Plastikmensch View Post
Code:
if(Exp[playerid] == Level[playerid] * 2)
Shouldn't this be >=?
If you don't set the default value of Level[playerid] to 1, you can't reach level 1, because
1 != 0*2
You're right, i wrote it quickly and did that mistake, my bad, i fixed it, thanks

Quote:
Originally Posted by Mobtiesgangsa View Post
i have my var for xp to increase OnPlayerDeath if the killerid killed a specific player its xp is increased by 25xp, my plans are to be raised from 0 > 2000 if its reached 2000xp a level will be increased the next level also increases the xp to 2400 and so on and so one
Well, the script is kinda same, but you gotta check it in OnPlayerDeath instead of in a timer in this case.
For the math, i can't help, i'm bad myself, if you get it i can help you with the other things
__________________
darkdrago is offline   Reply With Quote
Old 29/08/2019, 07:46 PM   #6
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 275
Reputation: 22
Default Re: Experiance system for player to level up

Quote:
Originally Posted by Mobtiesgangsa View Post
i have my var for xp to increase OnPlayerDeath if the killerid killed a specific player its xp is increased by 25xp, my plans are to be raised from 0 > 2000 if its reached 2000xp a level will be increased the next level also increases the xp to 2400 and so on and so one
Can you explain a bit more?
You can change darkdragos example for you needs. It was just an example of how it works.
If you want to increase the xp requirement by 400 for every level, the math is Level[killerid]*400+2000
(killerid, because you want to use it in OnPlayerDeath. Don't forget to check if it's valid)
Plastikmensch is offline   Reply With Quote
Old 29/08/2019, 07:52 PM   #7
Mobtiesgangsa
Big Clucker
 
Join Date: Oct 2016
Posts: 131
Reputation: 16
Default Re: Experiance system for player to level up

Quote:
Originally Posted by darkdrago View Post
You're right, i wrote it quickly and did that mistake, my bad, i fixed it, thanks



Well, the script is kinda same, but you gotta check it in OnPlayerDeath instead of in a timer in this case.
For the math, i can't help, i'm bad myself, if you get it i can help you with the other things
anyway thanks for your best advice ill be seeking to implement such a algorithm and it ill require some candidates for testing it on my host would be great if you would like to join, when im done it will be started on saturday
Mobtiesgangsa is offline   Reply With Quote
Old 29/08/2019, 07:59 PM   #8
darkdrago
Huge Clucker
 
darkdrago's Avatar
 
Join Date: Nov 2009
Location: Italy
Posts: 290
Reputation: 38
Default Re: Experiance system for player to level up

Quote:
Originally Posted by Mobtiesgangsa View Post
anyway thanks for your best advice ill be seeking to implement such a algorithm and it ill require some candidates for testing it on my host would be great if you would like to join, when im done it will be started on saturday
You can still test it with a Fake command:
Code:
CMD:fakedeath(playerid, params[])
{
	CallLocalFunction("OnPlayerDeath", "iii", playerid, playerid,0);
	return 1;
}
This might help you to test it, because it fakes your death like you killed yourself, so you'll get some XP
__________________
darkdrago 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
[GameMode] Roleplay/Stunt Server [Level + XP System] --> + [Admin/Vip System] HY Gamemode Scripts 13 17/10/2014 02:53 PM
[FilterScript] [FS]Level System for RolePlay + Register/Login System AlexSAMP Filterscripts 23 10/02/2013 11:35 AM
player level Brka Scripting Help 0 03/12/2011 11:15 AM
Rank (Level System) NOT ADMIN, BUT PLAYER [AG]_Just Help Archive 5 02/10/2009 03:40 PM
[HELP]Player level Frankox Help Archive 9 06/04/2009 10:04 PM


All times are GMT. The time now is 08:15 AM.


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