SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 21/08/2019, 01:32 PM   #1
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Level up check

I made a level system which has a max player level of 100, and i made this to handle player's level up:

pawn Code:
LevelUpCheck(playerid)
{
    if(Player[playerid][Spawned])
    {
            new exp = (ReturnPlayerLevel(playerid) * 4);

            if(ReturnPlayerExp(playerid) < exp && ReturnPlayerLevel(playerid) != MAX_PLAYER_LEVEL)
            {
                return InformPlayer(playerid, 10000, "You have ~r~failed ~w~to level up. ~n~~n~You need ~y~%d ~w~more EXP in order to reach level ~y~%d~w~.",
                exp - ReturnPlayerExp(playerid), ReturnPlayerLevel(playerid) + 1);
            }

            if(ReturnPlayerLevel(playerid) != MAX_PLAYER_LEVEL)
            {
                Beep(playerid);

                RemovePlayerExp(playerid, exp);

                Player[playerid][pLevel]++;

                SCMEX(playerid, COLOR_YELLOW, "You have leveled up and reached level %d!", ReturnPlayerLevel(playerid));
               
                InformPlayer(playerid, 10000,
                "~w~You have leveled up and reached level ~y~%d~w~.~n~~n~Keep gaining EXP in order to level up and unlock ~p~vehicles and weapons~w~!\
                ~n~~n~You can check your current level with ~y~/level~w~."
,
                ReturnPlayerLevel(playerid));
            }
            else
            {
                SCMTAEX(COLOR_INFO, "%s (%d) has reached the max achievable level on "#SERVER_NAME", congrats!", ReturnPlayerName(playerid), playerid);
                SCM(playerid, COLOR_INFO, "You have reached the max level achievable. You will not level up anymore.");
               
                InformPlayer(playerid, 15000, "You have reached the ~y~max level achievable~w~.~n~~n~You will not level up anymore.\
                ~n~~n~As a reward for reaching max player level, you have earned ~g~$1500000 ~w~and ~y~100 score~w~!"
);

                GivePlayerCash(playerid, 1500000);
                TransactionLog(-1, playerid, 1500000, "Achieved Max Player Level", 0);

                GiveScore(playerid, 100, "");

                Player[playerid][pExp] = 0;
            }
    }
    return 1;
}

I have two problems btw:

If i reach level 100 i'll get the first message (You have leveled up and reached level bla bla, keep gainging exp bla bla) while it should send the second message
(You have reached the max level achievable etc), but it doesn't.

On next LevelUpCheck, even if i'm max level (which is 100), it sends the failed to level up message. I don't want this. I want to set just a message when player levels up,
and if the player reaches level 100 (max level) send him the max achievable level message just once and don't send anymore message on next LevelUp check (because it's useless since he reached max level already).

How?

I placed LevelUpCheck in a 60 minutes timer:

pawn Code:
foreach(new i: Player) LevelUpCheck(i);
__________________


Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.
KeyOfKey is offline   Reply With Quote
Old 22/08/2019, 10:20 AM   #2
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

Bump.
__________________


Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.
KeyOfKey is offline   Reply With Quote
Old 22/08/2019, 11:39 AM   #3
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,072
Reputation: 184
Default Re: Level up check

I have no idea what you did and why you did some things but here is what i see.
pawn Code:
new exp = (ReturnPlayerLevel(playerid) * 4);
exp is always 4 times bigger then ReturnPlayerLevel (unless it returns 0, in that case exp will be also 0)
And right after that you check if exp is less then ReturnPlayerLevel
pawn Code:
if(ReturnPlayerExp(playerid) < exp && ReturnPlayerLevel(playerid) != MAX_PLAYER_LEVEL)
So basically that condition is useless since exp will NEVER be less then ReturnPlayerLevel

[NOTE]I did no consider negative values as possibility since that makes no sense here.
__________________
Looking for someone to start drifting server, drop me a pm if you are interested.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is online now   Reply With Quote
Old 22/08/2019, 11:49 AM   #4
TomatoRage
Big Clucker
 
TomatoRage's Avatar
 
Join Date: Mar 2013
Location: Israel
Posts: 193
Reputation: 6
Default Re: Level up check

Can you show ReturnPlayerLevel function
__________________
I can script for you, bugs, gamemodes, addons you name it. Hit me up
Click On Me Please
TomatoRage is offline   Reply With Quote
Old 22/08/2019, 11:49 AM   #5
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

That calculation is required to level up. Imagine if a player is level 2, so 8 EXP are required to level up to 3.

@Tomato:

pawn Code:
stock ReturnPlayerLevel(playerid)
{
    return Player[playerid] [pLevel] ;
}
__________________


Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.
KeyOfKey is offline   Reply With Quote
Old 22/08/2019, 12:12 PM   #6
TomatoRage
Big Clucker
 
TomatoRage's Avatar
 
Join Date: Mar 2013
Location: Israel
Posts: 193
Reputation: 6
Default Re: Level up check

