PDA

View Full Version : How can I make this work?


Stefand
11/05/2013, 10:44 AM
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..


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;
}

Antonio144
11/05/2013, 11:41 AM
Should work like this.
I added bool so we can check if the number exist or not.

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;
}

Stefand
11/05/2013, 11:48 AM
Worked thanks, REP++; xD

zombieking
11/05/2013, 11:48 AM
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)

Antonio144
11/05/2013, 12:09 PM
Didn't spell correctly, my bad.