OnPlayerUpdate constant messages showing up.
#1

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(PlayerInfo[playerid][pKills] < 50)
    {
        TextDrawShowForPlayer(playerid, noob[playerid]);
        TextDrawHideForPlayer(playerid, soldier[playerid]);
        TextDrawHideForPlayer(playerid, warlord[playerid]);
        TextDrawHideForPlayer(playerid, gow[playerid]);
        Rank[playerid] = 1;
    }
    if(PlayerInfo[playerid][pKills] >= 50 && PlayerInfo[playerid][pKills] < 200)
    {
        TextDrawHideForPlayer(playerid, noob[playerid]);
        TextDrawShowForPlayer(playerid, soldier[playerid]);
        TextDrawHideForPlayer(playerid, warlord[playerid]);
        TextDrawHideForPlayer(playerid, gow[playerid]);
        SendClientMessage(playerid, COLOR_ORANGE, "[INFO]{FFFFFF} Congratulations! You have ranked up to Soldier! The Sniper Rifle is now available for free. (/getsr)");
        Rank[playerid] = 2;
    }
    if(PlayerInfo[playerid][pKills] >= 200 && PlayerInfo[playerid][pKills] < 500)
    {
        TextDrawHideForPlayer(playerid, noob[playerid]);
        TextDrawHideForPlayer(playerid, soldier[playerid]);
        TextDrawShowForPlayer(playerid, warlord[playerid]);
        TextDrawHideForPlayer(playerid, gow[playerid]);
        SendClientMessage(playerid, COLOR_ORANGE, "[INFO]{FFFFFF} Congratulations! You have ranked up to War Lord! The RPG is now available for free. (/getrpg)");
        Rank[playerid] = 3;
    }
    if(PlayerInfo[playerid][pKills] >= 500)
    {
        TextDrawHideForPlayer(playerid, noob[playerid]);
        TextDrawHideForPlayer(playerid, soldier[playerid]);
        TextDrawHideForPlayer(playerid, warlord[playerid]);
        TextDrawShowForPlayer(playerid, gow[playerid]);
        SendClientMessage(playerid, COLOR_ORANGE, "[INFO]{FFFFFF} Congratulations! You have ranked up to God Of War. Poison Katana is now available");
        SendClientMessage(playerid, COLOR_GREY, "[WEAP-EFFECT]{FFFFFF} Deals enormous amount of damage. /getpk to get a poison katana.");
        Rank[playerid] = 4;
    }
    return 1;
}
I am really new to scripting, and i have been making so many threads for help and I'm making one again. When the player spawns, soooo many messages keep showing up. Like 10 messages in 1 second :P. I really need help guys. Thanks in advance.
Reply
#2

this code should be in OnPlayerDeath for killer id and some changes in it are also needed
in if lines use like this
if(PlayerInfo[killerid][pKills] == 50)
PlayerInfo[killerid][pKills] == 200)
and so on for other ones
there should only be 1 condition only in "if" like i shown above
Reply
#3

edited..
Reply
#4

Quote:
Originally Posted by inshal
Код:
OnPlayerUpdate...
I am really new to scripting, and i have been making so many threads for help and I'm making one again. When the player spawns, soooo many messages keep showing up. Like 10 messages in 1 second :P. I really need help guys. Thanks in advance.
Well what did you expect? Read the documentation, I highly recommend the SA-MP Wiki, it's a great place to start and come back to when in doubt on how to use scripting functions.

Back to your problem, in case you didn't know OPU (short for OnPlayerUpdate) gets called around 20-30 times per second per player! (depending on your streamrate or what-not set in the server.cfg) That's a lot!

Don't make assumptions, plan your code out, write it on a back of paper or whatever, like the other guy posted that part of code would be better put under "OnPlayerDeath" or somewhere else like in a timer.

Also to make sure the message never comes back again (which is what you want for achievements) make the variable set to 1 and check if it's not 1 (ie. 0):
(I've put comments in the code below, you may need to scroll left-right)
pawn Код:
// part of code
    if(PlayerInfo[playerid][pKills] < 50 && !Rank[playerid]) // meaning: if player has less than 50 kills and hasn't been given a rank yet - "!" means logical NOT, negation - do the code below
    {
        TextDrawShowForPlayer(playerid, noob[playerid]);
        TextDrawHideForPlayer(playerid, soldier[playerid]);
        TextDrawHideForPlayer(playerid, warlord[playerid]);
        TextDrawHideForPlayer(playerid, gow[playerid]);
        Rank[playerid] = 1; // player is now rank 1
    }
    if(PlayerInfo[playerid][pKills] >= 50 && PlayerInfo[playerid][pKills] < 200 && Rank[playerid] != 2) // meaning: if player has more than 50 kills and less than 200 kills and he ISN'T rank 2 yet, do the code below
    {
        TextDrawHideForPlayer(playerid, noob[playerid]);
        TextDrawShowForPlayer(playerid, soldier[playerid]);
        TextDrawHideForPlayer(playerid, warlord[playerid]);
        TextDrawHideForPlayer(playerid, gow[playerid]);
        SendClientMessage(playerid, COLOR_ORANGE, "[INFO]{FFFFFF} Congratulations! You have ranked up to Soldier! The Sniper Rifle is now available for free. (/getsr)");
        Rank[playerid] = 2; // player is now rank 2
    }
Seeing the logic behind this now? Just make sure you only ever give a player their rank/achievement/whatever once! And you do that by checking if a variable is set.

Good luck!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)