Advertisement
Chainksain

tutorial8.pwn

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