Angol Samp Fórumról:(Szerintem ez alapján megtudod csinálni.)
[pawn]#include <a_samp>
#define Save 1
forward check(playerid);
forward stopphone(playerid);
forward startphone(playerid);
#define txtcost 1
enum player_enum
{
bool:calling,
caller,
number
}
new player[MAX_PLAYERS][player_enum];
public OnFilterScriptInit()
{
print(\"\\n--------------------------------------\");
print(\" cellphone system ready \");
print(\"______________________________________\");
print(\"by NoZer0 a.k.a Daplayer (2009) \");
print(\"--------------------------------------\\n\");
return 1;
}
public OnPlayerConnect(playerid)
{
SendClientMessage(playerid, 0x33AA33AA, \"This server is using NoZer0\'s phone system (2009)\");
player[playerid][calling] = false;
player[playerid][caller] = 255;
GivePlayerMoney(playerid, 500);
#if Save==0
do
{
player[playerid][number] = 1000 + random(8999);
}
while(NumberUsed(playerid));
#else
new file[20];
GetPlayerName(playerid, file, 16);
format(file, sizeof(file), \"%s.txt\", file);
if (fexist(file))
{
new File:ftw = fopen(file, io_read);
new tmp[5];
fread(ftw, tmp);
player[playerid][number] = strval(tmp);
fclose(ftw);
}
else
{
do
{
player[playerid][number] = 1000 + random(8999);
}
while(NumberUsed(playerid));
new File:handle1 = fopen(file, io_write);
new tmp[6];
format(tmp, 5, \"%d\", player[playerid][number]);
fwrite(handle1, tmp);
fclose(handle1);
new File:handle2;
if (!fexist(\"numbers_used.txt\"))
{
format(tmp, 7, \"%d\", player[playerid][number]);
handle2 = fopen(\"numbers_used.txt\", io_write);
fwrite(handle2, tmp);
fclose(handle2);
}
else
{
format(tmp, 7, \"\\r\\n%d\", player[playerid][number]);
handle2 = fopen(\"numbers_used.txt\", io_append);
fwrite(handle2, tmp);
fclose(handle2);
}
}
#endif
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if (player[playerid][calling])
{
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, \"(Cellphone) User hang up\");
player[playerid][calling] = false;
player[player[playerid][caller]][calling] = false;
stopphone(playerid);
stopphone(player[playerid][caller]);
player[player[playerid][caller]][caller] = 255;
player[playerid][caller] = 255;
}
else if (player[playerid][caller] != 255)
{
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, \"(Cellphone) User hang up\");
stopphone(playerid);
stopphone(player[playerid][caller]);
player[player[playerid][caller]][caller] = 255;
player[playerid][caller] = 255;
}
player[playerid][caller] = 255;
player[playerid][calling] = false;
}
public OnPlayerText(playerid, text[])
{
if (!player[playerid][calling] || player[playerid][caller] == 255)
{
new string[128];
format(string, 255, \"(%d) %s\", player[playerid][number], text);
SendPlayerMessageToAll(playerid, string);
}
else
{
new str[158];
GetPlayerName(playerid, str, 16);
format(str, sizeof(str), \"(Cellphone)%s : %s\", str, text);
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, str);
SendClientMessage(playerid, 0xBFC0C2FF, str);
}
return 0;
}
public OnPlayerPrivmsg(playerid, recieverid, text[])
{
new rname[MAX_PLAYER_NAME];
new target = recieverid;
GetPlayerName(target, rname, sizeof(rname));
new string[255];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
format(string, 255, \"*** pm send to %s\", rname);
SendClientMessage(playerid, 0xBFC0C2FF, string);
format(string, 255, \"*** pm from %s: %s (%d)\", name, text, player[playerid][number]);
SendClientMessage(target, 0xBFC0C2FF, string);
return 0;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[128];
new idx = 0;
cmd = strtok(cmdtext, idx);
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/pickup\", true) == 0)
{
if (player[playerid][caller] == 255)
{
SendClientMessage(playerid, 0xBFC0C2FF, \"Why should you pickup your phone?\");
return 1;
}
if (player[playerid][calling])
{
SendClientMessage(playerid, 0xBFC0C2FF, \"You already got your phone in your hands\");
return 1;
}
new name[16];
GetPlayerName(playerid, name, 16);
new string[41];
format(string, sizeof(string), \"* %s takes out a cellphone.\", name);
SendClientMessageToAll(0x0000FF66, string);
startphone(playerid);
player[playerid][calling] = true;
player[player[playerid][caller]][calling] = true;
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, \"You hear a tone on the other side\");
return 1;
}
if(strcmp(cmd, \"/hangup\", true) == 0)
{
if (player[playerid][caller] != 255 && !player[playerid][calling])
{
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, \"(Cellphone) User hang up\");
stopphone(playerid);
stopphone(player[playerid][caller]);
player[player[playerid][caller]][caller] = 255;
player[playerid][caller] = 255;
return 1;
}
if (!player[playerid][calling])
{
SendClientMessage(playerid, 0xBFC0C2FF, \"You don\'t have a phone in your hands\");
return 1;
}
new name[16];
GetPlayerName(playerid, name, 16);
new string[57];
format(string, sizeof(string), \"* %s puts his cellphone back in his pocket.\", name);
SendClientMessageToAll(0x0000FF66, string);
SendClientMessage(player[playerid][caller], 0xBFC0C2FF, \"(Cellphone) User hang up\");
player[playerid][calling] = false;
player[player[playerid][caller]][calling] = false;
stopphone(playerid);
stopphone(player[playerid][caller]);
player[player[playerid][caller]][caller] = 255;
player[playerid][caller] = 255;
SendClientMessage(playerid, 0xBFC0C2FF, \"(Cellphone) You hang up\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/call\", true) == 0)
{
if (player[playerid][calling] || player[playerid][caller] != 255)
{
SendClientMessage(playerid, 0xBFC0C2FF, \"You are already on the phone. use /hangup to hangup\");
return 1;
}
new tmp[128];
tmp = strtok(cmdtext, idx);
if (!strlen(tmp))
{
SendClientMessage(playerid, 0xBFC0C2FF, \"USAGE: /call <phonenumber>\");
return 1;
}
new name[16];
GetPlayerName(playerid, name, 16);
new string[41];
format(string, sizeof(string), \"* %s takes out a cellphone.\", name);
SendClientMessageToAll(0x0000FF66, string);
new phonenumb = strval(tmp);
////////////////////////////////////////////////////////////////////////////////
if (phonenumb == 888) // here you can put your own numbers just copy for more
{
SendClientMessage(playerid, 0xFFFFFFAA, \"you called 888\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(player
[number] == phonenumb && phonenumb != 0 && !player[calling] && player[caller] == 255 && i != playerid)
{
format(string, sizeof(string), \"%s is calling you...\", name);
SendClientMessage(i, 0xFFFF00AA, string);
SendClientMessage(i, 0xFFFFFFFF, \"Tip: Use /pickup to pick up the phone\");
GetPlayerName(i, name, sizeof(name));
format(string, sizeof(string), \"You are calling %s...\", name);
SendClientMessage(playerid, 0xFFFFFFAA, string);
SendClientMessage(i, 0xFFFFFFFF, \"Tip: You can cancel the callaing, by using /hangup\");
startphone(playerid);
player[playerid][calling] = false;
player[playerid][caller] = i;
player[calling] = false;
player[caller] = playerid;
return 1;
}
}
}
SendClientMessage(playerid, 0xBFC0C2FF, \"You here a busy tone.\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/SMS\", true) == 0)
{
if (player[playerid][calling] || player[playerid][caller] != 255)
{
SendClientMessage(playerid, 0xBFC0C2FF, \"You are already on the phone. use /hangup to hangup\");
return 1;
}
new tmp[128];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, 0xBFC0C2FF, \"USAGE: /SMS <phonenumber> <text chat>\");
return 1;
}
new name[16];
GetPlayerName(playerid, name, 16);
new string[52];
format(string, sizeof(string), \"* %s takes out a cellphone.\", name);
SendClientMessageToAll(0x0000FF66, string);
new phonenumb = strval(tmp);
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= \' \'))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, 0xBFC0C2FF, \"USAGE: /SMS <phonenumber> <text chat>\");
return 1;
}
startphone(playerid);
SetTimerEx(\"stopphone\", 5000, 0, \"%d\", playerid);
////////////////////////////////////////////////////////////////////////////////
if(phonenumb == 666) // here you can put your own numbers just copy for more
{
SendClientMessage(playerid, 0xFFFFFFAA, \"you called 666\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
for(new i = 0; i <= MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(player[number] == phonenumb && phonenumb != 0 && !player[calling] && player[caller] == 255 && i != playerid)
{
if(GetPlayerMoney(playerid) >= txtcost)
{
format(string, sizeof(string), \"SMS: %s From %s (%d)\", result,name,player[playerid][number]);
SendClientMessage(playerid, 0xFFFFFFAA, \"Text Message Delivered\");
SendClientMessage(i, 0xFFFF00AA, string);
format(string, sizeof(string), \"~r~$-%d\", txtcost);
GameTextForPlayer(playerid, string, 5000, 1);
GivePlayerMoney(playerid,-txtcost);
PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
return 1;
}
else
{
format(string, 255, \"you dont have enough money to SMS, a SMS costs $%d\", txtcost);
SendClientMessage(playerid, 0xFFFF00AA, string);
return 1;
}
}
}
}
SendClientMessage(playerid, 0xBFC0C2FF, \" ..Message Delivery Failed\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/pb\", true) == 0 || strcmp(cmd, \"/phonebook\", true) == 0)
{
new string[23];
SendClientMessage(playerid, 0xC0C0C0FF, \"|_ Phone Book _|\");
for(new p = 0; p <= MAX_PLAYERS; p++)
{
if (IsPlayerConnected(p) && player[p][number] != 0)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(p, name, sizeof(name));
format(string, 255, \"%s : %d\", name, player[p][number]);
SendClientMessage(playerid, 0x33AA33AA, string);
}
}
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/mpn\", true) == 0 || strcmp(cmd, \"/myphonenumber\", true) == 0)
{
new string[37];
SendClientMessage(playerid, 0xC0C0C0FF, \"|_ Cell Phone System _|\");
format(string, 255, \"Your personal phonenumber is > %d <\", player[playerid][number]);
SendClientMessage(playerid, 0x33AA33AA, string);
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/ph\", true) == 0 || strcmp(cmd, \"/phonehelp\", true) == 0)
{
new string[56];
SendClientMessage(playerid, 0xC0C0C0FF, \"|_ Cell Phone System _|\");
SendClientMessage(playerid, 0xBFC0C2FF, \"Use /call to call to an specicified number.\");
SendClientMessage(playerid, 0x33AA33AA, \"Use /pickup to get your cellphone out of your pocket\");
SendClientMessage(playerid, 0xBFC0C2FF, \"Use /hangup to put your cellphone back in your pocket\");
format(string, 255, \"Use /SMS to sms your friend in private, a SMS cost $%d\", txtcost);
SendClientMessage(playerid, 0x33AA33AA, string);
SendClientMessage(playerid, 0xBFC0C2FF, \"Use /pb or /phonebook to see the phonenumbers of the online players\");
SendClientMessage(playerid, 0x33AA33AA, \"Use /mpn or /myphonenumber to see your own phonenumber\");
SendClientMessage(playerid, 0xBFC0C2FF, \"Use /pc or /phonecredits to see the credits\");
return 1;
}
////////////////////////////////////////////////////////////////////////////////
if(strcmp(cmd, \"/pc\", true) == 0 || strcmp(cmd, \"/phonecredits\", true) == 0)
{
SendClientMessage(playerid, 0xC0C0C0FF, \"|_ Cell Phone System _|\");
SendClientMessage(playerid, 0x33AA33AA, \"All credits of this phone system go\'s to NoZer0 a.k.a Daplayer\");
return 1;
}
return 0;
}
stock strtok(const string[], &index,seperator=\' \')
{
new length = strlen(string);
new offset = index;
new result[128];
while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
if ((index < length) && (string[index] == seperator))
{
index++;
}
return result;
}
public stopphone(playerid)
{
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_STOPUSECELLPHONE);
return 1;
}
public startphone(playerid)
{
SetPlayerSpecialAction(playerid,SPECIAL_ACTION_USECELLPHONE);
return 1;
}
stock NumberUsed(playerid)
{
for(new i=0; i<MAX_PLAYERS; i++)
if (player[number] == player[playerid][number] && i != playerid) return 1;
#if Save==1
if (fexist(\"numbers_used.txt\"))
{
new File:ftw = fopen(\"numbers_used.txt\", io_read);
new tmp[7];
while(fread(ftw, tmp))
{
printf(\"[%d]\", strval(tmp));
if (strval(tmp) == player[playerid][number]) return 1;
}
fclose(ftw);
}
#endif
return 0;
}[/pawn]
Filterscript