· 5 years ago · Aug 06, 2020, 12:08 PM
1//=======================NewYork RolePlay=======================================
2/*
3 Owner Lykenzzi
4 Scripter Lykenzzi
5 Crafted buy Lukenzzi
6*/
7//==============================================================================
8
9//==============================[Inludes]=======================================
10#include <a_samp>
11#include <YSI\y_timers>
12#include <YSI\y_va>
13#include <a_mysql>
14//==============================[Defined]=======================================
15#if defined MAX_PLAYERS
16 #undef MAX_PLAYERS
17#endif
18#define MAX_PLAYERS 200
19
20#define func:%0(%1) forward%0(%1); public%0(%1)
21//=============================[Dialozi]========================================
22
23//==============================[MySQL SetUp====================================
24#define MYSQL_HOST "localhost"
25#define MYSQL_USER "root"
26#define MYSQL_PW ""
27#define MYSQL_DB "reglog_db"
28
29new MySQL:SQL, yQuery[500], yString[500];
30//=============================[New-ovi]========================================
31#define srwboja "{E76004}"
32#define BELA "{FFFFFF}"
33
34#define Info(%0,%1) \
35 SendClientMessageEx(%0, 0xE76004FF, "[MySQL RegLog]: "BELA""%1)
36
37stock SendClientMessageEx(playerid, colour, const fmat[], va_args<>) {
38 new str[145];
39 va_format(str, sizeof (str), fmat, va_start<3>);
40 return SendClientMessage(playerid, colour, str);
41}
42//=============================[ENUM-OVI=========================================
43enum PLAYER_ENUM {
44 pName[24],
45 pSQLID,
46 pLozinka[24],
47 pDrzava,
48 pEmail[128],
49 pGodine,
50 pSpol,
51 pNovac,
52 pSkin,
53 pLevel
54};
55
56new PI[MAX_PLAYERS][PLAYER_ENUM];
57
58enum {
59 dialog_REGISTER,
60 dialog_DRZAVA,
61 dialog_EMAIL,
62 dialog_SPOL,
63 dialog_GODINE,
64 dialog_LOGIN
65};
66//==============================================================================
67
68main()
69{
70 print("\n----------------------------------");
71 print(" "Mod je uspesno ucitan !");
72 print("----------------------------------\n");
73}
74
75public OnGameModeInit()
76{
77 SQL = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PW, MYSQL_DB);
78
79 if (mysql_errno() != 0) {
80 print(" * MYSQL ERROR: Nije se moguce konektovati na databazu.");
81 SendRconCommand("exit");
82 return 0;
83 }
84 print(" * MYSQL INFO: Konekcija na databazu je uspjesna.");
85
86 SetGameModeText("@ VP > v1.0 > Yansi");
87
88 EnableStuntBonusForAll(0);
89 DisableInteriorEnterExits();
90
91 mysql_tquery(SQL, "CREATE TABLE IF NOT EXISTS `users` (\
92 `ID` int(11) NOT NULL,\
93 `Name` varchar(24) NOT NULL DEFAULT 'none',\
94 `Lozinka` varchar(24) NOT NULL DEFAULT 'none',\
95 `Email` varchar(128) NOT NULL DEFAULT 'none',\
96 `Drzava` int(11) NOT NULL DEFAULT 0,\
97 `Godine` int(11) NOT NULL DEFAULT 0,\
98 `Skin` int(11) NOT NULL DEFAULT 19,\
99 `Level` int(11) NOT NULL DEFAULT 3,\
100 `Novac` int(11) NOT NULL DEFAULT 150000,\
101 `Spol` int(11) NOT NULL DEFAULT 0\
102 )");
103 return 1;
104}
105
106public OnGameModeExit()
107{
108 return 1;
109}
110
111public OnPlayerRequestClass(playerid, classid)
112{
113 SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
114 SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
115 SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
116 return 1;
117}
118
119public OnPlayerConnect(playerid)
120{
121 yQuery[0] = EOS;
122 mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' LIMIT 1", GetName(playerid));
123 mysql_pquery(SQL, yQuery, "CheckPlayerAccount", "d", "");
124
125 TogglePlayerSpectating(playerid, false);
126 return 1;
127}
128forward CheckPlayerAccount(playerid);
129public CheckPlayerAccount(playerid)
130{
131 switch(cache_num_rows()) {
132 case 0: {
133
134 InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
135 InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
136
137 yString[0] = EOS;
138
139 format(yString, sizeof(yString), \
140 ""srwboja"> "BELA"Dobrodosao '%s' na 'Ime Servera'!\n\
141 "srwboja"____________________________________\n\
142 "srwboja"> "BELA"Vas nalog nije pronadjen u bazi!\n\
143 "srwboja"> "BELA"Da biste nastavili igru potrebno je da se registrujete!\n\
144 "srwboja"> "BELA"Da bi se registrovali potrebno je da uneste lozinku!\n\
145 "srwboja"____________________________________\n\
146 "BELA"> "srwboja"Ime Servera "BELA" - "srwboja"SINCE 2019", GetName(playerid));
147
148 ShowPlayerDialog(playerid, dialog_REGISTER, DIALOG_STYLE_INPUT,
149 ""srwboja"VP - "BELA"Registracija", yString,
150 ""srwboja"UNESI", "KICK");
151 }
152 case 1: {
153
154 InterpolateCameraPos(playerid, 537.2963, -995.1501, 124.7903, 1373.3412, -2283.9702, 65.2952, 10000, 30000);
155 InterpolateCameraLookAt(playerid, 538.1735, -995.6352, 124.6076, 1374.3429, -2283.9468, 64.7175, 10000, 30000);
156
157 //login dialog
158 format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
159 \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
160 "srwboja"___________________________________________________________________",
161 GetName(playerid));
162
163 ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
164 }
165 }
166 return 1;
167}
168
169stock GetName(playerid) {
170 new name[MAX_PLAYER_NAME];
171 GetPlayerName(playerid, name, sizeof(name));
172 return name;
173}
174forward CheckSQLID(playerid);
175public CheckSQLID(playerid)
176{
177 PI[playerid][pSQLID] = cache_insert_id();
178 printf("(MYSQl REGISTER): Novi account kreiran ! Ime: %s | ID: %d", GetName(playerid), playerid);
179 return 1;
180}
181
182public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
183{
184 if(dialogid == dialog_REGISTER) {
185 if(!response)
186 return Kick(playerid);
187
188 yString[0] = EOS;
189
190 format(PI[playerid][pName], 24, GetName(playerid));
191 format(PI[playerid][pLozinka], 128, inputtext);
192
193 yQuery[0] = EOS;
194
195 mysql_format(SQL, yQuery, sizeof(yQuery), "INSERT INTO `users` (Name, Lozinka) VALUES ('%e', '%e')", GetName(playerid), inputtext);
196 mysql_tquery(SQL, yQuery, "CheckSQLID", "");
197
198 ShowPlayerDialog(playerid, dialog_DRZAVA, DIALOG_STYLE_LIST,
199 ""srwboja"VP - "BELA"Drzava",
200 ""srwboja"[1]. "BELA"Srbija\n"srwboja"[2]. "BELA"Hrvatska\n"srwboja"[3]. "BELA"BiH\n"srwboja"[4]. "BELA"Crna Gora\n"srwboja"[5]. "BELA"Ostalo\n",
201 ""srwboja"ODABERI", "KICK");
202 }
203
204 if(dialogid == dialog_EMAIL) {
205 if(!response)
206 return Kick(playerid);
207
208 if(!IsValidEmail(inputtext))
209 return Kick(playerid);
210
211 yString[0] = EOS;
212 yQuery[0] = EOS;
213
214 format(PI[playerid][pEmail], 128, inputtext);
215
216 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Email` = '%s' WHERE `ID` = '%d'", PI[playerid][pEmail], PI[playerid][pSQLID]);
217 mysql_tquery(SQL, yQuery);
218
219 Info(playerid, "Vasa e-mail adresa: %s", inputtext);
220
221 yString[0] = EOS;
222 ShowPlayerDialog(playerid, dialog_SPOL, DIALOG_STYLE_MSGBOX, ""srwboja"VP - "BELA"Spol",
223 ""srwboja"> "BELA"Odaberite kog ste spola, musko lili zensko?",
224 ""srwboja"MUSKO", "ZENSKO");
225 }
226
227 if(dialogid == dialog_SPOL) {
228 if(!response) {
229 Info(playerid, "Uredu, vi ste zenskog spola !");
230 PI[playerid][pSpol] = 2, PI[playerid][pSkin] = 12;
231
232 yQuery[0] = EOS;
233 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 2, `Skin` = 12 WHERE `ID` = %d", PI[playerid][pSQLID]);
234 mysql_tquery(SQL, yQuery);
235
236 SetPlayerSkin(playerid, PI[playerid][pSkin]);
237 GivePlayerMoney(playerid, PI[playerid][pNovac]);
238 SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
239 SpawnPlayer(playerid);
240 }
241
242 Info(playerid, "Uredu, vi ste muskog spola !");
243 PI[playerid][pSpol] = 1, PI[playerid][pSkin] = 19;
244
245 yQuery[0] = EOS;
246 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Spol` = 1, `Skin` = 29 WHERE `ID` = %d", PI[playerid][pSQLID]);
247 mysql_tquery(SQL, yQuery);
248
249 SetPlayerSkin(playerid, PI[playerid][pSkin]);
250 GivePlayerMoney(playerid, PI[playerid][pNovac]);
251 SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
252 SpawnPlayer(playerid);
253 return 1;
254 }
255
256 if(dialogid == dialog_DRZAVA) {
257 if(!response)
258 return Kick(playerid);
259
260 yQuery[0] = EOS;
261 switch(listitem) {
262 case 0: {
263 Info(playerid, "Vi ste poreklom iz Srbije !");
264
265 PI[playerid][pDrzava] = 1;
266 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '1' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
267 mysql_tquery(SQL, yQuery);
268
269 format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
270 \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
271 "srwboja"__________________________________________________");
272
273 ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
274 ""srwboja"VP - "BELA"Godine", yString,
275 ""srwboja"UNESI", "KICK");
276 }
277 case 1: {
278 Info(playerid, "Vi ste poreklom iz Hrvatske !");
279
280 PI[playerid][pDrzava] = 2;
281 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '2' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
282 mysql_tquery(SQL, yQuery);
283
284 format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
285 \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
286 "srwboja"__________________________________________________");
287
288 ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
289 ""srwboja"VP - "BELA"Godine", yString,
290 ""srwboja"UNESI", "KICK");
291 }
292 case 2: {
293 Info(playerid, "Vi ste poreklom iz Bosne i Hercegovine !");
294
295 PI[playerid][pDrzava] = 3;
296 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '3' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
297 mysql_tquery(SQL, yQuery);
298
299 format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
300 \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
301 "srwboja"__________________________________________________");
302
303 ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
304 ""srwboja"VP - "BELA"Godine", yString,
305 ""srwboja"UNESI", "KICK");
306 }
307 case 3: {
308 Info(playerid, "Vi ste poreklom iz Crne Gore !");
309
310 PI[playerid][pDrzava] = 4;
311 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '4' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
312 mysql_tquery(SQL, yQuery);
313
314 format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
315 \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
316 "srwboja"__________________________________________________");
317
318 ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
319 ""srwboja"VP - "BELA"Godine", yString,
320 ""srwboja"UNESI", "KICK");
321 }
322 case 4: {
323 Info(playerid, "Vi ste poreklom iz neke druge drzave !");
324
325 PI[playerid][pDrzava] = 5;
326 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Drzava` = '5' WHERE `ID` = '%d'", PI[playerid][pSQLID]);
327 mysql_tquery(SQL, yQuery);
328
329 format(yString, sizeof(yString), ""srwboja"> "BELA"Molimo Vas unesite Vas broj godina ispod!\
330 \n"srwboja"__________________________________________________\n"srwboja"> "BELA"Minimalan broj godina: 12, maksimalan: 50\n\
331 "srwboja"__________________________________________________");
332
333 ShowPlayerDialog(playerid, dialog_GODINE, DIALOG_STYLE_INPUT,
334 ""srwboja"VP - "BELA"Godine", yString,
335 ""srwboja"UNESI", "KICK");
336 }
337 }
338 return 1;
339 }
340
341 if(dialogid == dialog_GODINE) {
342 if(!response)
343 return Kick(playerid);
344
345 PI[playerid][pGodine] = strval(inputtext);
346
347 yQuery[0] = EOS, yString[0] = EOS;
348
349 mysql_format(SQL, yQuery, sizeof(yQuery), "UPDATE `users` SET `Godine` = '%d' WHERE `ID` = '%d'", PI[playerid][pGodine], PI[playerid][pSQLID]);
350 mysql_tquery(SQL, yQuery);
351
352 format(yString, sizeof(yString), ""srwboja"> "BELA"Unesite Vasu vazecu e-mail adresu !\n"srwboja"_______________________________________________ \
353 \n> "BELA"Zbog bezbednosti Vaseg accounta, molimo vas unesite e-mail..\n"srwboja"___________________________________________________________________",
354 GetName(playerid));
355
356 ShowPlayerDialog(playerid, dialog_EMAIL, DIALOG_STYLE_INPUT, ""srwboja"VP - "BELA"E-Mail", yString, ""srwboja"UNESI", "KICK");
357 return 1;
358 }
359
360 //login
361 if(dialogid == dialog_LOGIN) {
362 if(!response)
363 return Kick(playerid);
364
365 yQuery[0] = EOS;
366
367 mysql_format(SQL, yQuery, sizeof(yQuery), "SELECT * FROM `users` WHERE `Name` = '%e' AND `Lozinka` = '%e' LIMIT 1", GetName(playerid), inputtext);
368 mysql_pquery(SQL, yQuery, "OnPlayerLogin", "d", playerid);
369 }
370 return 1;
371}
372//==============================================================================
373IsValidEmail(const email[])
374{
375 new at_pos = strfind(email, "@", true);
376 if(at_pos >= 1)
377 {
378 new offset = (at_pos + 1), dot_pos = strfind(email, ".", true, offset);
379 if(dot_pos > offset)
380 {
381 return 1;
382 }
383 }
384 return 0;
385}
386//==============================================================================
387forward OnPlayerLogin(playerid);
388public OnPlayerLogin(playerid)
389{
390 yString[0] = EOS;
391 switch(cache_num_rows()) {
392 case 0: {
393 format(yString, sizeof(yString), ""srwboja"> "BELA"Dobrodosao %s na 'Ime Servera'\n"srwboja"___________________________________________________________________ \
394 \n> "BELA"Vas account je pronadjen u nasoj bazi podataka..\n"srwboja"> "BELA"Molimo ulogujte se, unesite tacnu sifru ispod\n \
395 "srwboja"___________________________________________________________________",
396 GetName(playerid));
397
398 ShowPlayerDialog(playerid, dialog_LOGIN, DIALOG_STYLE_PASSWORD, ""srwboja"VP - "BELA"Prijavljivanje", yString, ""srwboja"UNESI", "IZLAZ");
399
400 SendClientMessage(playerid, 0xFF0000FF, "(greska): "BELA"Pogresna lozinka !");
401 }
402 case 1: {
403 cache_get_value_name(0, "Name", PI[playerid][pName]);
404 cache_get_value_name(0, "Lozinka", PI[playerid][pLozinka]);
405 cache_get_value_name(0, "Email", PI[playerid][pEmail]);
406 cache_get_value_name_int(0, "Drzava", PI[playerid][pDrzava]);
407 cache_get_value_name_int(0, "Godine", PI[playerid][pGodine]);
408 cache_get_value_name_int(0, "Spol", PI[playerid][pSpol]);
409 cache_get_value_name_int(0, "Skin", PI[playerid][pSkin]);
410 cache_get_value_name_int(0, "Novac", PI[playerid][pNovac]);
411 cache_get_value_name_int(0, "Level", PI[playerid][pLevel]);
412
413 cache_get_value_name_int(0, "ID", PI[playerid][pSQLID]);
414
415 for(new i = 0; i < 40; i++) { SendClientMessage(playerid, -1, " "); }
416 Info(playerid, "%s, uspesno ste se ulogovali na 'Ime Servera' OGC !", GetName(playerid));
417
418 ResetPlayerMoney(playerid), GivePlayerMoney(playerid, PI[playerid][pNovac]);
419
420 SetPlayerScore(playerid, PI[playerid][pLevel]);
421 SetPlayerSkin(playerid, PI[playerid][pSkin]);
422 TogglePlayerSpectating(playerid, false);
423
424 SetSpawnInfo(playerid, 0, PI[playerid][pSkin], 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0); //edit
425 SpawnPlayer(playerid);
426 }
427 }
428 return 1;
429}
430