How to change timer to check if XP is equal or above...
#1

How to change timer to check if XP is equal or above and below a certain amount, and only check once.

Here is my code:
pawn Код:
public RankDetection(playerid)
{
    switch(PlayerInfo[playerid][Xp])
    {

        case 20:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private II!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 45:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Private First Class!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 70:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Specialist!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 120:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Corporal!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 170:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Sergeant!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 250:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Sergeant First Class!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 400:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Master Sergeant!");
            IncreasePlayerXp(playerid,1);
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
        }

        case 650:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to First Sergeant!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 1000:
        {
            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Sergeant Major!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
        }

        case 1500:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Command Sergeant Major!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 2100:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Sergeant Major of the Army!");
            IncreasePlayerXp(playerid,1);
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");

        }

        case 2800:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Warrant Officer!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 3900:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Chief Warrant Officer 2!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 5000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Chief Warrant Officer 3!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 7500:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Chief Warrant Officer 4!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 10000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Chief Warrant Officer 5!");
            IncreasePlayerXp(playerid,1);
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");

        }

        case 15000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Second Lieutenant!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 19000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to First Lieutenant!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 27000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Captain!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 35000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Major!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 50000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Lieutenant Colonel!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 70000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Colonel!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 100000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Brigadier General!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 120000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Major General!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 150000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to Lieutenant General!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 200000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to General!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);

        }

        case 300000:
        {

            SendClientMessage(playerid, COLOR_GREEN, "You have been promoted to General of the Army!");
            PlayAudioStreamForPlayer(playerid, "https://dl.dropbox.com/u/77376451/rankupmwffa.mp3");
            IncreasePlayerXp(playerid,1);
            GivePlayerAchievement(playerid, Ach_WhoDaresWins, 1);
        }
    }
    SetPlayerScore(playerid, PlayerInfo[playerid][Xp]);
    return 1;
}
As you can see, it is only set to check if it is equal to, not more...

So, I want to know how to change it so it checks if it above or equal too that, but below the next case, and only check once.

Thank you.


FIXED
Reply
#2

Rephrase your question, your code has nothing to do with timers. One thing I can say though is to take advantage of the range operator in the switch statement. (..) http://wiki.amxmodx.org/Pawn_Tutorial#Switch_Statements
Reply
#3

You should use an array for this, not 4500 switch cases..

Create an array of the score needed for each level, and a string-array for the rank names.

pawn Код:
new rankScore[] = {
20,
45,
70
...
};

new rankNames[][] = {
"Private II",
"Private First Class",
"Specialist",
...
};
Or more ideally use an enum (which is harder to understand for a beginner).
Reply
#4

Fixed!!!
I looked at lolumadd's COD5 script xD

Anyways thanks for the suggestions though.

I kept it in a timer, but changed "case" to "if"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)