Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************
- * Includes *
- *****************************/
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #include <sscanf2>
- #include <streamer>
- /****************************
- * Define *
- *****************************/
- #define MySQL_Host ""
- #define MySQL_User ""
- #define MySQL_DB ""
- #define MySQL_Pass ""
- #define MySQL_Port 3306
- #define COLOR_GREEN "{6EF83C}"
- #define COLOR_RED "{F81414}"
- #define COLOR_WHITE "{FFFFFF}"
- #define COLOR_ORANGE "{FFAF00}"
- #define COLOR_YE "{FFFF00}"
- #define COLOR_GRI "{C0C0C0}"
- #define DIALOG_PHONE 2000
- #define DIALOG_RECHARGE 3000
- #define ISP_SAT 1
- #define ISP_LVT 2
- #define ISP_SFT 3
- /****************************
- * Forwards *
- *****************************/
- forward onCallStarted(playerid, targetid);
- forward onCallCostTake(playerid);
- forward onCallFinished(playerid, reason);
- forward onMySQLCheck(playerid);
- enum PlayerSIM
- {
- Activated,
- ISP,
- Value
- };
- new PhoneInfo[MAX_PLAYERS][PlayerSIM];
- new PlayerText:Net[MAX_PLAYERS];
- new playerName[MAX_PLAYERS][MAX_PLAYER_NAME];
- static
- MySQL:sqlHandle,
- CallStarted[MAX_PLAYERS],
- TimerPhone[MAX_PLAYERS],
- IsCalled[MAX_PLAYERS],
- Phone[5]
- ;
- 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(COLOR_RED # "[Phones Dealer]", 0x008080FF, -1727.5148, 1041.5735, 45.2109, 40.0, 0, 0);
- Create3DTextLabel(COLOR_RED # "[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);
- sqlHandle = 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(sqlHandle, "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(sqlHandle);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid, playerName[playerid], MAX_PLAYER_NAME);
- Net[playerid] = CreatePlayerTextDraw(playerid,69.000000, 317.000000, "_");
- PlayerTextDrawBackgroundColor(playerid,Net[playerid], 255);
- PlayerTextDrawFont(playerid,Net[playerid], 1);
- PlayerTextDrawLetterSize(playerid,Net[playerid], 0.500000, 1.000000);
- PlayerTextDrawColor(playerid,Net[playerid], -1);
- PlayerTextDrawSetOutline(playerid,Net[playerid], 0);
- PlayerTextDrawSetProportional(playerid,Net[playerid], 1);
- PlayerTextDrawSetShadow(playerid,Net[playerid], 1);
- PlayerTextDrawSetSelectable(playerid,Net[playerid], 0);
- new queryS[80];
- mysql_format(sqlHandle, queryS, sizeof(queryS), "SELECT * FROM `phone` WHERE `Name` = '%s' LIMIT 1", playerName[playerid]);
- mysql_tquery(sqlHandle, queryS, "onMySQLCheck", "i", playerid);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- switch(PhoneInfo[playerid][ISP])
- {
- case 1:
- {
- PlayerTextDrawSetString(playerid, Net[playerid], "SAT");
- }
- case 2:
- {
- PlayerTextDrawSetString(playerid, Net[playerid], "LVT");
- }
- case 3:
- {
- PlayerTextDrawSetString(playerid, Net[playerid], "SFT");
- }
- }
- if(PhoneInfo[playerid][Activated] == 1)
- {
- PlayerTextDrawShow(playerid, Net[playerid]);
- }
- else
- {
- PlayerTextDrawHide(playerid, Net[playerid]);
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(PhoneInfo[playerid][Activated] == 1)
- {
- new query[80];
- format(query, sizeof(query), "UPDATE `phone` SET `ISP` = '%d', `Value` = '%d'", PhoneInfo[playerid][ISP], PhoneInfo[playerid][Value]);
- mysql_query(sqlHandle, query);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(response)
- {
- switch(dialogid)
- {
- case 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", COLOR_WHITE # "Las Venturas Telecom\nSan Fierro Telecom\n" # COLOR_RED "[HOT!]" # COLOR_WHITE "San Andreas Telecom", "Buy", "Cancel");
- }
- }
- }
- case DIALOG_RECHARGE:
- {
- if(strval(inputtext) == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: You can't recharge 0 $ :/ ");
- if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, COLOR_RED # "Error: you don't have all this money ");
- //TODO(MSC) Check if input is valid
- GivePlayerMoney(playerid, -strval(inputtext));
- PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] + strval(inputtext);
- SendClientMessage(playerid, -1, COLOR_GREEN # "Success: You account recharged!");
- }
- case 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");
- }
- }
- }
- case DIALOG_PHONE + 2:
- {
- if(GetPlayerMoney(playerid) < 10) return SendClientMessage(playerid, -1, COLOR_RED # "Error: you dont have $ 10 in the hand!");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][ISP] = 2;
- PhoneInfo[playerid][Activated] = 1;
- SendClientMessage(playerid, -1, COLOR_GREEN # "[LVT]: Now you are able to use /call!");
- new query[92];
- format(query, sizeof(query), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 2, 100)", playerName[playerid]);
- mysql_query(sqlHandle, query);
- }
- case DIALOG_PHONE + 3:
- {
- new str[200];
- if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, -1, COLOR_RED # "Error: you dont have $ 1000 in the hand!");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][ISP] = 3;
- PhoneInfo[playerid][Activated] = 1;
- SendClientMessage(playerid, -1, COLOR_GREEN # "[SFT]: Now you are able to use /call!");
- format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 3, 100)", playerName[playerid]);
- mysql_query(sqlHandle, str);
- }
- case DIALOG_PHONE + 4:
- {
- if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, -1, COLOR_RED # "Error: you dont have $ 10000 in the hand!");
- GivePlayerMoney(playerid, -100);
- PhoneInfo[playerid][ISP] = 1;
- PhoneInfo[playerid][Activated] = 1;
- PhoneInfo[playerid][Value] = 500;
- SendClientMessage(playerid, -1, COLOR_GREEN # "[SAT]: Now you are able to use /call!");
- new query[92];
- format(query, sizeof(query), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 1, 600)", playerName[playerid]);
- mysql_tquery(sqlHandle, query);
- PlayerTextDrawShow(playerid, Net[playerid]);
- }
- }
- }
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- if(CallStarted[playerid] == 1)
- {
- new str[144];
- format(str, sizeof(str), COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI " %s]: " # COLOR_WHITE "%s", playerName[playerid], text);
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, str);
- SendClientMessage(playerid, -1, str);
- return 0;
- }
- return 1;
- }
- 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;
- }
- else
- {
- PhoneInfo[playerid][Activated] = 0;
- }
- return 1;
- }
- CMD:call(playerid, params[])
- {
- if(CallStarted[playerid] == 1)
- {
- onCallFinished(playerid, 0);
- }
- else
- {
- new id;
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please buy a SIM card Before trying to call someone!");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please recharge your account before speak with anyone!");
- if(sscanf(params, "u", id)) return SendClientMessage(playerid, -1, COLOR_RED # "Usage: /call [playerid]");
- if(playerid == id) return SendClientMessage(playerid, -1, COLOR_RED # "You can't call youself, Silly!");
- new str[150];
- if(PhoneInfo[id][Activated] == 0)
- {
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Started...");
- format(str, sizeof(str), COLOR_GRI # "[" # COLOR_GREEN "%s" # COLOR_GRI "]: " # COLOR_WHITE "Sorry, this player number not exists or not activated", PhoneInfo[playerid][ISP]);
- SendClientMessage(playerid, -1 ,str);
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Ended.");
- return 1;
- }
- else
- {
- new isp[4];
- switch(PhoneInfo[playerid][ISP])
- {
- case 1:
- {
- isp = "SAT";
- }
- case 2:
- {
- isp = "LVT";
- }
- case 3:
- {
- isp = "SFT";
- }
- }
- SetPVarInt(playerid, "CalledPlayer", id);
- SetPVarInt(id, "CalledPlayer", playerid);
- IsCalled[id] = 1;
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Start Calling...");
- SendClientMessage(id, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "New Call");
- format(str, sizeof(str), COLOR_GRI # "[" # COLOR_GREEN "%s" # COLOR_GRI "]: " # COLOR_WHITE "You have a new call from %s use " # COLOR_GRI "/answer " # COLOR_WHITE "to accept call else use " # COLOR_GRI "/decline", isp, playerName[playerid]);
- SendClientMessage(id, -1 ,str);
- }
- }
- return 1;
- }
- CMD:answer(playerid, params[])
- {
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please buy a SIM card Before trying to call someone!");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please recharge your account before speak with anyone!");
- if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: you have no new calls!");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Connection Success! Start speak!");
- onCallStarted(playerid, GetPVarInt(playerid, "CalledPlayer"));
- return 1;
- }
- CMD:decline(playerid, params[])
- {
- if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please buy a SIM card Before trying to call someone!");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please recharge your account before speak with anyone!");
- if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "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, COLOR_RED # "Error: Please buy a SIM card Before trying to call someone!");
- if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, COLOR_RED # "Error: Please recharge your account before speak with anyone!");
- new str[120];
- format(str, sizeof(str), COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "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), COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "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);
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Started...");
- return 1;
- }
- public onCallFinished(playerid, reason)
- {
- if(reason == 1)
- {
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "You have no more money to pay the phone calls!");
- SendClientMessage(playerid, -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Ended.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Lost Connection.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "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, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Ended.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "this number busy at moment.");
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "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, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "Call Ended.");
- CallStarted[playerid] = 0;
- SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, COLOR_GRI # "[" # COLOR_GREEN "Phone" # COLOR_GRI "]: " # COLOR_WHITE "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);
- switch(PhoneInfo[playerid][ISP])
- {
- case 1:
- {
- PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 10;
- }
- case 2:
- {
- PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 50;
- }
- case 3:
- {
- PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 70;
- }
- }
- return 1;
- }
- public OnPlayerEnterDynamicCP(playerid, checkpointid)
- {
- if(checkpointid == Phone[3])
- {
- ShowPlayerDialog(playerid, DIALOG_PHONE, DIALOG_STYLE_LIST, "Phone Dealer", COLOR_WHITE # "Recharging my account\nBuy a SIM Card", "Buy", "Cancel");
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement