Custom Made Phone system, saying un-existent number. :S
#1

And hello again.. I don't really know what is made of me without you guys.

I made my first phone system, but it says me all the time "You get a busy tone.". It's the text i setted to return when the number the player called is not an existent number.

To see if it exists, i used foreach to check all players phone number, and if some of them is the call number, it will call him.. The code explains better. Actualy tested with a friend, and both me and him couldn't call each other.

pawn Код:
CMD:call(playerid, params[])
{
    if(PlayerInfo[playerid][Phone] == 1)
    {
        new number;
        if(!sscanf(params, "i", number))
        {
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
                else return SendClientMessage(playerid, COLOR_LIGHTRED, "You get a busy tone.");
            }
            return 1;
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /call [Number]");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have a phone.");
}
Thanks
Reply
#2

Ow my f*cking god...

pawn Код:
for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
REMOVE the return 1 INSIDE THE LOOP.

15th time I tell you this,

Also, use this:

pawn Код:
new acount = 0;
           for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
        {
            acount++;
                }
    }
if(acount > 0)
{
      if(PlayerInfo[i][PhoneNumber] == number)
        {
            SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
            PlayerInfo[playerid][Call] = number;
            PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
            return 1;
        }
}
else
{
 THA MESSAGE FOR NOT EXISTING
        {
        {
To see if somebody has that number, otherwise it will return the message for every player
Reply
#3

Be careful when using 'return' in loops.
Reply
#4

Quote:
Originally Posted by milanosie
Посмотреть сообщение
Ow my f*cking god...

pawn Код:
for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
REMOVE the return 1 INSIDE THE LOOP.

15th time I tell you this,

Also, use this:

pawn Код:
new acount = 0;
           for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
        {
            acount++;
                }
    }
if(acount > 0)
{
      if(PlayerInfo[i][PhoneNumber] == number)
        {
            SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
            PlayerInfo[playerid][Call] = number;
            PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
            return 1;
        }
}
else
{
 THA MESSAGE FOR NOT EXISTING
        {
        {
To see if somebody has that number, otherwise it will return the message for every player
That shows me these errors, and i know how to fix them but i don't know if my way will not bug it. xD

Код:
C:\Users\Ricardo\Desktop\Programaзгo\samp03rp\gamemodes\RRP.pwn(7537) : error 017: undefined symbol "i"
C:\Users\Ricardo\Desktop\Programaзгo\samp03rp\gamemodes\RRP.pwn(7539) : error 017: undefined symbol "i"
C:\Users\Ricardo\Desktop\Programaзгo\samp03rp\gamemodes\RRP.pwn(7541) : error 017: undefined symbol "i"
C:\Users\Ricardo\Desktop\Programaзгo\samp03rp\gamemodes\RRP.pwn(7553) : warning 209: function "cmd_call" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
pawn Код:
CMD:call(playerid, params[])
{
    if(PlayerInfo[playerid][Phone] == 1)
    {
        new number;
        if(!sscanf(params, "i", number))
        {
            new acount = 0;
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    acount++;
                }
            }
            if(acount > 0)
            {
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "You get a busy tone.");
                }
            }
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /call [Number]");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have a phone.");
}
Errors lines:
pawn Код:
if(PlayerInfo[i][PhoneNumber] == number)
                {
                    SendClientMessage(i, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[i][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
Reply
#5

'i' s scope is restricted to the loop try this.

pawn Код:
CMD:call(playerid, params[])
{
    if(PlayerInfo[playerid][Phone] == 1)
    {
        new
            iTargetID = INVALID_PLAYER_ID,
            number;
        if(!sscanf(params, "i", number))
        {
            for (new i = 0; i < MAX_PLAYERS; i++)
            {
                if( !IsPlayerConnected( i )) continue;
                if(PlayerInfo[i][PhoneNumber] == number)
                {
                    iTargetID = i;
                    break;
                }
            }
            if(iTargetID != INVALID_PLAYER_ID)
            {
                if(PlayerInfo[iTargetID][PhoneNumber] == number)//Pointless, should swap this for the var that tells you if the number is busy.
                {
                    SendClientMessage(iTargetID, COLOR_YELLOWGREEN, "Your phone is beeping, /pickup too pickup the call or /hangup if you are not willing to pickup.");
                    PlayerInfo[playerid][Call] = number;
                    PlayerInfo[iTargetID][Call] = PlayerInfo[playerid][PhoneNumber];
                    return 1;
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "You get a busy tone.");
                }
            }
            else return SendClientMessage(playerid, COLOR_LIGHTRED, "No player with that number found.");
        }
        else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /call [Number]");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have a phone.");
}
EDIT: I don't think busy tone will work how you want it to though. You should have a var to tell you if the players number is busy or not. I commented the line you should edit.
Reply
#6

Will try out. Thanks for the help.
Reply
#7

Made this /pickup and /p to pickup and talk, but, when we do it, nothing show up to me, eigher to my partner.

pawn Код:
CMD:pickup(playerid, params[])
{
    if(PlayerInfo[playerid][Call] != 0)
    {
        new iTargetID = INVALID_PLAYER_ID;
        for (new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][Call] == PlayerInfo[playerid][PhoneNumber])
            {
                iTargetID = i;
                break;
            }
            if(iTargetID != INVALID_PLAYER_ID)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "You picked up the call.");
                SendClientMessage(iTargetID, COLOR_LIGHTRED, "He picked up the call.");
            }
            return 1;
        }
        return 1;
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "No-one is calling you.");
}
CMD:p(playerid, params[])
{
    if(PlayerInfo[playerid][Call] != 0)
    {
        new iTargetID = INVALID_PLAYER_ID;
        for (new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerInfo[i][Call] == PlayerInfo[playerid][PhoneNumber])
            {
                iTargetID = i;
                break;
            }
            if(iTargetID != INVALID_PLAYER_ID)
            {
                new text[128], string[128];
                if(!sscanf(params, "s[128]", text))
                {
                    format(string, sizeof(string), "He says: %s", text);
                    SendClientMessage(iTargetID, COLOR_YELLOWGREEN, string);
                    format(string, sizeof(string), "You said: %s", text);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                    return 1;
                }
                else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /p [Text]");
            }
            return 1;
        }
        return 1;
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You are not in a call.");
}
Reply
#8

