SA-MP Forums Archive
How can I make this work? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How can I make this work? (/showthread.php?tid=436407)



How can I make this work? - Stefand - 11.05.2013

Well I got a working phone script but I want it to say when a number does not exist that its not in use.
But when I enter a number it sends that message that many times as that there are players online..

pawn Код:
command(call, playerid, params[])
{
    new number, string[128];
    if(sscanf(params, "d", number))
    {
        SendClientMessage(playerid, WHITE, "SYNTAX: /call [number]");
    }
    else
    {
        if(Player[playerid][PhoneN] == number || Player[playerid][PhoneN] == 0)
        {
            TextDrawShowForPlayer(playerid, Text:cantcallyourself);
            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
        }
        else
        {
            if(Player[playerid][PhoneStat] == 0)
            {
                if(Player[playerid][CellphoneConsole] == -1)
                {
                    if(number == 911)
                    {
                        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                        Player[playerid][CellphoneConsole] = 911;
                        format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                        NearByMessage(playerid, NICESKY, string);
                        SCM(playerid, PHONECOLOR, "***Dialing sound***");
                        SendClientMessage(playerid, PHONECOLOR, "Phone: You've called Emergency services, what do you need, Police, Fireman, Medic?");
                        Player[playerid][OnPhone] = 1;
                    }
                    else
                    {
                        if(Player[playerid][PhoneCredit] >= 1)
                        {
                            if(number != -1)
                            {
                                for(new i = 0; i < MAX_PLAYERS; i++)
                                {
                                    if(IsPlayerConnectedEx(i))
                                    {
                                        if(Player[i][PhoneN] == number)
                                        {
                                            if(Player[i][PhoneStat] == 0)
                                            {
                                                if(Player[i][BeingCalled] == -1)
                                                {
                                                    Player[playerid][Calling] = i;
                                                    Player[i][BeingCalled] = playerid;
                                                   
                                                    Player[playerid][OnPhone] = 1;
                                                    Player[i][OnPhone] = 1;



                                                    format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                    SCM(playerid, PHONECOLOR, "***Dialing sound***");

                                                    format(string, sizeof(string), "* %s's cellphone starts to ring...", RPName(i));
                                                    NearByMessage(i, NICESKY, string);
                                                    format(string, sizeof(string), "You are getting called, /pickup, Number: %d", Player[playerid][PhoneN]);
                                                    SCM(i, ADMINBLUE, string);

                                                    Player[i][CallConnectingTime] = 1;

                                                    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                                                }
                                                else
                                                {
                                                    format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                    SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                                    SCM(playerid, PHONECOLOR, "***You hear a voicemail***");
                                                    SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                                    format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                }
                                            }
                                            else
                                            {
                                                format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                NearByMessage(playerid, NICESKY, string);
                                                SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                                SCM(playerid, PHONECOLOR, "***You hear a voicemail***");
                                                SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                                format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                                NearByMessage(playerid, NICESKY, string);
                                            }
                                        }
                                        else if(Player[i][PhoneN] != number) //this is the code
                                        {
                                            format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                            NearByMessage(playerid, NICESKY, string);
                                            SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                            SCM(playerid, PHONECOLOR, "***You hear a message: This phone number is not in use.***");
                                            SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                            format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                            NearByMessage(playerid, NICESKY, string);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            TextDrawShowForPlayer(playerid, Text:Notenoughcredit);
                            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
                        }
                    }
                }
                else
                {
                    TextDrawShowForPlayer(playerid, Text:AlreadyCalling);
                    SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
                }
            }
            else
            {
                TextDrawShowForPlayer(playerid, Text:PhoneOFF);
                SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
            }
        }
    }
    return 1;
}



Re: How can I make this work? - Antonio144 - 11.05.2013

Should work like this.
I added bool so we can check if the number exist or not.
pawn Код:
command(call, playerid, params[])
{
    new number, string[128];
    new bool:pexists; //
    if(sscanf(params, "d", number))
    {
        SendClientMessage(playerid, WHITE, "SYNTAX: /call [number]");
    }
    else
    {
        if(Player[playerid][PhoneN] == number || Player[playerid][PhoneN] == 0)
        {
            TextDrawShowForPlayer(playerid, Text:cantcallyourself);
            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
        }
        else
        {
            if(Player[playerid][PhoneStat] == 0)
            {
                if(Player[playerid][CellphoneConsole] == -1)
                {
                    if(number == 911)
                    {
                        SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                        Player[playerid][CellphoneConsole] = 911;
                        format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                        NearByMessage(playerid, NICESKY, string);
                        SCM(playerid, PHONECOLOR, "***Dialing sound***");
                        SendClientMessage(playerid, PHONECOLOR, "Phone: You've called Emergency services, what do you need, Police, Fireman, Medic?");
                        Player[playerid][OnPhone] = 1;
                    }
                    else
                    {
                        if(Player[playerid][PhoneCredit] >= 1)
                        {
                            if(number != -1)
                            {
                                for(new i = 0; i < MAX_PLAYERS; i++)
                                {
                                    if(IsPlayerConnectedEx(i))
                                    {
                                        if(Player[i][PhoneN] == number)
                                        {
                                            pexist = true; // if the number does exist this will be true
                                            if(Player[i][PhoneStat] == 0)
                                            {
                                                if(Player[i][BeingCalled] == -1)
                                                {
                                                    Player[playerid][Calling] = i;
                                                    Player[i][BeingCalled] = playerid;
                                                   
                                                    Player[playerid][OnPhone] = 1;
                                                    Player[i][OnPhone] = 1;



                                                    format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                    SCM(playerid, PHONECOLOR, "***Dialing sound***");

                                                    format(string, sizeof(string), "* %s's cellphone starts to ring...", RPName(i));
                                                    NearByMessage(i, NICESKY, string);
                                                    format(string, sizeof(string), "You are getting called, /pickup, Number: %d", Player[playerid][PhoneN]);
                                                    SCM(i, ADMINBLUE, string);

                                                    Player[i][CallConnectingTime] = 1;

                                                    SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
                                                }
                                                else
                                                {
                                                    format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                    SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                                    SCM(playerid, PHONECOLOR, "***You hear a voicemail***");
                                                    SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                                    format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                                    NearByMessage(playerid, NICESKY, string);
                                                }
                                            }
                                            else
                                            {
                                                format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                                NearByMessage(playerid, NICESKY, string);
                                                SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                                SCM(playerid, PHONECOLOR, "***You hear a voicemail***");
                                                SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                                format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                                NearByMessage(playerid, NICESKY, string);
                                            }
                                        }
                                    }
                                }
                                if(pexist != true) // This code will be executed if the number does not exist (when the loop finishes)
                                {
                                        format(string, sizeof(string), "* %s takes out %s cellphone, and dials a number.", RPName(playerid), SexGender(playerid));
                                        NearByMessage(playerid, NICESKY, string);
                                        SCM(playerid, PHONECOLOR, "***Dialing sound***");
                                        SCM(playerid, PHONECOLOR, "***You hear a message: This phone number is not in use.***");
                                        SCM(playerid, PHONECOLOR, "***BEEP BEEP BEEP***");
                                        format(string, sizeof(string), "* %s puts %s cellphone back into %s pocket.", RPName(playerid), SexGender(playerid), SexGender(playerid));
                                        NearByMessage(playerid, NICESKY, string);
                                 }
                            }
                        }
                        else
                        {
                            TextDrawShowForPlayer(playerid, Text:Notenoughcredit);
                            SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
                        }
                    }
                }
                else
                {
                    TextDrawShowForPlayer(playerid, Text:AlreadyCalling);
                    SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
                }
            }
            else
            {
                TextDrawShowForPlayer(playerid, Text:PhoneOFF);
                SetTimerEx("RemoveTextMessage", 3500, false, "d", playerid);
            }
        }
    }
    return 1;
}



Re: How can I make this work? - Stefand - 11.05.2013

Worked thanks, REP++; xD


Re: How can I make this work? - zombieking - 11.05.2013

Sure, add a bool and never set its value - clever (because the names don't match - the declaration says pexists but you are using 'pexist' instead of the other one)
Loop through all the players and check if someone has the dialed number (and send an error message or a tone if no one has it)



Re: How can I make this work? - Antonio144 - 11.05.2013

Didn't spell correctly, my bad.