Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Copyright (c) 2015-2016 SA-MP FilterScript
- *
- * This program is free software: you can redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with this program.
- * If not, see <http://www.gnu.org/licenses/>.
- */
- /*AUTHOR ***********************
- @Yaa - SA-MP Scripter
- ********************************/
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #include <sscanf2>
- #include <streamer>
- #define MySQL_Host ""
- #define MySQL_User ""
- #define MySQL_DB ""
- #define MySQL_Pass ""
- #define MySQL_Port 3306
- #define DIALOG_PHONE 2000
- #define DIALOG_RECHARGE 3000
- /* Config:
- ISP:
- id 1 = SAT
- id 2 = LVT
- id 3 = SFT
- */
- enum PlayerSIM
- {
- Activated,
- ISP,
- SAT,
- LVT,
- SFT,
- Value
- };
- static
- MySQL:register,
- PhoneInfo[MAX_PLAYERS][PlayerSIM],
- PlayerText:Net[1],
- CallStarted[MAX_PLAYERS],
- TimerPhone[MAX_PLAYERS],
- IsCalled[MAX_PLAYERS],
- Phone[5]
- ;
- forward onCallStarted(playerid, targetid);
- forward onCallCostTake(playerid);
- forward onCallFinished(playerid, reason);
- forward onMySQLCheck(playerid);
- #define G "{6EF83C}"
- #define R "{F81414}"
- #define W "{FFFFFF}"
- #define O "{FFAF00}"
- #define YE "{FFFF00}"
- #define GRI "{C0C0C0}"
- public OnFilterScriptInit()
- {
- print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
- print(" * Yassine Phone System * ");
- print(" * Loaded * ");
- print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
- Phone[0] = CreatePickup(1318, 2, -1727.5148, 1041.5735, 45.2109, -1);
- Phone[1] = CreatePickup(1318, 2, 2408.6062, 1987.6985, 10.8203, -1);
- Create3DTextLabel(""R"[Phones Dealer]", 0x008080FF, -1727.5148, 1041.5735, 45.2109, 40.0, 0, 0);
- Create3DTextLabel(""R"[Phones Dealer]", 0x008080FF, 2408.6062, 1987.6985, 10.8203, 40.0, 0, 0);
- Phone[2] = CreateActor(165, 2318.3064, -7.4166, 26.7496, 92.5721);
- Phone[3] = CreateDynamicCP(2316.6213, -7.2762, 26.7422, 1.50, -1, -1, -1, 40.0);
- Phone[4] = CreatePickup(1318, 2, 2305.5718, -16.1358, 26.7496, -1);
- new MySQLOpt:options = mysql_init_options();
- mysql_set_option(options, SERVER_PORT, MySQL_Port);
- mysql_log(ALL);
- register = mysql_connect(MySQL_Host, MySQL_User, MySQL_Pass, MySQL_DB, options);
- if(mysql_errno() != 0)
- {
- printf("[MySQL Connection]: The connection to Database `%s` has failed.", MySQL_DB);
- printf("[MySQL Notice]: Fail to Create `phone` table on database `%s`", MySQL_DB);
- }
- else
- {
- printf("[MySQL Connection]: The connection to Database `%s` was successful.", MySQL_DB);
- mysql_query(register, "CREATE TABLE IF NOT EXISTS `phone` (`Name` VARCHAR(64),`ISP` INT(129), `Value` INT(20))");
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
- print(" * Yassine Phone System * ");
- print(" * UnLoaded * ");
- print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
- DestroyPickup(Phone[0]);
- DestroyPickup(Phone[1]);
- DestroyActor(Phone[2]);
- mysql_close(register);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Net[0] = CreatePlayerTextDraw(playerid,69.000000, 317.000000, "SAT");
- PlayerTextDrawBackgroundColor(playerid,Net[0], 255);
- PlayerTextDrawFont(playerid,Net[0], 1);
- PlayerTextDrawLetterSize(playerid,Net[0], 0.500000, 1.000000);
- PlayerTextDrawColor(playerid,Net[0], -1);
- PlayerTextDrawSetOutline(playerid,Net[0], 0);
- PlayerTextDrawSetProportional(playerid,Net[0], 1);
- PlayerTextDrawSetShadow(playerid,Net[0], 1);
- PlayerTextDrawSetSelectable(playerid,Net[0], 0);
- new queryS[128];
- mysql_format(register, queryS, sizeof(queryS), "SELECT * FROM `phone` WHERE `Name` = '%s' LIMIT 1", GetName(playerid));
- mysql_tquery(register, queryS, "onMySQLCheck", "i", playerid);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(PhoneInfo[playerid][ISP] == 3)
- {
- PlayerTextDrawSetString(playerid, Net[0], "SFT");
- }
- if(PhoneInfo[playerid][ISP] == 2)
- {
- PlayerTextDrawSetString(playerid, Net[0], "LVT");
- }
- if(PhoneInfo[playerid][ISP] == 1)
- {
- PlayerTextDrawSetString(playerid, Net[0], "SAT");
- }
- PlayerTextDrawShow(playerid, Net[0]);
- if(PhoneInfo[playerid][Activated] == 0)
- {
- PlayerTextDrawHide(playerid, Net[0]);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(PhoneInfo[playerid][Activated] == 1)
- {
- new querylist[200];
- format(querylist, sizeof(querylist), "UPDATE `phone` SET `ISP` = '%d', `Value` = '%d'", PhoneInfo[playerid][ISP], PhoneInfo[playerid][Value]);
- mysql_query(register, querylist);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_PHONE)
- {
- switch(listitem)
- {
- case 0:
- {
- ShowPlayerDialog(playerid, DIALOG_RECHARGE, DIALOG_STYLE_INPUT, "Recharging your account", "Please enter a value below for recharge your account", "Buy", "Cancel");
- }
- case 1:
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE+1, DIALOG_STYLE_LIST, "SIM Cards", ""W"Las Venturas Telecom\nSan Fierro Telecom\n"R"[HOT!]"W"San Andreas Telecom", "Buy", "Cancel");
- }
- }
- }
- if(dialogid == DIALOG_RECHARGE)
- {
- if(response)
- {
- if(strval(inputtext) == 0) return SendClientMessage(playerid, -1, ""R"Error: You can't recharge 0 $ :/ ");
- if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, ""R"Error: you don't have all this money ");
- GivePlayerMoney(playerid, -strval(inputtext));
- PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] + strval(inputtext);
- SendClientMessage(playerid, -1, ""G"Success: You account recharged !");
- }
- }
- if(dialogid == DIALOG_PHONE+1)
- {
- switch(listitem)
- {
- case 0:
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE+2, DIALOG_STYLE_MSGBOX, "Las Venturas Telecom", "Welcome to LVT ! \nWe will give you the following functions: \n- Call Cost $ 70/sec\n- Cheap Price\n Price: $ 10\n Do you really want to buy from us a SIM Card?", "Buy", "Cancel");
- }
- case 1:
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE+3, DIALOG_STYLE_MSGBOX, "San Fierro Telecom", "Welcome to SFT ! \nWe will give you the following functions: \n- Call Cost $ 50/sec \n- Cheap Price\n Price: $ 1000 \n Do you really want to buy from us a SIM Card?", "Buy", "Cancel");
- }
- case 2:
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE+4, DIALOG_STYLE_MSGBOX, "San Andreas Telecom", "Welcome to SAT ! \nWe will give you the following functions: \n- Call Cost $ 10/sec\n- recharge $ 1000\n- Free first 50 seconds !\n Price: $ 10 000\n Do you really want to buy from us a SIM Card?", "Buy", "Cancel");
- }
- }
- }
- if(dialogid == DIALOG_PHONE+2)
- {
- if(response)
- {
- new str[200];
- if(GetPlayerMoney(playerid) < 10) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 10 in the hand !");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][LVT] = 1;
- PhoneInfo[playerid][ISP] = 2;
- PhoneInfo[playerid][Activated] = 1;
- SendClientMessage(playerid, -1, ""G"[LVT]: Now you are able to use /call !");
- format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 2, 100)", GetName(playerid));
- mysql_query(register, str);
- }
- }
- if(dialogid == DIALOG_PHONE+3)
- {
- if(response)
- {
- new str[200];
- if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 1000 in the hand !");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][SFT] = 1;
- PhoneInfo[playerid][ISP] = 3;
- PhoneInfo[playerid][Activated] = 1;
- SendClientMessage(playerid, -1, ""G"[SFT]: Now you are able to use /call !");
- format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 3, 100)", GetName(playerid));
- mysql_query(register, str);
- }
- }
- if(dialogid == DIALOG_PHONE+4)
- {
- if(response)
- {
- new str[200];
- if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 10000 in the hand !");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][SAT] = 1;
- PhoneInfo[playerid][ISP] = 1;
- PhoneInfo[playerid][Activated] = 1;
- PhoneInfo[playerid][Value] = 500;
- SendClientMessage(playerid, -1, ""G"[SAT]: Now you are able to use /call !");
- format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 1, 600)", GetName(playerid));
- mysql_query(register, str);
- PlayerTextDrawShow(playerid, Net[0]);
- }
- }
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if(CallStarted[playerid] == 1)
- {
- new str[100];
- format(str, sizeof(str), ""GRI"["G"Phone"GRI" %s]: "W"%s", GetName(playerid), text);
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, str);
- SendClientMessage(playerid, -1, str);
- return 0;
- }
- return 0;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- if(Phone[0] == pickupid || Phone[1] == pickupid)
- {
- SetPlayerPos(playerid, 2315.952880,-1.618174,26.742187);
- }
- if(Phone[4] == pickupid)
- {
- SetPlayerPos(playerid, 2412.8931, 1987.4094, 10.8203);
- }
- return 1;
- }
- public onMySQLCheck(playerid)
- {
- new rows;
- cache_get_row_count(rows);
- if(rows == 1)
- {
- cache_get_value_name_int(0, "ISP", PhoneInfo[playerid][ISP]);
- cache_get_value_name_int(0, "Value", PhoneInfo[playerid][Value]);
- PhoneInfo[playerid][Activated] = 1;
- if(PhoneInfo[playerid][ISP] == 1)
- {
- PhoneInfo[playerid][SAT] = 1;
- }
- if(PhoneInfo[playerid][ISP] == 2)
- {
- PhoneInfo[playerid][LVT] = 1;
- }
- if(PhoneInfo[playerid][ISP] == 3)
- {
- PhoneInfo[playerid][SFT] = 1;
- }
- }
- else
- {
- PhoneInfo[playerid][Activated] = 0;
- }
- return 1;
- }
- CMD:call(playerid, params[])
- {
- if(CallStarted[playerid] == 1)
- {
- onCallFinished(playerid, 0);
- }
- else
- {
- new id, str[150];
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
- if(sscanf(params, "u", id)) return SendClientMessage(playerid, -1, ""R"Usage: /call [playerid]");
- if(playerid == id) return SendClientMessage(playerid, -1, ""R"You can't call youself, Silly !");
- if(PhoneInfo[id][Activated] == 0)
- {
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Started...");
- format(str, sizeof(str), ""GRI"["G"%s"GRI"]: "W"Sorry, this player number not exists or not activated", PhoneInfo[playerid][ISP]);
- SendClientMessage(playerid, -1 ,str);
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- return 1;
- }
- else
- {
- new isp[20];
- if(PhoneInfo[playerid][ISP] == 1) isp = "SAT";
- if(PhoneInfo[playerid][ISP] == 2) isp = "LVT";
- if(PhoneInfo[playerid][ISP] == 3) isp = "SFT";
- SetPVarInt(playerid, "CalledPlayer", id);
- SetPVarInt(id, "CalledPlayer", playerid);
- IsCalled[id] = 1;
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Start Calling...");
- SendClientMessage(id, -1, ""GRI"["G"Phone"GRI"]: "W"New Call");
- format(str, sizeof(str), ""GRI"["G"%s"GRI"]: "W"You have a new call from %s use "GRI"/answer "W"to accept call else use "GRI"/decline", isp, GetName(playerid));
- SendClientMessage(id, -1 ,str);
- }
- }
- return 1;
- }
- CMD:answer(playerid, params[])
- {
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
- if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, ""R"Error: you have no new calls !");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Connection Success ! Start speak !");
- onCallStarted(playerid, GetPVarInt(playerid, "CalledPlayer"));
- return 1;
- }
- CMD:decline(playerid, params[])
- {
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
- if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, ""R"Error: you have no new calls !");
- IsCalled[playerid] = 0;
- onCallFinished(playerid, 2);
- return 1;
- }
- CMD:phone(playerid, params[])
- {
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
- new str[120];
- format(str, sizeof(str), ""GRI"["G"Phone"GRI"]: "W"You are using ISP Id:%d ", PhoneInfo[playerid][ISP]);
- SendClientMessage(playerid, -1, str);
- SendClientMessage(playerid, -1, "ISP Ids: SAT -> 1, LVT -> 2, SFT -> 3");
- format(str, sizeof(str), ""GRI"["G"Phone"GRI"]: "W"You have $ %d in your account", PhoneInfo[playerid][Value]);
- SendClientMessage(playerid, -1, str);
- return 1;
- }
- public onCallStarted(playerid, targetid)
- {
- SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
- SetPlayerSpecialAction(targetid, SPECIAL_ACTION_USECELLPHONE);
- SetPVarInt(playerid, "CalledPlayer", targetid);
- SetPVarInt(targetid, "CalledPlayer", playerid);
- CallStarted[playerid] = 1;
- CallStarted[targetid] = 1;
- TimerPhone[playerid] = SetTimerEx("onCallCostTake", 1000, true, "i", playerid);
- TimerPhone[targetid] = SetTimerEx("onCallCostTake", 1000, true, "i", targetid);
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Started...");
- return 1;
- }
- public onCallFinished(playerid, reason)
- {
- if(reason == 1)
- {
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"You have no more money to pay the phone calls !");
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Lost Connection.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
- CallStarted[playerid] = 0;
- KillTimer(TimerPhone[playerid]);
- KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
- SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
- SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
- return 1;
- }
- if(reason == 2)
- {
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"this number busy at moment.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
- CallStarted[playerid] = 0;
- KillTimer(TimerPhone[playerid]);
- KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
- SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
- SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- CallStarted[playerid] = 0;
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
- CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
- KillTimer(TimerPhone[playerid]);
- KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
- SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
- SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
- }
- return 1;
- }
- public onCallCostTake(playerid)
- {
- if(PhoneInfo[playerid][Value] == 0) return onCallFinished(playerid, 1);
- if(PhoneInfo[playerid][SFT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 50;
- if(PhoneInfo[playerid][LVT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 70;
- if(PhoneInfo[playerid][SAT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 10;
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid, checkpointid)
- {
- if(checkpointid == Phone[3])
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE, DIALOG_STYLE_LIST, "Phone Dealer", ""W"Recharging my account\nBuy a SIM Card", "Buy", "Cancel");
- }
- return 1;
- }
- stock GetName(playerid)
- {
- new szName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, szName, sizeof(szName));
- return szName;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement