Advertisement
Chainksain

tutorial7.pwn

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