· 9 years ago · Jan 20, 2017, 10:22 PM
1/**
2 * Copyright (c) 2015-2016 SA-MP FilterScript
3 *
4 * This program is free software: you can redistribute it and/or modify it under the terms of the
5 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
6 * License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with this program.
13 * If not, see <http://www.gnu.org/licenses/>.
14*/
15
16 /*AUTHOR ***********************
17 @Yaa - SA-MP Scripter
18 ********************************/
19
20#include <a_samp>
21#include <a_mysql>
22#include <zcmd>
23#include <sscanf2>
24#include <streamer>
25
26#define MySQL_Host ""
27#define MySQL_User ""
28#define MySQL_DB ""
29#define MySQL_Pass ""
30#define MySQL_Port 3306
31
32#define DIALOG_PHONE 2000
33#define DIALOG_RECHARGE 3000
34
35/* Config:
36
37 ISP:
38
39 id 1 = SAT
40 id 2 = LVT
41 id 3 = SFT
42*/
43
44enum PlayerSIM
45{
46 Activated,
47 ISP,
48 SAT,
49 LVT,
50 SFT,
51 Value
52};
53
54
55static
56
57 MySQL:register,
58 PhoneInfo[MAX_PLAYERS][PlayerSIM],
59 PlayerText:Net[1],
60 CallStarted[MAX_PLAYERS],
61 TimerPhone[MAX_PLAYERS],
62 IsCalled[MAX_PLAYERS],
63 Phone[4]
64;
65
66forward onPhoneUpdate(playerid);
67forward onCallStarted(playerid, targetid);
68forward onCallCostTake(playerid);
69forward onCallFinished(playerid, reason);
70forward onPlayerStreamedOutNetwork(playerid);
71forward onTargetStreamedOutNetwork(playerid);
72forward onMySQLCheck(playerid);
73
74#define G "{6EF83C}"
75#define R "{F81414}"
76#define W "{FFFFFF}"
77#define O "{FFAF00}"
78#define YE "{FFFF00}"
79#define GRI "{C0C0C0}"
80
81public OnFilterScriptInit()
82{
83 print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
84 print(" * Yassine Phone System * ");
85 print(" * Loaded * ");
86 print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
87
88 Phone[0] = CreatePickup(1318, 2, -1727.5148, 1041.5735, 45.2109, -1);
89 Phone[1] = CreatePickup(1318, 2, 2408.6062, 1987.6985, 10.8203, -1);
90 Create3DTextLabel(""R"[Phones Dealer]", 0x008080FF, -1727.5148, 1041.5735, 45.2109, 40.0, 0, 0);
91 Create3DTextLabel(""R"[Phones Dealer]", 0x008080FF, 2408.6062, 1987.6985, 10.8203, 40.0, 0, 0);
92
93 Phone[2] = CreateActor(165, 2318.3064, -7.4166, 26.7496, 92.5721);
94
95 Phone[3] = CreateDynamicCP(2316.6213, -7.2762, 26.7422, 1.50, -1, -1, -1, 40.0);
96
97 new MySQLOpt:options = mysql_init_options();
98 mysql_set_option(options, SERVER_PORT, MySQL_Port);
99 mysql_log(ALL);
100 register = mysql_connect(MySQL_Host, MySQL_User, MySQL_Pass, MySQL_DB, options);
101 if(mysql_errno() != 0)
102 {
103 printf("[MySQL Connection]: The connection to Database `%s` has failed.", MySQL_DB);
104 printf("[MySQL Notice]: Fail to Create `phone` table on database `%s`", MySQL_DB);
105 }
106 else
107 {
108 printf("[MySQL Connection]: The connection to Database `%s` was successful.", MySQL_DB);
109 mysql_query(register, "CREATE TABLE IF NOT EXISTS `phone` (`Name` VARCHAR(64),`ISP` INT(129), `Value` INT(20))");
110 }
111 return 1;
112}
113
114public OnFilterScriptExit()
115{
116 print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
117 print(" * Yassine Phone System * ");
118 print(" * UnLoaded * ");
119 print(" -*-*-*-*-*-*-*-*-*-*-*-*-*- ");
120
121 DestroyPickup(Phone[0]);
122 DestroyPickup(Phone[1]);
123 DestroyActor(Phone[2]);
124 mysql_close(register);
125 return 1;
126}
127
128public OnPlayerConnect(playerid)
129{
130
131 Net[0] = CreatePlayerTextDraw(playerid,69.000000, 317.000000, "SAT");
132 PlayerTextDrawBackgroundColor(playerid,Net[0], 255);
133 PlayerTextDrawFont(playerid,Net[0], 1);
134 PlayerTextDrawLetterSize(playerid,Net[0], 0.500000, 1.000000);
135 PlayerTextDrawColor(playerid,Net[0], -1);
136 PlayerTextDrawSetOutline(playerid,Net[0], 0);
137 PlayerTextDrawSetProportional(playerid,Net[0], 1);
138 PlayerTextDrawSetShadow(playerid,Net[0], 1);
139 PlayerTextDrawSetSelectable(playerid,Net[0], 0);
140
141 new queryS[128];
142 mysql_format(register, queryS, sizeof(queryS), "SELECT * FROM `phone` WHERE `Name` = '%s' LIMIT 1", GetName(playerid));
143 mysql_tquery(register, queryS, "onMySQLCheck", "i", playerid);
144 return 1;
145}
146public OnPlayerSpawn(playerid)
147{
148 if(PhoneInfo[playerid][ISP] == 3)
149 {
150 PlayerTextDrawSetString(playerid, Net[0], "SFT");
151 }
152 if(PhoneInfo[playerid][ISP] == 2)
153 {
154 PlayerTextDrawSetString(playerid, Net[0], "LVT");
155 }
156 if(PhoneInfo[playerid][ISP] == 1)
157 {
158 PlayerTextDrawSetString(playerid, Net[0], "SAT");
159 }
160 PlayerTextDrawShow(playerid, Net[0]);
161
162 if(PhoneInfo[playerid][Activated] == 0)
163 {
164 PlayerTextDrawHide(playerid, Net[0]);
165 }
166 return 1;
167}
168public OnPlayerDisconnect(playerid, reason)
169{
170 if(PhoneInfo[playerid][Activated] == 1)
171 {
172 new querylist[200];
173 format(querylist, sizeof(querylist), "UPDATE `phone` SET `ISP` = '%d', `Value` = '%d'", PhoneInfo[playerid][ISP], PhoneInfo[playerid][Value]);
174 mysql_query(register, querylist);
175 }
176 return 1;
177}
178
179public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
180{
181 if(dialogid == DIALOG_PHONE)
182 {
183 switch(listitem)
184 {
185 case 0:
186 {
187 ShowPlayerDialog(playerid, DIALOG_RECHARGE, DIALOG_STYLE_INPUT, "Recharging your account", "Please enter a value below for recharge your account", "Buy", "Cancel");
188 }
189 case 1:
190 {
191 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");
192 }
193 }
194 }
195 if(dialogid == DIALOG_RECHARGE)
196 {
197 if(response)
198 {
199 if(strval(inputtext) == 0) return SendClientMessage(playerid, -1, ""R"Error: You can't recharge 0 $ :/ ");
200 if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid, -1, ""R"Error: you don't have all this money ");
201 GivePlayerMoney(playerid, -strval(inputtext));
202 PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] + strval(inputtext);
203 SendClientMessage(playerid, -1, ""G"Success: You account recharged !");
204 }
205 }
206 if(dialogid == DIALOG_PHONE+1)
207 {
208 switch(listitem)
209 {
210 case 0:
211 {
212 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");
213 }
214 case 1:
215 {
216 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");
217 }
218 case 2:
219 {
220 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");
221 }
222 }
223 }
224 if(dialogid == DIALOG_PHONE+2)
225 {
226 if(response)
227 {
228 new str[200];
229 if(GetPlayerMoney(playerid) < 10) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 10 in the hand !");
230 GivePlayerMoney(playerid, -100);
231 PhoneInfo[playerid][LVT] = 1;
232 PhoneInfo[playerid][ISP] = 2;
233 PhoneInfo[playerid][Activated] = 1;
234 SendClientMessage(playerid, -1, ""G"[LVT]: Now you are able to use /call !");
235 format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 2, 100)", GetName(playerid));
236 mysql_query(register, str);
237 }
238 }
239 if(dialogid == DIALOG_PHONE+3)
240 {
241 if(response)
242 {
243 new str[200];
244 if(GetPlayerMoney(playerid) < 1000) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 1000 in the hand !");
245 GivePlayerMoney(playerid, -100);
246 PhoneInfo[playerid][SFT] = 1;
247 PhoneInfo[playerid][ISP] = 3;
248 PhoneInfo[playerid][Activated] = 1;
249 SendClientMessage(playerid, -1, ""G"[SFT]: Now you are able to use /call !");
250 format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 3, 100)", GetName(playerid));
251 mysql_query(register, str);
252 }
253 }
254 if(dialogid == DIALOG_PHONE+4)
255 {
256 if(response)
257 {
258 new str[200];
259 if(GetPlayerMoney(playerid) < 10000) return SendClientMessage(playerid, -1, ""R"Error: you dont have $ 10000 in the hand !");
260 GivePlayerMoney(playerid, -100);
261 PhoneInfo[playerid][SAT] = 1;
262 PhoneInfo[playerid][ISP] = 1;
263 PhoneInfo[playerid][Activated] = 1;
264 PhoneInfo[playerid][Value] = 500;
265 SendClientMessage(playerid, -1, ""G"[SAT]: Now you are able to use /call !");
266 format(str, sizeof(str), "INSERT INTO `phone`(`Name`, `ISP`, `Value`) VALUES ('%s', 1, 600)", GetName(playerid));
267 mysql_query(register, str);
268 PlayerTextDrawShow(playerid, Net[0]);
269 }
270 }
271 return 1;
272}
273public OnPlayerText(playerid, text[])
274{
275 if(CallStarted[playerid] == 1)
276 {
277 new str[100];
278 format(str, sizeof(str), ""GRI"["G"Phone"GRI" %s]: "W"%s", GetName(playerid), text);
279 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, str);
280 SendClientMessage(playerid, -1, str);
281 return 0;
282 }
283 return 0;
284}
285
286public OnPlayerPickUpPickup(playerid, pickupid)
287{
288 if(Phone[0] == pickupid || Phone[1] == pickupid)
289 {
290 SetPlayerPos(playerid, 2315.952880,-1.618174,26.742187);
291 }
292 return 1;
293}
294
295public onMySQLCheck(playerid)
296{
297 new rows;
298 cache_get_row_count(rows);
299 if(rows == 1)
300 {
301 cache_get_value_name_int(0, "ISP", PhoneInfo[playerid][ISP]);
302 cache_get_value_name_int(0, "Value", PhoneInfo[playerid][Value]);
303
304 PhoneInfo[playerid][Activated] = 1;
305 if(PhoneInfo[playerid][ISP] == 1)
306 {
307 PhoneInfo[playerid][SAT] = 1;
308 }
309 if(PhoneInfo[playerid][ISP] == 2)
310 {
311 PhoneInfo[playerid][LVT] = 1;
312 }
313 if(PhoneInfo[playerid][ISP] == 3)
314 {
315 PhoneInfo[playerid][SFT] = 1;
316 }
317 }
318 else
319 {
320 PhoneInfo[playerid][Activated] = 0;
321 }
322 return 1;
323}
324
325CMD:call(playerid, params[])
326{
327 if(CallStarted[playerid] == 1)
328 {
329 onCallFinished(playerid, 0);
330 }
331 else
332 {
333 new id, str[150];
334 if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
335 if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
336 if(sscanf(params, "u", id)) return SendClientMessage(playerid, -1, ""R"Usage: /call [playerid]");
337 if(playerid == id) return SendClientMessage(playerid, -1, ""R"You can't call youself, Silly !");
338 if(PhoneInfo[id][Activated] == 0)
339 {
340 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Started...");
341 format(str, sizeof(str), ""GRI"["G"%s"GRI"]: "W"Sorry, this player number not exists or not activated", PhoneInfo[playerid][ISP]);
342 SendClientMessage(playerid, -1 ,str);
343 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
344 return 1;
345 }
346 else
347 {
348 new isp[20];
349 if(PhoneInfo[playerid][ISP] == 1) isp = "SAT";
350 if(PhoneInfo[playerid][ISP] == 2) isp = "LVT";
351 if(PhoneInfo[playerid][ISP] == 3) isp = "SFT";
352
353 SetPVarInt(playerid, "CalledPlayer", id);
354 SetPVarInt(id, "CalledPlayer", playerid);
355 IsCalled[id] = 1;
356 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Start Calling...");
357 SendClientMessage(id, -1, ""GRI"["G"Phone"GRI"]: "W"New Call");
358 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));
359 SendClientMessage(id, -1 ,str);
360 }
361 }
362 return 1;
363}
364
365CMD:answer(playerid, params[])
366{
367 if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
368 if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
369 if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, ""R"Error: you have no new calls !");
370 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Connection Success ! Start speak !");
371 onCallStarted(playerid, GetPVarInt(playerid, "CalledPlayer"));
372 return 1;
373}
374
375CMD:decline(playerid, params[])
376{
377 if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
378 if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
379 if(IsCalled[playerid] == 0) return SendClientMessage(playerid, -1, ""R"Error: you have no new calls !");
380 IsCalled[playerid] = 0;
381 onCallFinished(playerid, 2);
382 return 1;
383}
384
385CMD:phone(playerid, params[])
386{
387 if(PhoneInfo[playerid][Activated] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please buy a SIM card Before trying to call someone !");
388 if(PhoneInfo[playerid][Value] == 0) return SendClientMessage(playerid, -1, ""R"Error: Please recharge your account before speak with anyone !");
389 new str[120];
390
391 format(str, sizeof(str), ""GRI"["G"Phone"GRI"]: "W"You are using ISP Id:%d ", PhoneInfo[playerid][ISP]);
392 SendClientMessage(playerid, -1, str);
393 SendClientMessage(playerid, -1, "ISP Ids: SAT -> 1, LVT -> 2, SFT -> 3");
394 format(str, sizeof(str), ""GRI"["G"Phone"GRI"]: "W"You have $ %d in your account", PhoneInfo[playerid][Value]);
395 SendClientMessage(playerid, -1, str);
396 return 1;
397}
398
399public onCallStarted(playerid, targetid)
400{
401 SetPlayerSpecialAction(playerid, SPECIAL_ACTION_USECELLPHONE);
402 SetPlayerSpecialAction(targetid, SPECIAL_ACTION_USECELLPHONE);
403
404 SetPVarInt(playerid, "CalledPlayer", targetid);
405 SetPVarInt(targetid, "CalledPlayer", playerid);
406
407 CallStarted[playerid] = 1;
408 CallStarted[targetid] = 1;
409
410 TimerPhone[playerid] = SetTimerEx("onCallCostTake", 1000, true, "i", playerid);
411 TimerPhone[targetid] = SetTimerEx("onCallCostTake", 1000, true, "i", targetid);
412
413 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Started...");
414 return 1;
415}
416
417public onCallFinished(playerid, reason)
418{
419 if(reason == 1)
420 {
421 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"You have no more money to pay the phone calls !");
422 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
423
424 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Lost Connection.");
425 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
426
427 CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
428 CallStarted[playerid] = 0;
429
430 KillTimer(TimerPhone[playerid]);
431 KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
432
433 SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
434 SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
435 return 1;
436 }
437 if(reason == 2)
438 {
439 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
440
441 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"this number busy at moment.");
442 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
443
444 CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
445 CallStarted[playerid] = 0;
446
447 KillTimer(TimerPhone[playerid]);
448 KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
449
450 SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
451 SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
452 return 1;
453 }
454 else
455 {
456 SendClientMessage(playerid, -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
457 CallStarted[playerid] = 0;
458 SendClientMessage(GetPVarInt(playerid, "CalledPlayer"), -1, ""GRI"["G"Phone"GRI"]: "W"Call Ended.");
459 CallStarted[GetPVarInt(playerid, "CalledPlayer")] = 0;
460 KillTimer(TimerPhone[playerid]);
461 KillTimer(TimerPhone[GetPVarInt(playerid, "CalledPlayer")]);
462 SetPlayerSpecialAction(playerid, SPECIAL_ACTION_STOPUSECELLPHONE);
463 SetPlayerSpecialAction(GetPVarInt(playerid, "CalledPlayer"), SPECIAL_ACTION_STOPUSECELLPHONE);
464 }
465 return 1;
466}
467
468public onCallCostTake(playerid)
469{
470 if(PhoneInfo[playerid][Value] == 0) return onCallFinished(playerid, 1);
471 if(PhoneInfo[playerid][SFT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 50;
472 if(PhoneInfo[playerid][LVT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 70;
473 if(PhoneInfo[playerid][SAT] == 1) PhoneInfo[playerid][Value] = PhoneInfo[playerid][Value] - 10;
474 return 1;
475}
476
477public OnPlayerEnterDynamicCP(playerid, checkpointid)
478{
479 if(checkpointid == Phone[3])
480 {
481 ShowPlayerDialog(playerid, DIALOG_PHONE, DIALOG_STYLE_LIST, "Phone Dealer", ""W"Recharging my account\nBuy a SIM Card", "Buy", "Cancel");
482 }
483 return 1;
484}
485
486stock GetName(playerid)
487{
488 new szName[MAX_PLAYER_NAME];
489 GetPlayerName(playerid, szName, sizeof(szName));
490 return szName;
491}