21.12.2011, 12:24
I'm trying to create a cellphone system and I have working /call, /hangup and /pickup commands but when I call a number it doesn't reach to the other player or 911. This is how it looks like so far:
pawn Код:
public OnPlayerText(playerid, text[])
{
new sendername[MAX_PLAYER_NAME];
new tmp[256];
new string[256];
if(realchat)
{
if(gPlayerLogged[playerid] == 0)
{
return 0;
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s says: %s", sendername, text);
ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
return 0;
}
if(Mobile[playerid] != 255)
{
new idx;
tmp = strtok(text, idx);
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s says (Cellphone): %s", sendername, text);
ProxDetector(20.0, playerid, string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
if(Mobile[playerid] == 911)
{
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "Operator (Cellphone): Sorry, I dont understand, police or paramedic?");
return 0;
}
else if ((strcmp("police", tmp, true, strlen(tmp)) == 0) && (strlen(tmp) == strlen("police")))
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Operator (Cellphone): Please hold, I will connect you to the Police Department.");
Mobile[playerid] = 912;
SendClientMessage(playerid, COLOR_DEPTBLUE, "Dispatch (Cellphone): This is the Police Department, please give me a short description of the Incident.");
return 0;
}
else if ((strcmp("paramedic", tmp, true, strlen(tmp)) == 0) && (strlen(tmp) == strlen("paramedic")))
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Operator (Cellphone): Please hold, I will connect you to the Fire Department.");
Mobile[playerid] = 914;
SendClientMessage(playerid, COLOR_LIGHTRED, "Dispatch (Cellphone): THis is the Fire Department, please give me a short description of the Incident.");
return 0;
}
else
{
SendClientMessage(playerid, COLOR_WHITE, "Operator (Cellphone): Sorry, I dont understand, police or paramedic?");
return 0;
}
}
return 0;
}
return 0;
}
pawn Код:
if(strcmp(cmd, "/call", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " You are not logged in yet.");
return 1;
}
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " USAGE: /call [number]");
return 1;
}
if(PlayerInfo[playerid][pPhone] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " You dont have a cellphone.");
return 1;
}
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s takes out a cellphone.", sendername);
ProxDetector(30.0, playerid, string,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
new number = strval(tmp);
if(number == 911)
{
SendClientMessage(playerid, COLOR_WHITE, "You can now use T to talk on your cellphone, type /hangup to hang up.");
SendClientMessage(playerid, COLOR_LIGHTRED, "Operator (Cellphone): Hello, which service do you require, Police or Paramedic?");
Mobile[playerid] = 911;
return 1;
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(PlayerInfo[i][pNumber] == number && number != 0)
{
giveplayerid = i;
Mobile[playerid] = giveplayerid;
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
if(Mobile[giveplayerid] == 255)
{
format(string, sizeof(string), "Your cellphone is ringing, type (/pickup).");
SendClientMessage(giveplayerid, COLOR_DARKYELLOW, string);
GetPlayerName(giveplayerid, sendername, sizeof(sendername));
SendClientMessage(playerid, COLOR_WHITE, "You can now use T to talk on your cellphone, type /hangup to hang up.");
format(string, sizeof(string), "* %s's phone begins to ring.", sendername);
ProxDetector(30.0, i, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
CellTime[playerid] = 1;
return 1;
}
}
}
}
}
}
SendClientMessage(playerid, COLOR_LIGHTGREY, " You just get a busy tone.");
}
return 1;
}
if(strcmp(cmd, "/pickup", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " You are not logged in yet.");
return 1;
}
if(Mobile[playerid] != 255)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " You are already on a call.");
return 1;
}
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(Mobile[i] == playerid)
{
Mobile[playerid] = i;
SendClientMessage(i, COLOR_WHITE, " They picked up the call.");
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s answers his cellphone.", sendername);
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
}
}
}
}
return 1;
}
if(strcmp(cmd, "/hangup", true) == 0 || strcmp(cmd, "/h", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(gPlayerLogged[playerid] == 0)
{
SendClientMessage(playerid, COLOR_LIGHTGREY, " You are not logged in yet.");
return 1;
}
new caller = Mobile[playerid];
if(IsPlayerConnected(caller))
{
if(caller != INVALID_PLAYER_ID)
{
if(caller != 255)
{
if(caller < 255)
{
SendClientMessage(caller, COLOR_LIGHTGREY, " They hung up.");
CellTime[caller] = 0;
CellTime[playerid] = 0;
SendClientMessage(playerid, COLOR_LIGHTGREY, " You hung up.");
Mobile[caller] = 255;
}
Mobile[playerid] = 255;
CellTime[playerid] = 0;
}
}
}
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
}
return 1;
}