PDA

View Full Version : Phone system.


Shetch
11/04/2012, 02:47 AM
Can you guys tell me how to make a '/call' phone system?
I want it so each player has their own phone number and so it doesn't mix up with anyone else number.
And how would i generate the number?

Snipa
11/04/2012, 02:48 AM
http://forum.sa-mp.com/showthread.php?t=265167
That uses player names afaik.

Shetch
11/04/2012, 02:53 AM
http://forum.sa-mp.com/showthread.php?t=265167
That uses player names afaik.

He uses player's ID instead of an actual phone number.

antonio112
11/04/2012, 03:19 AM
Well, are you actually requesting a whole script or just guidance in what you have to do and how you have to do it? If you're asking for the whole script, you should post here:

http://forum.sa-mp.com/showthread.php?t=187229&page=207


Else, I can give you a short hint in what you have to do.

Well, first thing, is to set players phonenumber. You'll need a global variable for each player, so we'll start with that:

// Somewhere on top of your script
new PhoneNumber[MAX_PLAYERS]; // Notice that it is an array, since we'll be using different numbers for each player

public OnPlayerConnect(playerid)
{
PhoneNumber[playerid] = 0;
SetPVarInt(playerid, "CalledBy", -1); // We set these 2 player variables to -1. You'll understand why later
SetPVarInt(playerid, "OnCallWith", -1);

// Now, let's say we make a command that'll give a player a random phone number:
CMD:buyphone(playerid, params[])
{
if(PhoneNumber[playerid] > 0)
return SendClientMessage(playerid, -1, "You already own a phone number.");

new number = 1000000 + random(99999); // This will generate a random phone number between 100000 and 999999. There's practically none chance to get the same phone number twice.
new str[128];
PhoneNumber[playerid] = number;
format(str, sizeof str, "You bought yourself a new phone. Number: %i", PhoneNumber[playerid]);
SendClientMessage(playerid, -1, str);
return 1;
}

// And now, about calling and answering, here's the tricky part. Let's do the call command. I assume you use ZCMD + foreach + sscanf
CMD:call(playerid, params[])
{
if(PhoneNumber[playerid] == 0)
return SendClientMessage(playerid, -1, "You don't have a cellphone. Buy one first before calling.");

if(GetPVarInt(playerid, "OnCallWith") == -1)
return SendClientMessage(playerid, -1, "You're already on a call with somebody.");

new pNumber;
if(sscanf(params, "i", pNumber))
return SendClientMessage(playerid, -1, "Usage: /call [Phone Number]");
foreach (Player, i)
{
if(PhoneNumber[i] == pNumber)
{
new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(i, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s is calling you. Type /pickup to answer.", pName);
SendClientMessage(i, -1, str);
format(str, sizeof str, "You're calling %s.", tName);
SendClientMessage(playerid, -1, str);
SetPVarInt(i, "CalledBy", playerid); // We set player variables, so later when the target types /pickup, we'll know who he has to answer to and who he'll talk to.
return 1;
}
}
SendClientMessage(playerid , -1, "The number you tried to reach does not exist.");
return 1;
}

// Now, we move on /pickup command

CMD:pickup(playerid, params[]);
{
#pragma unused params
if(GetPVarInt(playerid, "CalledBy") == -1)
return SendClientMessage(playerid, -1, "Noone's calling you.");

new pID = GetPVarInt(playerid, "CalledBy");
new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(pID, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s answered your call. You can now talk to him.", pName);
SendClientMessage(pID, -1, str);
format(str, sizeof str, "You answered %s call. You can talk to him now.", tName);
SendClientMessage(playerid, -1, str);
SetPVarInt(playerid, "OnCallWith", pID);
SetPVarInt(pID, "OnCallWith", playerid);
return 1;
}
CMD:hangup(playerid, params[])
{
if(GetPVarInt(playerid, "CalledBy") == -1)
return SendClientMessage(playerid, -1, "Noone's calling you.");

new pID = GetPVarInt(playerid, "CalledBy");
SetPVarInt(playerid, "CalledBy", -1);
SetPVarInt(playerid, "OnCallWith", -1);
SetPVarInt(pID, "OnCallWith", -1);
SendClientMessage(playerid, -1, "You hung up.");
SendClientMessage(pID, -1, "The other person hung up.");
return 1;
}

// Now, how about when two guys are on the phone?
public OnPlayerText(playerid, text[])
{
new str[128];
if(GetPVarInt(playerid, "OnCallWith") != -1)
{
new tName[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
new pID = GetPVarInt(playerid, "OnCallWith");
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(pID, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s cell: %s", pName, text);
SendClientMessage(pID, -1, str);
SendClientMessage(playerid, -1, str);
}
return 1;
}


Now, this is about all ... Of course, it's not a complete phone system, just an 'example' on how you should do it. I made it on forum, so don't expect it to be working 100%. If you have any other problems / questions, post here.

SFRPVN
06/03/2014, 12:31 PM
Well, are you actually requesting a whole script or just guidance in what you have to do and how you have to do it? If you're asking for the whole script, you should post here:

http://forum.sa-mp.com/showthread.php?t=187229&page=207


Else, I can give you a short hint in what you have to do.

Well, first thing, is to set players phonenumber. You'll need a global variable for each player, so we'll start with that:

// Somewhere on top of your script
new PhoneNumber[MAX_PLAYERS]; // Notice that it is an array, since we'll be using different numbers for each player

public OnPlayerConnect(playerid)
{
PhoneNumber[playerid] = 0;
SetPVarInt(playerid, "CalledBy", -1); // We set these 2 player variables to -1. You'll understand why later
SetPVarInt(playerid, "OnCallWith", -1);

// Now, let's say we make a command that'll give a player a random phone number:
CMD:buyphone(playerid, params[])
{
if(PhoneNumber[playerid] > 0)
return SendClientMessage(playerid, -1, "You already own a phone number.");

new number = 1000000 + random(99999); // This will generate a random phone number between 100000 and 999999. There's practically none chance to get the same phone number twice.
new str[128];
PhoneNumber[playerid] = number;
format(str, sizeof str, "You bought yourself a new phone. Number: %i", PhoneNumber[playerid]);
SendClientMessage(playerid, -1, str);
return 1;
}

// And now, about calling and answering, here's the tricky part. Let's do the call command. I assume you use ZCMD + foreach + sscanf
CMD:call(playerid, params[])
{
if(PhoneNumber[playerid] == 0)
return SendClientMessage(playerid, -1, "You don't have a cellphone. Buy one first before calling.");

if(GetPVarInt(playerid, "OnCallWith") == -1)
return SendClientMessage(playerid, -1, "You're already on a call with somebody.");

new pNumber;
if(sscanf(params, "i", pNumber))
return SendClientMessage(playerid, -1, "Usage: /call [Phone Number]");
foreach (Player, i)
{
if(PhoneNumber[i] == pNumber)
{
new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(i, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s is calling you. Type /pickup to answer.", pName);
SendClientMessage(i, -1, str);
format(str, sizeof str, "You're calling %s.", tName);
SendClientMessage(playerid, -1, str);
SetPVarInt(i, "CalledBy", playerid); // We set player variables, so later when the target types /pickup, we'll know who he has to answer to and who he'll talk to.
return 1;
}
}
SendClientMessage(playerid , -1, "The number you tried to reach does not exist.");
return 1;
}

// Now, we move on /pickup command

CMD:pickup(playerid, params[]);
{
#pragma unused params
if(GetPVarInt(playerid, "CalledBy") == -1)
return SendClientMessage(playerid, -1, "Noone's calling you.");

new pID = GetPVarInt(playerid, "CalledBy");
new pName[MAX_PLAYER_NAME], tName[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(pID, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s answered your call. You can now talk to him.", pName);
SendClientMessage(pID, -1, str);
format(str, sizeof str, "You answered %s call. You can talk to him now.", tName);
SendClientMessage(playerid, -1, str);
SetPVarInt(playerid, "OnCallWith", pID);
SetPVarInt(pID, "OnCallWith", playerid);
return 1;
}
CMD:hangup(playerid, params[])
{
if(GetPVarInt(playerid, "CalledBy") == -1)
return SendClientMessage(playerid, -1, "Noone's calling you.");

new pID = GetPVarInt(playerid, "CalledBy");
SetPVarInt(playerid, "CalledBy", -1);
SetPVarInt(playerid, "OnCallWith", -1);
SetPVarInt(pID, "OnCallWith", -1);
SendClientMessage(playerid, -1, "You hung up.");
SendClientMessage(pID, -1, "The other person hung up.");
return 1;
}

// Now, how about when two guys are on the phone?
public OnPlayerText(playerid, text[])
{
new str[128];
if(GetPVarInt(playerid, "OnCallWith") != -1)
{
new tName[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
new pID = GetPVarInt(playerid, "OnCallWith");
GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
GetPlayerName(pID, tName, MAX_PLAYER_NAME);
format(str, sizeof str, "%s cell: %s", pName, text);
SendClientMessage(pID, -1, str);
SendClientMessage(playerid, -1, str);
}
return 1;
}


Now, this is about all ... Of course, it's not a complete phone system, just an 'example' on how you should do it. I made it on forum, so don't expect it to be working 100%. If you have any other problems / questions, post here.

I can't Compiler
Window PAWN Compiler Output is Nothing