I am not so sure if it is going to work but try this
Code:
LevelUpCheck(playerid)
{
    if(Player[playerid][Spawned])
    {
            new exp;
            if(ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL)
            {
                exp = (ReturnPlayerLevel(playerid) * 4);
            }
            else{
             exp = 0;
            }
            if((ReturnPlayerExp(playerid) < exp) && ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL)
            {
                return InformPlayer(playerid, 10000, "You have ~r~failed ~w~to level up. ~n~~n~You need ~y~%d ~w~more EXP in order to reach level ~y~%d~w~.", 
                exp - ReturnPlayerExp(playerid), ReturnPlayerLevel(playerid) + 1);
            }

            else if(ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL)
            {
                Beep(playerid);

                RemovePlayerExp(playerid, exp);

                Player[playerid][pLevel]++;

                SCMEX(playerid, COLOR_YELLOW, "You have leveled up and reached level %d!", ReturnPlayerLevel(playerid));
                
                InformPlayer(playerid, 10000, 
                "~w~You have leveled up and reached level ~y~%d~w~.~n~~n~Keep gaining EXP in order to level up and unlock ~p~vehicles and weapons~w~!\
                ~n~~n~You can check your current level with ~y~/level~w~.",
                ReturnPlayerLevel(playerid));
            }
            else
            {
                SCMTAEX(COLOR_INFO, "%s (%d) has reached the max achievable level on "#SERVER_NAME", congrats!", ReturnPlayerName(playerid), playerid);
                SCM(playerid, COLOR_INFO, "You have reached the max level achievable. You will not level up anymore.");
                
                InformPlayer(playerid, 15000, "You have reached the ~y~max level achievable~w~.~n~~n~You will not level up anymore.\
                ~n~~n~As a reward for reaching max player level, you have earned ~g~$1500000 ~w~and ~y~100 score~w~!");

                GivePlayerCash(playerid, 1500000);
                TransactionLog(-1, playerid, 1500000, "Achieved Max Player Level", 0);

                GiveScore(playerid, 100, "");

                Player[playerid][pExp] = 0;
            }
    }
    return 1;
}
__________________
I can script for you, bugs, gamemodes, addons you name it. Hit me up
Click On Me Please
TomatoRage is offline   Reply With Quote
Old 22/08/2019, 12:28 PM   #7
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

Nope doesn't work. It sends the message everytime even if i'm already level 100.
__________________


Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.
KeyOfKey is offline   Reply With Quote
Old 22/08/2019, 12:29 PM   #8
TomatoRage
Big Clucker
 
TomatoRage's Avatar
 
Join Date: Mar 2013
Location: Israel
Posts: 193
Reputation: 6
Default Re: Level up check

Quote:
Originally Posted by KeyOfKey View Post
Nope doesn't work. It sends the message everytime even if i'm already level 100.
On the next check did it send the failed message ?
__________________
I can script for you, bugs, gamemodes, addons you name it. Hit me up
Click On Me Please
TomatoRage is offline   Reply With Quote
Old 22/08/2019, 12:32 PM   #9
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

No. I just get the "you have reached max player level achievable" bla bla
__________________


Symon's Cops and Robbers - Grand opening: October 1st 2019

Discord | IP | Website

Add your server to favourites and join our Discord.
KeyOfKey is offline   Reply With Quote
Old 22/08/2019, 12:33 PM   #10
TomatoRage
Big Clucker
 
TomatoRage's Avatar
 
Join Date: Mar 2013
Location: Israel
Posts: 193
Reputation: 6
Default Re: Level up check

try this and double check the max player level is it 100?
pawn Code:
LevelUpCheck(playerid)
{
    if(Player[playerid][Spawned])
    {
            new exp;
            if(ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL)
            {
                exp = (ReturnPlayerLevel(playerid) * 4);
            }
            else{
             exp = -1;
            }
            if((ReturnPlayerExp(playerid) < exp) && ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL)
            {
                return InformPlayer(playerid, 10000, "You have ~r~failed ~w~to level up. ~n~~n~You need ~y~%d ~w~more EXP in order to reach level ~y~%d~w~.",
                exp - ReturnPlayerExp(playerid), ReturnPlayerLevel(playerid) + 1);
            }

            else if(ReturnPlayerLevel(playerid) < MAX_PLAYER_LEVEL && exp != -1)
            {
                Beep(playerid);

                RemovePlayerExp(playerid, exp);

                Player[playerid][pLevel]++;

                SCMEX(playerid, COLOR_YELLOW, "You have leveled up and reached level %d!", ReturnPlayerLevel(playerid));
               
                InformPlayer(playerid, 10000,
                "~w~You have leveled up and reached level ~y~%d~w~.~n~~n~Keep gaining EXP in order to level up and unlock ~p~vehicles and weapons~w~!\
                ~n~~n~You can check your current level with ~y~/level~w~."
,
                ReturnPlayerLevel(playerid));
            }
            else if(ReturnPlayerLevel(playerid) == MAX_PLAYER_LEVEL && exp == -1)
            {
                SCMTAEX(COLOR_INFO, "%s (%d) has reached the max achievable level on "#SERVER_NAME", congrats!", ReturnPlayerName(playerid), playerid);
                SCM(playerid, COLOR_INFO, "You have reached the max level achievable. You will not level up anymore.");
               
                InformPlayer(playerid, 15000, "You have reached the ~y~max level achievable~w~.~n~~n~You will not level up anymore.\
                ~n~~n~As a reward for reaching max player level, you have earned ~g~$1500000 ~w~and ~y~100 score~w~!"
);

                GivePlayerCash(playerid, 1500000);
                TransactionLog(-1, playerid, 1500000, "Achieved Max Player Level", 0);

                GiveScore(playerid, 100, "");

                Player[playerid][pExp] = 0;
            }
    }
    return 1;
}
__________________
I can script for you, bugs, gamemodes, addons you name it. Hit me up
Click On Me Please
TomatoRage 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
[Tutorial] How to make a check timer (will check laggers) Eth Tutorials 9 01/05/2014 01:09 AM
Admin Level Check dreamboxxl Scripting Help 5 15/05/2013 07:45 PM
Check if he/she is higher level Zex Tan Scripting Help 2 07/04/2013 01:48 AM
[SOLVED] dudb cant check my level! Micko9 Help Archive 2 10/04/2010 07:29 AM


All times are GMT. The time now is 11:52 AM.


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