SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 12/06/2014, 02:01 PM   #1
Twizted
High-roller
 
Join Date: Feb 2011
Location: Portugal
Posts: 1,475
Reputation: 289
Default Creating an experience system:

I've been reading a tutorial for this purpose but it doesn't really help me much. I'm adding an experience system within my server. I want the player to level up after obtaining 1000 experience points by doing several things (I won't encourage killing, so players will get experience points for being online, completing missions, jobs, etc.). I'm not really sure how I could do this sort of system, therefore requiring your help.

pawn Code:
enum pInfo
{
    pPass, // un-needed
    pCash, // un-needed
    pAdmin, // un-needed
    pSex, // un-needed
    pAge, // un-needed
    pLevel,
    pEXP,
    Float:pPos_x, // un-needed
    Float:pPos_y, // un-needed
    Float:pPos_z, // un-needed
    pSkin, // un-needed
    pCrew // un-needed
}

To sum it up: For each 1000 experience points a player has, he levels up (using SetPlayerScore for that). I'd be very grateful If you could help me out.
Twizted is offline   Reply With Quote
Old 12/06/2014, 02:32 PM   #2
BiosMarcel
Banned
 
Join Date: Jul 2012
Location: Germany
Posts: 1,224
Reputation: 234
Default AW: Creating an experience system:

PHP Code:
stock AddPlayerEXP(playerid,xp)
{
    
pEXP pEXP xp;
    if(
pEXP >= 1000)
    {
        
SetPlayerScore(playerid,GetPlayerScore(playerid) + 1);
        
pEXP pEXP 1000;
        
pLevel++;
    }
    return 
1;

BiosMarcel is offline   Reply With Quote
Old 12/06/2014, 02:34 PM   #3
magnusburton
Big Clucker
 
magnusburton's Avatar
 
Join Date: Jun 2013
Location: Stockholm, Sweden
Posts: 53
Reputation: 8
Default Re: AW: Creating an experience system:

Quote:
Originally Posted by [Bios]Marcel View Post
PHP Code:
stock AddPlayerEXP(playerid,xp)
{
    
pEXP pEXP xp;
    if(
pEXP >= 1000)
    {
        
SetPlayerScore(playerid,GetPlayerScore(playerid) + 1);
        
pEXP pEXP 1000;
        
pLevel++;
    }
    return 
1;

Added the pLevel++;
__________________

a free, virtual stock market game.
magnusburton is offline   Reply With Quote
Old 12/06/2014, 03:01 PM   #4
_Mohit_
Big Clucker
 
Join Date: Sep 2012
Location: India
Posts: 83
Reputation: 5
Default Re: Creating an experience system:

where do u use the enums? I mean something like PlayerInfo[].... Should be there.Post it also so that i can help u.
_Mohit_ is offline   Reply With Quote
Old 12/06/2014, 06:38 PM   #5
Twizted
High-roller
 
Join Date: Feb 2011
Location: Portugal
Posts: 1,475
Reputation: 289
Default Re: Creating an experience system:

Quote:
Originally Posted by _Mohit_ View Post
where do u use the enums? I mean something like PlayerInfo[].... Should be there.Post it also so that i can help u.
pawn Code:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pSex,
    pAge,
    pLevel,
    pEXP,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pCrew
}
new PlayerInfo[MAX_PLAYERS][pInfo];

@[Bios]Marcel: What If I want to add a specific ammount of EXP to the player's EXP?
Twizted is offline   Reply With Quote
Old 12/06/2014, 06:53 PM   #6
TakeiT
Gangsta
 
Join Date: May 2014
Location: Toronto, Canada
Posts: 740
Reputation: 157
Default Re: Creating an experience system:

I use this to check a similar system, if it's what you're looking for.

pawn Code:
if (!(PlayerInfo[pid][pEXP] % 1000))
{
    //level up or whatever in here.
}
TakeiT is offline   Reply With Quote
Old 12/06/2014, 07:02 PM   #7
Patrick
Guest
 
Posts: n/a
Default Re: Creating an experience system:

Maybe something like this?

pawn Code:
#define EXP_ACHIEVMENT (1000)

#define SetPlayerEXP(%0,%1) \
        PlayerInfo[%0][pEXP] = %1, CheckPlayerEXP(%0)

#define GetPlayerEXP(%0) \
        PlayerInfo[%0][pEXP]

CheckPlayerEXP(playerid)
{
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT) //1, 000
    {
        //code here
    }
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT * 2) //2, 000
    {
        //code here
    }
    if(PlayerInfo[playerid][pEXP] >= EXP_ACHIEVMENT * 3) //3, 000
    {
        //code here
    }        
}
  Reply With Quote
