SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 22/08/2019, 12:45 PM   #11
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

Nope, same problem. This code is trolling me.

Basically this is what happens:

I'm level 99 and i reach level 100, i get the "You have leveled up and reached level 100" message, while it should send the max achievable message instead.

After i reach level 100 and the LevelUp checks again, this time i get the max achievable player level message, and everytime the LevelUpCheck stars if i'm level 100 it sends the same message, while it shouldn't be like this.

It should send the message only ONCE, after you reached level 100 you'll not get ANY message.

But this doesn't happen somehow.
__________________


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:52 PM   #12
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, same problem. This code is trolling me.

Basically this is what happens:

I'm level 99 and i reach level 100, i get the "You have leveled up and reached level 100" message, while it should send the max achievable message instead.

After i reach level 100 and the LevelUp checks again, this time i get the max achievable player level message, and everytime the LevelUpCheck stars if i'm level 100 it sends the same message, while it shouldn't be like this.

It should send the message only ONCE, after you reached level 100 you'll not get ANY message.

But this doesn't happen somehow.
Now i fully understand what your problem is and this is the solution you are welcome ~Edited

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 -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));
                AlreadyChecked[playerid] = 0;
             }
            else if(ReturnPlayerLevel(playerid) == MAX_PLAYER_LEVEL - 1 && AlreadyChecked[playerid] == 0)
            {
                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;
                AlreadyChecked[playerid] = 1;
            }
    }
    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, 01:11 PM   #13
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

Why that "AlreadyChecked"? Do i need to save it in my player's enum or not need? What if player quits and reconnect? Its variable will be set to 0 and i'll get the same problem again i guess.
__________________


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, 01:32 PM   #14
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
Why that "AlreadyChecked"? Do i need to save it in my player's enum or not need? What if player quits and reconnect? Its variable will be set to 0 and i'll get the same problem again i guess.
On second thought you can remove the AlreadyChecked array because when a player is already at 100 it wouldn't trigger any condition

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 -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 - 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, "");
                Beep(playerid);

                RemovePlayerExp(playerid, exp);

                Player[playerid][pLevel]++;

                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, 02:53 PM   #15
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,818
Reputation: 650
Default Re: Level up check

So first why
pawn Code:
foreach(new i: Player) LevelUpCheck(i);
just check each time after the player earned exp aka. in your EarnPlayerExp function, or however it is called

Here your restructured LevelUpCheck
pawn Code:
LevelUpCheck(playerid) {
    // removed spawn check because irrelevant
    if(ReturnPlayerLevel(playerid) != MAX_PLAYER_LEVEL) {
        new exp = (ReturnPlayerLevel(playerid) * 4);
        // removed failed message, add it in the else if you want it again
        if(ReturnPlayerExp(playerid) >= exp) {
            Beep(playerid);

            Player[playerid][pLevel]++; // you have ReturnPlayerLevel but no IncreasePlayerLevel or SetPlayerLevel function???

            if(ReturnPlayerLevel(playerid) == MAX_PLAYER_LEVEL) {
                Player[playerid][pExp] = 0; // no SetPlayerExp but a RemovePlayerExp function???   

                GiveScore(playerid, 100, "");

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

                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~!"
                );
            } else {
                RemovePlayerExp(playerid, exp);

                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)
                );
            }
        }
    }
}
Nero_3D is online now   Reply With Quote
Old 22/08/2019, 05:04 PM   #16
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

Yes Nero but where i should call LevelCheck to check if player can level up or not? Wouldn't i need a timer? I wanna run it every 60 minutes so i think a timer is ok.
__________________


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, 05:29 PM   #17
BiGuy
Little Clucker
 
Join Date: Jun 2018
Posts: 16
Reputation: 1
Default Re: Level up check

call levelupcheck whenever player earn exp its better than timer thats what nero means
__________________
Join my discord server 'The BiG Gaming Community':
https://discord.gg/6hzV6VT
BiGuy is offline   Reply With Quote
Old 22/08/2019, 06:10 PM   #18
KeyOfKey
Huge Clucker
 
KeyOfKey's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 450
Reputation: 16
Default Re: Level up check

I fixed with Nero's code, thank you!

A question (more a doubt tho). I don't wanna give any more EXP if a player is level 100 so i did in this way:

pawn Code:
stock GivePlayerExp(playerid, amount)
{
    if(ReturnPlayerLevel(playerid) == MAX_PLAYER_LEVEL) return 0;

    Player[playerid][pExp] += amount;
    return 1;
}

Is this correct?
__________________


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 23/08/2019, 06:13 AM   #19
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,066
Reputation: 50
Default Re: Level up check

Yes, it's correct, but where is levelupcheck? it's supposed to be here.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala 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 12:04 PM.


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