pawn Код:
if(iTargetID != INVALID_PLAYER_ID)
            {
                new text[128], string[128];
                if(!sscanf(params, "s[128]", text))
                {
                    format(string, sizeof(string), "He says: %s", text);
                    SendClientMessage(iTargetID, COLOR_YELLOWGREEN, string);
                    format(string, sizeof(string), "You said: %s", text);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                    return 1;
                }
                else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /p [Text]");
Why are you using this inside the loop?
It should be outside.
Reply
#9

Quote:
Originally Posted by milanosie
Посмотреть сообщение
pawn Код:
if(iTargetID != INVALID_PLAYER_ID)
            {
                new text[128], string[128];
                if(!sscanf(params, "s[128]", text))
                {
                    format(string, sizeof(string), "He says: %s", text);
                    SendClientMessage(iTargetID, COLOR_YELLOWGREEN, string);
                    format(string, sizeof(string), "You said: %s", text);
                    SendClientMessage(playerid, COLOR_GREEN, string);
                    return 1;
                }
                else return SendClientMessage(playerid, COLOR_LIGHTRED, "Usage: /p [Text]");
Why are you using this inside the loop?
It should be outside.
Because this part is the one i am using to send the messages/textes, and there is the need of checking things before.. I am really confused. Lol. I am following what they said in be posts before..
Reply
#10

Was there something wrong with the code i posted? You seem to have edited and broke it. Again you are returning 1 inside a loop with no conditions. It will only ever loop once. And if you send the message from inside the loop you will spam the player and yourself (if you fix the loop that is).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)