Spamming Message
#1

pawn Код:
forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pPackageLoading] >= 1)
            {
                PlayerInfo[i][pPackageLoading] --;
            }
            if(PlayerInfo[i][pPackageLoading] == 0)
            {
                SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
                return 1;
            }
            if(PlayerInfo[i][pPackageLoading] < 0)
            {
                PlayerInfo[i][pPackageLoading] = 0;
            }
        }
    }
    return 1;
}
The message "You are now able to load more products." spams all the way down the page, how do I make it so it only says it once?
Reply
#2

Change
pawn Код:
if(PlayerInfo[i][pPackageLoading] == 0)
to
pawn Код:
if(PlayerInfo[i][pPackageLoading] == 1)
The timer stops at 0, so then once PackageLoading reaches 0, it stays like that. So it's going to send the message everytime it detects PackageLoading at 0.
Reply
#3

Yeah, is there any way it just sends the message once when the timer hits 0?
Reply
#4

This ought to work;

pawn Код:
forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;

        /*
            Very important to decrement before comparing.
            If the package loading var is already 0,
            the function will set it to -1 and skip the following block.
            It will then execute the next block to set the variable back to 0.

            If the package loading var is not 0, the first statement will
            decrement the var, but it will not send the message until the
            var reaches 0.
        */

       
        if(--PlayerInfo[i][pPackageLoading] == 0)
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
            continue;
        }
        if(PlayerInfo[i][pPackageLoading] < 0)
        {
            PlayerInfo[i][pPackageLoading] = 0;
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
This ought to work;

pawn Код:
forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;

        /*
            Very important to decrement before comparing.
            If the package loading var is already 0,
            the function will set it to -1 and skip the following block.
            It will then execute the next block to set the variable back to 0.

            If the package loading var is not 0, the first statement will
            decrement the var, but it will not send the message until the
            var reaches 0.
        */

       
        if(--PlayerInfo[i][pPackageLoading] == 0)
        {
            SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
            continue;
        }
        if(PlayerInfo[i][pPackageLoading] < 0)
        {
            PlayerInfo[i][pPackageLoading] = 0;
        }
    }
    return 1;
}
Still the same Vince, just spams the message down the page. I can't think of a way possible.. unless I use 'stock'?
Reply
#6

I had this happened before to me, try this;
pawn Код:
forward Check();
public Check()
{
        if(!IsPlayerConnected(i))

            for(new i = 0; i < MAX_PLAYERS; i++)
            {
                if(--PlayerInfo[i][pPackageLoading] == 0)
                {
                    SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
                    continue;
                }
                if(PlayerInfo[i][pPackageLoading] < 0)
                {
                    PlayerInfo[i][pPackageLoading] = 0;
                }
            }
        }
    return 1;
}
Reply
#7

pawn Код:
forward Check();
public Check()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][pPackageLoading] == 1)
            {
                SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
            }
            if(PlayerInfo[i][pPackageLoading] >= 1)
            {
                PlayerInfo[i][pPackageLoading] --;
            }
            if(PlayerInfo[i][pPackageLoading] < 0)// AND WHY DO YOU NEED THIS? I WOULD DELETE THIS.
            {
                PlayerInfo[i][pPackageLoading] = 0;
            }
        }
    }
    return 1;
}
this should work
Reply
#8

Thanks guys, I added Vince's one wrong, managed to get it to work, thanks Vince.

[pawn]
forward Check();
public Check()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;

if(--PlayerInfo[i][pPackageLoading] == 0 && PlayerInfo[i][pJob] == JOB_TRUCKER )
{
SendClientMessage(i, COLOR_LIGHTBLUE, "You are now able to load more products.");
continue;
}
}
return 1;
}[pawn]

I have this now, would it work so only the players with a trucker job would get the message? I know quite a bit about scripting, but not too sure if this would work in PlayerUpdate
Reply
#9

You could replace the IsPlayerConnected with the following, which will just skip over anyone that is not a trucker.
pawn Код:
if(PlayerInfo[i][pJob] != JOB_TRUCKER) continue;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)