Old 12/06/2014, 07:09 PM   #8
Denying
Gangsta
 
Join Date: Feb 2013
Posts: 541
Reputation: 13
Default Re: Creating an experience system:

Okay, so I'll assume you are an experienced scripter who knows his way around, I'll just tell you the stages, generally.

You want to have an EXP variable for each player, preferably in an enum.
Each time you give a player EXP (such as completing a mission) you will want to see how much EXP he/she will have after you give him/her the EXP, if it's over 1000 (assuming you'll level up only at 1000 no matter what level you are at) you will want to get the difference between 1000 and his current EXP:
example: Player A has 600 EXP and you're giving him 500 EXP we don't 100 EXP to go to waste, so you will have to do 1000 - 600 = 400. You will then subtract 400 from the 500, you will level him up and SET (not add) his EXP to the remaining of the 500 which in this case is 100.

Also you'll probably want to save his data somewhere (a .ini file, a database) I guess that's it.
Denying is offline   Reply With Quote
Old 12/06/2014, 07:16 PM   #9
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,639
Reputation: 1185
Default Re: Creating an experience system:

pawn Code:
#include <a_samp>
#include <zcmd>

enum PlayerInfo
{
    Exp,
    CurExp,
    Level,
}
new pInfo[MAX_PLAYERS][PlayerInfo];

CMD:test(playerid, params[])
{
    SetTimer("LevelTimer", 1800000, true);
   
    pInfo[playerid][Exp] = 8;
    pInfo[playerid][Level] = 1;
   
    return 1;
}

forward LevelTimer(playerid);
public LevelTimer(playerid)
{
    new string[128];
   
    if(pInfo[playerid][CurExp] != pInfo[playerid][Exp])
    {
        pInfo[playerid][CurExp] += 1;

        format(string, sizeof(string), "SERVER:{FFFFFF} Level progression: {BF4B4B}%d{FFFFFF}/{60B34B}%d{FFFFFF}. Next payday in 30 minutes.", pInfo[playerid][CurExp], pInfo[playerid][Exp]);
        SendClientMessage(playerid, 0x46E850FF, string);
    }
   
    else if(pInfo[playerid][CurExp] == pInfo[playerid][Exp])
    {
        pInfo[playerid][CurExp] = 0;
        pInfo[playerid][Exp] += 8;
       
        pInfo[playerid][Level] += 1;

        format(string, sizeof(string), "SERVER:{FFFFFF} You have leveled up! New level: {FFBB00}%d{FFFFFF}!", pInfo[playerid][Level]);
        SendClientMessage(playerid, 0x46E850FF, string);
       
        format(string, sizeof(string), "SERVER:{FFFFFF} Experience necessities upgraded: {BF4B4B}%d{FFFFFF}/{FFBB00}%d{FFFFFF}.", pInfo[playerid][CurExp], pInfo[playerid][Exp]);
        SendClientMessage(playerid, 0x46E850FF, string);
    }

    return 1;
}
Dignity is offline   Reply With Quote
Old 12/06/2014, 07:44 PM   #10
BiosMarcel
Banned
 
Join Date: Jul 2012
Location: Germany
Posts: 1,224
Reputation: 234
Default AW: Re: Creating an experience system:

Quote:
Originally Posted by Twizted View Post
pawn Code:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pSex,
    pAge,
    pLevel,
    pEXP,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pSkin,
    pCrew
}
new PlayerInfo[MAX_PLAYERS][pInfo];

@[Bios]Marcel: What If I want to add a specific ammount of EXP to the player's EXP?
You said that u want them to lvl up every 1000 xp );
BiosMarcel 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 10:07 PM
Experience system bug Fenky Scripting Help 8 07/08/2013 03:03 AM
Experience System srcka< Scripting Help 8 22/07/2012 09:10 AM
[HELP] Experience and level system anito Scripting Help 1 02/07/2012 03:07 PM


All times are GMT. The time now is 06:39 AM.


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