Phone bug
#1

I'll explain the bug first. I have a phone system, you can call and text other people. The problem is now, when I call someone, and afterwards the other hangs up, all messages that will be said after that both appear in the main chat and as a call-message from a player. Here is the code;

/call
pawn Код:
CMD:call(playerid, params[])
{
    new number, string[128], done;
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pHasCellphone]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a cellphone.");
    if(!PlayerInfo[playerid][pCellphone]) return SendClientMessage(playerid, COLOR_GREY, "You don't have a simcard.");
    if(sscanf(params, "i", number)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /call [number]");
    if(PhoneOff[playerid]) return SendClientMessage(playerid, COLOR_GREY, "Your phone is turned off.");
    if(Calling[playerid] || BeingCalled[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are already on a call.");
    if(number == 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid phone number.");
    format(string, sizeof(string), "* %s takes out their cellphone and starts calling a number.", RPN(playerid));
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    if(number == 911)
    {
        Calling[playerid] = 1;
        Call911[playerid] = 1;
        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
        SendClientMessage(playerid, COLOR_YELLOW, "[Cellphone]: You are connected to the SAPD emergency line, please explain your emergency.");
    }
    foreach(Player, i)
    {
        if(PlayerInfo[i][pCellphone] == number)
        {
            if(PhoneOff[i]) return SendClientMessage(playerid, COLOR_GREY, "Player has their phone turned off.");
            if(BeingCalled[i] || Calling[i]) return SendClientMessage(playerid, COLOR_GREY, "Number busy.");
            Calling[playerid] = 2;
            BeingCalled[i] = 2;
            Called[playerid] = i;
            Caller[i] = playerid;
            if(PlayerInfo[playerid][pAchievementRingRing] == 0)
            {
                ShowPlayerDialog(playerid,2350,DIALOG_STYLE_MSGBOX,"Achievement: Ring Ring","Congratulations, You have achieved the 'ring ring' badge by calling a player with your smartphone! \n You recieved $15!","Okay","Cancel");
                GiveZaiatMoney(playerid, 15);
                PlayerInfo[playerid][pTotalAchievements] ++;
                PlayerInfo[playerid][pAchievementRingRing] = 1;
            }
            SendClientMessage(playerid, COLOR_ORANGE, " The cellphone is ringing, wait for someone to pickup.");
            format(string, sizeof(string), "* %s's cellphone starts ringing.", RPN(i));
            SendNearbyMessage(i, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
            format(string, sizeof(string), " [Cellphone]: Incoming call from %s, Ph: %d", RPN(playerid), PlayerInfo[playerid][pCellphone]);
            SendClientMessage(i, COLOR_YELLOW, string);
            SendClientMessage(i, COLOR_WHITE, " Type /pickup to answer or /hangup to cancel the incoming call.");
            done = 1;
            SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
        }
    }
    if(done != 1)
    {
        SendClientMessage(playerid, COLOR_GREY, "Number is not currently available.");
    }
    return 1;
}
/pickup

pawn Код:
CMD:pickup(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pHasCellphone]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a cellphone.");
    if(!BeingCalled[playerid]) return SendClientMessage(playerid, COLOR_GREY, "Nobody is caling you.");
    format(string, sizeof(string), "* %s answers their cellphone.", RPN(playerid));
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    SendClientMessage(playerid, COLOR_ORANGE, " You have picked up the line.");
    SendClientMessage(Caller[playerid], COLOR_ORANGE, " They pickedup the line.");
    Calling[Caller[playerid]] = 2;
    BeingCalled[playerid] = 2;
    SetTimerEx("PhoneCall", 1000, false, "d", Caller[playerid]);
    return 1;
}
/hangup

pawn Код:
CMD:hangup(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pHasCellphone]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a cellphone.");
    if(!BeingCalled[playerid] && !Calling[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You are not on a call nor is anybody calling you.");
    format(string, sizeof(string), "* %s puts their cellphone away.", RPN(playerid));
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    SendClientMessage(playerid, COLOR_ORANGE, " You have hungup the line.");
    if(BeingCalled[playerid]) SendClientMessage(Caller[playerid], COLOR_ORANGE, " They hungup the line.");
    else if(Calling[playerid]) SendClientMessage(Called[playerid], COLOR_ORANGE, " They hungup the line.");
    if(Call911[playerid]) return SendClientMessage(playerid, COLOR_GREY, "You can't hangup on a 911 call.");
    //
    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
    if(Calling[playerid])
    {
        SetPlayerSpecialAction(Called[playerid], SPECIAL_ACTION_STOPUSECELLPHONE);
        format(string, sizeof(string), "[Cellphone] Phonecall lasted for %d seconds, price: $%d", CallTime[playerid], CallTime[playerid]*10/100);
        SendClientMessage(playerid, COLOR_YELLOW, string);
        GiveZaiatMoney(playerid, -(CallTime[playerid]*10/100));
        TaxMoney += (CallTime[playerid]*10/100);
        Calling[playerid] = 0;
        BeingCalled[playerid] = 0;
        Caller[playerid] = -1;
        CallTime[playerid] = 0;
        Called[playerid] = -1;
    }
    else if(Calling[Caller[playerid]])
    {
        SetPlayerSpecialAction(Called[playerid], SPECIAL_ACTION_STOPUSECELLPHONE);
        format(string, sizeof(string), "[Cellphone] Phonecall lasted for %d seconds, price: $%d", CallTime[Caller[playerid]], CallTime[Caller[playerid]]*10/100);
        SendClientMessage(Caller[playerid], COLOR_YELLOW, string);
        GiveZaiatMoney(Caller[playerid], -(CallTime[Caller[playerid]]*10/100));
        TaxMoney += (CallTime[Caller[playerid]]*10/100);
        Calling[Called[playerid]] = 0;
        BeingCalled[Called[playerid]] = 0;
        Caller[Called[playerid]] = -1;
        CallTime[Called[playerid]] = 0;
        Called[Called[playerid]] = -1;
    }
    return 1;
}
And the actual talking;

pawn Код:
if(BeingCalled[playerid] == 2 || Calling[playerid] == 2 || Call911[playerid])
    {
        if(strlen(PlayerInfo[playerid][pAccent])) format(string, sizeof(string), "[Cellphone] %s: [%s Accent] %s", RPN(playerid), PlayerInfo[playerid][pAccent], text);
        else format(string, sizeof(string), "[Cellphone] %s: %s", RPN(playerid), text);
        if(!Call911[playerid])
        {
            if(BeingCalled[playerid] == 2) SendClientMessage(Caller[playerid], COLOR_YELLOW, string);
            else if(Calling[playerid] == 2) SendClientMessage(Called[playerid], COLOR_YELLOW, string);
        }
    }
Thank you for the time you take reading this.
Reply
#2

Anyone?
Reply
#3

Please?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)