This msg keeps repeating
#1

Hello,i've a rob function with 30 seconds countdown,and i've added this code to send message to cops when player starts a robbery:

pawn Код:
for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(!IsPlayerConnected(i))continue;
    new current_zone;
    current_zone = player_zone[i];
    if(gTeam[i] == TEAM_COP)
    {
    new copmsg[170];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(copmsg, sizeof(copmsg), "- WARNING ALL COPS: Robbery in progress by %s (%d) - Location: %s",name,playerid,zones[current_zone][zone_name]);
    SendClientMessage(i, COLOR_BLUE, copmsg);
    }
    }
The problem is: It send the same message every 1 second for 30 seconds,cause spamming the chat.How to fix that?
Reply
#2

Show the whole code, including the timer.
Reply
#3

Quote:
Originally Posted by MP2
Посмотреть сообщение
Show the whole code, including the timer.
pawn Код:
public pRobTimer(playerid)
{
    pRobCount[playerid]--;
    new rbgt[128];
    format(rbgt, sizeof(rbgt), "Robbery ~g~in progress.~r~Do NOT leave the checkpoint.~y~Time left: ~g~%i", pRobCount[playerid]);
    GameTextForPlayer(playerid, rbgt, 1000, 5);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
    if(!IsPlayerConnected(i))continue;
    new current_zone;
    current_zone = player_zone[i];
    if(gTeam[i] == TEAM_COP)
    {
    new copmsg[170];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(copmsg, sizeof(copmsg), "- WARNING ALL COPS: Robbery in progress by %s (%d) - Location: %s",name,playerid,zones[current_zone][zone_name]);
    SendClientMessage(i, COLOR_BLUE, copmsg);
    }
    }
    if(pRobCount[playerid] == 0)
    {
        KillTimer(pRobTimerID[playerid]);
        new plwl = GetPlayerWantedLevel(playerid);
        plwl = GetPlayerWantedLevel(playerid);
        SetPlayerWantedLevel(playerid,plwl +2);
        new robmoney = 10500 + random(50000);
        GivePlayerMoney(playerid,robmoney);
        new string2[135];
        format(string2, sizeof(string2), "- SUCCESS ROBBERY - Wanted Level %d - Robbed %i$",plwl,robmoney);
        SendClientMessage(playerid,red,string2);
        GameTextForPlayer(playerid, "Robbery ~r~COMPLETE.", 3000, 5);
        new file[128];
        new pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(file, sizeof(file), SERVER_USER_FILE, pname);
        TotalRobberies += PlayerInfo[playerid][pRobberies];
        PlayerInfo[playerid][pRobberies] = dini_Int(file, "Robberies");
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
        new string3[135];
        new current_zone;
        current_zone = player_zone[playerid];
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string3, sizeof(string3), "- ROBBERY - %s (%d) has robbed %i$ from %s",name,playerid,robmoney,zones[current_zone][zone_name]);
        SendClientMessageToAll(COLOR_WHITE,string3);
    }
}
Reply
#4

ye, coz you didnt add a check for WHEN the message should be sent. assuming a robbery needs 30 seconds (so thats the initial countdown), a switch/case will do fine:
pawn Код:
public pRobTimer(playerid)
{
    pRobCount[playerid]--;
    new rbgt[128];
    format(rbgt, sizeof(rbgt), "Robbery ~g~in progress.~r~Do NOT leave the checkpoint.~y~Time left: ~g~%i", pRobCount[playerid]);
    GameTextForPlayer(playerid, rbgt, 1000, 5);
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    new copmsg[170];
    format(copmsg, sizeof(copmsg), "- WARNING ALL COPS: Robbery in progress by %s (%d) - Location: %s",name,playerid,zones[current_zone][zone_name]);
    switch(pRobCount[playerid])
    {
        case 29://case 25://?//assuming your countdown starts at 30, then pRobCount[playerid]--;, so send the message 1 second after the player triggered the timer, thats 29 hehe. hm. why not send the message 5 seconds later, so theplayer can take a breath first? ^^
        {
            for(new i=0;i<MAX_PLAYERS;i++)
            {
                if(!IsPlayerConnected(i))continue;
                new current_zone;
                current_zone = player_zone[i];
                if(gTeam[i] == TEAM_COP)
                {
                    SendClientMessage(i, COLOR_BLUE, copmsg);
                }
            }
        }
        case 0:
        {
            KillTimer(pRobTimerID[playerid]);
            new plwl = GetPlayerWantedLevel(playerid);
            plwl = GetPlayerWantedLevel(playerid);
            SetPlayerWantedLevel(playerid,plwl +2);
            new robmoney = 10500 + random(50000);
            GivePlayerMoney(playerid,robmoney);
            new string2[135];
            format(string2, sizeof(string2), "- SUCCESS ROBBERY - Wanted Level %d - Robbed %i$",plwl,robmoney);
            SendClientMessage(playerid,red,string2);
            GameTextForPlayer(playerid, "Robbery ~r~COMPLETE.", 3000, 5);
            new file[128];
            new pname[MAX_PLAYER_NAME];
            GetPlayerName(playerid, pname, sizeof(pname));
            format(file, sizeof(file), SERVER_USER_FILE, pname);
            TotalRobberies += PlayerInfo[playerid][pRobberies];
            PlayerInfo[playerid][pRobberies] = dini_Int(file, "Robberies");
            SetPlayerScore(playerid, GetPlayerScore(playerid) + 1);
            new string3[135];
            new current_zone;
            current_zone = player_zone[playerid];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));
            format(string3, sizeof(string3), "- ROBBERY - %s (%d) has robbed %i$ from %s",name,playerid,robmoney,zones[current_zone][zone_name]);
            SendClientMessageToAll(COLOR_WHITE,string3);
        }
    }
    return 1;
}
now feel free to add a default:{GameTextForPlayer(playerid,"seconds left: format(%d,pRobCount[playerid]blabla)
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)