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