· 5 years ago · Apr 16, 2020, 10:04 PM
1#include <a_samp>
2#include <a_mysql>
3#include <sscanf2>
4#include <zcmd>
5#include <DOF2>
6
7#define function%0(%1) forward %0(%1); public %0(%1)
8
9new MySQL:DBConn, host[16], username[MAX_PLAYER_NAME], database[MAX_PLAYER_NAME], pass[16];
10
11main()
12{
13 print("\n----------------------------------");
14 print(" Blank Gamemode by your name here");
15 print("----------------------------------\n");
16}
17
18public OnGameModeInit()
19{
20 SetGameModeText("Blank Script");
21 AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
22 LoadMap("maps/favela_objects.txt");
23 DataBaseInit();
24 return 1;
25}
26
27public OnGameModeExit()
28{
29 DOF2_Exit();
30 return 1;
31}
32
33public OnPlayerRequestClass(playerid, classid)
34{
35 SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
36 SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
37 SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
38 return 1;
39}
40
41public OnPlayerConnect(playerid)
42{
43 RemoveBuildingFromFile(playerid, "maps/favela_buildings.txt");
44 return 1;
45}
46
47public OnPlayerDisconnect(playerid, reason)
48{
49 new rsnstr[3][] =
50 {
51 "Timeout/Crash",
52 "Saiu",
53 "Kickado/Banido"
54 };
55 new string[64];
56 format(string, sizeof(string), "%s foi desconectado (%s)", GetPlayerNameEx(playerid), rsnstr[reason]);
57 SendClientMessageToAll(-1, string);
58 return 1;
59}
60
61public OnPlayerSpawn(playerid)
62{
63 return 1;
64}
65
66public OnPlayerDeath(playerid, killerid, reason)
67{
68 return 1;
69}
70
71public OnVehicleSpawn(vehicleid)
72{
73 return 1;
74}
75
76public OnVehicleDeath(vehicleid, killerid)
77{
78 return 1;
79}
80
81public OnPlayerText(playerid, text[])
82{
83 return 1;
84}
85
86public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
87{
88 return 1;
89}
90
91public OnPlayerExitVehicle(playerid, vehicleid)
92{
93 return 1;
94}
95
96public OnPlayerStateChange(playerid, newstate, oldstate)
97{
98 return 1;
99}
100
101public OnPlayerEnterCheckpoint(playerid)
102{
103 return 1;
104}
105
106public OnPlayerLeaveCheckpoint(playerid)
107{
108 return 1;
109}
110
111public OnPlayerEnterRaceCheckpoint(playerid)
112{
113 return 1;
114}
115
116public OnPlayerLeaveRaceCheckpoint(playerid)
117{
118 return 1;
119}
120
121public OnRconCommand(cmd[])
122{
123 return 1;
124}
125
126public OnPlayerRequestSpawn(playerid)
127{
128 return 1;
129}
130
131public OnObjectMoved(objectid)
132{
133 return 1;
134}
135
136public OnPlayerObjectMoved(playerid, objectid)
137{
138 return 1;
139}
140
141public OnPlayerPickUpPickup(playerid, pickupid)
142{
143 return 1;
144}
145
146public OnVehicleMod(playerid, vehicleid, componentid)
147{
148 return 1;
149}
150
151public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
152{
153 return 1;
154}
155
156public OnVehicleRespray(playerid, vehicleid, color1, color2)
157{
158 return 1;
159}
160
161public OnPlayerSelectedMenuRow(playerid, row)
162{
163 return 1;
164}
165
166public OnPlayerExitedMenu(playerid)
167{
168 return 1;
169}
170
171public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
172{
173 return 1;
174}
175
176public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
177{
178 return 1;
179}
180
181public OnRconLoginAttempt(ip[], password[], success)
182{
183 return 1;
184}
185
186public OnPlayerUpdate(playerid)
187{
188 return 1;
189}
190
191public OnPlayerStreamIn(playerid, forplayerid)
192{
193 return 1;
194}
195
196public OnPlayerStreamOut(playerid, forplayerid)
197{
198 return 1;
199}
200
201public OnVehicleStreamIn(vehicleid, forplayerid)
202{
203 return 1;
204}
205
206public OnVehicleStreamOut(vehicleid, forplayerid)
207{
208 return 1;
209}
210
211public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
212{
213 return 1;
214}
215
216public OnPlayerClickPlayer(playerid, clickedplayerid, source)
217{
218 return 1;
219}
220
221public OnPlayerClickMap(playerid, Float:fX, Float:fY, Float:fZ)
222{
223 return 1;
224}
225
226// FUNCOES
227
228function DataBaseInit()
229{
230 LoadDBSettings("dbconfig.ini");
231 DBConn = mysql_connect(host, username, pass, database);
232 if(mysql_errno() != 0)
233 {
234 print("[MySQL] ERRO: Não foi possível conectar à database!");
235 SendRconCommand("exit");
236 }
237 else
238 {
239 printf("[MySQL] Conectado a '%s' com sucesso!", database);
240 print("[MySQL] Verificando tabelas...");
241
242 mysql_query(DBConn, "CREATE TABLE IF NOT EXISTS Player (\
243 id int NOT NULLL AUTO_INCREMENT,\
244 nome varchar(255) NOT NULL,\
245 senha varchar(255) NOT NULL,\
246 admin int DEFAULT 0,\
247 PRIMARY KEY(id));", false);
248 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS score int DEFAULT 0;", false);
249 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS health float DEFAULT 100;", false);
250 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS armor float DEFAULT 100;", false);
251 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS dinheiro int DEFAULT 100;", false);
252 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS posX double DEFAULT 0;", false);
253 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS posY double DEFAULT 0;", false);
254 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS posZ double DEFAULT 0;", false);
255 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS angulo double DEFAULT 0;", false);
256 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS interior int DEFAULT 0;", false);
257 mysql_query(DBConn, "ALTER TABLE Player ADD IF NOT EXISTS vw int DEFAULT 0;", false);
258
259 print("[MySQL] Tabela 'Player' verificada com sucesso!");
260 }
261
262 return 1;
263}
264
265function RemoveBuildingFromFile(playerid, const file[])
266{
267 new File:map = fopen(file, io_read);
268 if(map)
269 {
270 new string[256];
271 while(fread(map, string))
272 {
273 new modelid, Float:pos[3], Float:rad;
274 if(!sscanf(string, "dffff", modelid, pos[0], pos[1], pos[2], rad))
275 RemoveBuildingForPlayer(playerid, modelid, pos[0], pos[1], pos[2], rad);
276 else
277 return printf("Carregamento do mapa '%s' falhou para o jogador %s(%d).", file, GetPlayerNameEx(playerid), playerid);
278 }
279 }
280 return printf("Jogador %s(%d) carregou o mapa '%s' com êxito.", GetPlayerNameEx(playerid), playerid, file);
281}
282
283function LoadMap(const file[])
284{
285 printf("Carregando Mapa '%s'...", file);
286 new File:map = fopen(file, io_read);
287 if(map)
288 {
289 new string[256];
290 while(fread(map, string))
291 {
292 new modelid, Float:pos[3], Float:rot[3];
293 if(sscanf(string, "dffffff", modelid, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]))
294 return printf("Erro ao carregar o mapa '%s'!",file);
295 else
296 CreateObject(modelid, pos[0], pos[1], pos[2], rot[0], rot[1], rot[2]);
297
298 }
299 return printf("Mapa '%s' carregado com sucesso!",file);
300 }
301 else return printf("Erro ao carregar o mapa '%s'!",file);
302}
303
304// COMANDOS
305
306CMD:pos(playerid, const params[])
307{
308 new Float:pos[3], giveplayerid;
309 if(sscanf(params, "ufff", giveplayerid, pos[0], pos[1], pos[2]))
310 return SendClientMessage(playerid, -1, "USO: /pos [id] [x] [y] [z]");
311
312 if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID)
313 return SendClientMessage(playerid, -1, "ERRO: ID Inválido!");
314
315 SetPlayerPos(giveplayerid, pos[0], pos[1], pos[2]);
316 return 1;
317}
318
319CMD:info(playerid, const params[])
320{
321 new giveplayerid, string[64];
322
323 if(sscanf(params, "u", giveplayerid))
324 return SendClientMessage(playerid, -1, "USO: /info [id]");
325
326 if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID)
327 return SendClientMessage(playerid, -1, "ERRO: ID Inválido!");
328
329 format(string, sizeof(string), "Jogador: %s", GetPlayerNameEx(giveplayerid));
330 SendClientMessage(playerid, -1, string);
331
332 format(string, sizeof(string), "ID: %d", giveplayerid);
333 SendClientMessage(playerid, -1, string);
334
335 format(string, sizeof(string), "Score: %d", GetPlayerScore(giveplayerid));
336 SendClientMessage(playerid, -1, string);
337
338 format(string, sizeof(string), "Dinheiro: %d", GetPlayerMoney(giveplayerid));
339 SendClientMessage(playerid, -1, string);
340
341 format(string, sizeof(string), "Life: %f", GetPlayerHealthEx(giveplayerid));
342 SendClientMessage(playerid, -1, string);
343
344 format(string, sizeof(string), "Armor: %f", GetPlayerArmourEx(giveplayerid));
345 SendClientMessage(playerid, -1, string);
346
347 new Float:pos[3];
348 GetPlayerPos(giveplayerid, pos[0], pos[1], pos[2]);
349 format(string, sizeof(string), "PosX: %f PosY: %f PosZ: %f", pos[0], pos[1], pos[2]);
350 SendClientMessage(playerid, -1, string);
351
352 format(string, sizeof(string),"Int: %d", GetPlayerInterior(giveplayerid));
353 SendClientMessage(playerid, -1, string);
354
355 format(string, sizeof(string),"Virtual World: %d", GetPlayerVirtualWorld(giveplayerid));
356 SendClientMessage(playerid, -1, string);
357
358 return 1;
359}
360
361// PROCEDIMENTOS
362
363stock LoadDBSettings(filename[])
364{
365 //new host[16], username[MAX_PLAYER_NAME], database[MAX_PLAYER_NAME], pass[16];
366 if(DOF2_FileExists(filename))
367 {
368 format(host, sizeof(host), "%s", DOF2_GetString(filename,"address"));
369 format(username, sizeof(username), "%s", DOF2_GetString(filename,"username"));
370 format(database, sizeof(database), "%s", DOF2_GetString(filename,"database"));
371 format(pass, sizeof(pass), "%s", DOF2_GetString(filename,"password"));
372 }
373 else
374 {
375 DOF2_CreateFile(filename);
376 DOF2_SetString(filename,"address","127.0.0.1");
377 DOF2_SetString(filename,"username","root");
378 DOF2_SetString(filename,"database", " ");
379 DOF2_SetString(filename,"password", " ");
380 DOF2_SaveFile();
381 }
382}
383
384stock GetPlayerNameEx(playerid)
385{
386 new PlayerName[MAX_PLAYER_NAME];
387 GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
388 return PlayerName;
389}
390
391function Float:GetPlayerHealthEx(playerid)
392{
393 new Float:health;
394 GetPlayerHealth(playerid, health);
395 return health;
396}
397
398function Float:GetPlayerArmourEx(playerid)
399{
400 new Float:armor;
401 GetPlayerArmour(playerid, armor);
402 return armor;
403}