Advertisement
Guest User

[MySQL - R41]: Dynamic teleports system - FixFl0w

a guest
Oct 14th, 2018
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. /System dynamic teleports SOLVER PROBLEMS. 14-10-2018
  2. #include <a_samp>
  3. #include <a_mysql>
  4. #include <zcmd>
  5.  
  6. new MySQL:mysqldb;
  7. #define mysql_host "localhost"
  8. #define mysql_usuario "root"
  9. #define mysql_clave ""
  10. #define mysql_db "basededatosxd"
  11.  
  12. new OFFSETXD[MAX_PLAYERS];
  13.  
  14. new enum {
  15. SIN_USO,
  16. DIALOG_TELESXD,
  17. }
  18.  
  19. stock Nombre(playerid){
  20. new namek[24];
  21. GetPlayerName(playerid,namek,sizeof(namek));
  22. return namek;}
  23.  
  24. public OnGameModeInit(){
  25. mysqldb = mysql_connect(mysql_host,mysql_usuario,mysql_clave,mysql_db);
  26. if(mysqldb == MYSQL_INVALID_HANDLE || mysql_errno(mysqldb)!=0){
  27. print("There was a failure in the connection to the database");
  28. SendRconCommand("exit");}
  29. else {
  30. print("The connection to the database was successful.");}
  31. mysql_query(mysqldb,"CREATE TABLE IF NOT EXISTS `teles` (ID INTEGER PRIMARY KEY AUTO_INCREMENT, NOMBRETELE VARCHAR(24), POSX FLOAT, POSY FLOAT, POSZ FLOAT, Interior INT, Creador VARCHAR(24))",false);
  32. return 1;
  33. }
  34.  
  35. public OnGameModeExit(){
  36. mysql_close(mysqldb);
  37. return 1;
  38. }
  39.  
  40. //COMANDOS
  41. CMD:createteleport(playerid,params[]){
  42. new nombretele[12];
  43. if(sscanf(params,"s[16]",nombretele)) return SendClientMessage(playerid,-1,"*Use: /createteleport [name]");
  44. if(strlen(nombretele) > 15 || strlen(nombretele) < 3) return SendClientMessage(playerid,-1,"* Character numbers must be between <0-15>");
  45. new consult[120];
  46. mysql_format(mysqldb,consult,sizeof(consult),"SELECT * FROM teles WHERE NOMBRETELE = '%s'",nombretele);
  47. new Cache:R = mysql_query(mysqldb,consult,true);
  48. if(cache_num_rows()) return SendClientMessage(playerid,-1,"* A teleport with that name already exists.");
  49. new Float:Position[3];
  50. GetPlayerPos(playerid,Position[0],Position[1],Position[2]);
  51. new interiorXD = GetPlayerInterior(playerid);
  52. new string[120],query[180];
  53. mysql_format(mysqldb,query,sizeof(query),"INSERT INTO teles (NOMBRETELE,POSX,POSY,POSZ,Interior,Creador) VALUES ('%e','%f','%f','%f','%d','%e')",nombretele,Position[0],Position[1],Position[2],interiorXD,Nombre(playerid));
  54. mysql_query(mysqldb,query,false);
  55. format(string,sizeof(string),"{FFFFFF}New {00FF00}teleport {FFFFFF}created!\nName: '%s'\nTake a snapshot of this to remember!",nombretele);
  56. ShowPlayerDialog(playerid,SIN_USO,DIALOG_STYLE_MSGBOX,"Teleports",string,"Okay","");
  57. cache_delete(R);
  58. return 1;
  59. }
  60.  
  61. CMD:teleport(playerid,params[]){
  62. new telexd[12];
  63. if(sscanf(params,"s[12]",telexd)) return SendClientMessage(playerid,-1,"*Use: /teleport [name]");
  64. new query[120],nametele[12];
  65. mysql_format(mysqldb,query,sizeof(query),"SELECT * FROM teles WHERE NOMBRETELE = '%s'",telexd);
  66. new Cache:W = mysql_query(mysqldb,query,true);
  67. new Float:posxxd, Float:posyxd,Float:poszxd,interiorp;
  68. if(cache_num_rows()){
  69. cache_get_value_name(0,"NOMBRETELE",nametele);
  70. cache_get_value_name_float(0,"POSX",posxxd);
  71. cache_get_value_name_float(0,"POSY",posyxd);
  72. cache_get_value_name_float(0,"POSZ",poszxd);
  73. cache_get_value_name_int(0,"Interior",interiorp);
  74. SetPlayerPos(playerid,posxxd,posyxd,poszxd);
  75. new string[120];
  76. format(string,sizeof(string),"* You have teleported to the teleport: {00FF00}'%s'",nametele);
  77. }else SendClientMessage(playerid,-1,"* That teleport does not exist in our database.");
  78. cache_delete(W);
  79. return 1;
  80. }
  81.  
  82. CMD:deleteteleport(playerid,params[]){
  83. if(!IsPlayerAdmin(playerid)) return 0;
  84. new nombretele[12];
  85. if(sscanf(params,"s[12]",nombretele)) return SendClientMessage(playerid,-1,"*Use: /deleteteleport [name]");
  86. new query[120],string[50];
  87. mysql_format(mysqldb,query,sizeof(query),"DELETE FROM teles WHERE NOMBRETELE = '%s'",nombretele);
  88. mysql_query(mysqldb,query,false);
  89. format(string,sizeof(string),"You have removed the teleport: {FF0000}%s",nombretele);
  90. SendClientMessage(playerid,-1,string);
  91. return 1;
  92. }
  93.  
  94. COMMAND:teleports(playerid,params[]){// //teleports
  95. OFFSETXD[playerid] = 0;
  96. new nombretele[12],nombrecreador[24],lista[62+ 20 * (24+32+24+26)];
  97. new Cache: R = mysql_query(mysqldb,"SELECT `NOMBRETELE`,`Creador` FROM `teles` WHERE `ID` > -1 LIMIT 10");
  98. if(!cache_num_rows()){OFFSETXD[playerid] = 0;cache_delete(R);SendClientMessage(playerid,-1,"* There are no teleports in the database.");return 1;}
  99. strcat(lista,"{FFFFFF}#ID\t{FF0000}Name\t{00FF00}Creator\n");
  100. for(new i; i< cache_num_rows(); i++){
  101. cache_get_value_name(i,"NOMBRETELE",nombretele);
  102. cache_get_value_name(i,"Creador",nombrecreador);
  103. format(lista,sizeof(lista),"%s\n#%d\t%s\t%s\n",lista, i,nombretele,nombrecreador);
  104. }
  105. ShowPlayerDialog(playerid,DIALOGO_TELESXD,DIALOG_STYLE_TABLIST_HEADERS,"{FFFFFF}Teleports",lista,"+Teleports","Exit");
  106. return 1;
  107. }
  108.  
  109. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[]){
  110. if(dialogid == DIALOGO_TELESXD)
  111. {
  112. if(!response) return OFFSETXD[playerid] = 0;
  113. OFFSETXD[playerid] += 10;
  114. new nombretele[12],nombrecreador[24],lista[62+ 20 * (24+32+24+26)],query[128];
  115. mysql_format(mysqldb,query,sizeof(query),"SELECT `NOMBRETELE`,'Creador' FROM `teles` WHERE `ID` > 0 LIMIT 10 OFFSET %d",OFFSETXD[playerid]);
  116. new Cache:R = mysql_query(mysqldb,query,true);
  117. if(!cache_num_rows()){OFFSETXD[playerid] = 0;cache_delete(R);SendClientMessage(playerid,-1,"* There are no more teles in the database");return 1;}
  118. strcat(lista,"{FFFFFF}#ID\t{FF0000}Name\t{00FF00}Creator\n");
  119. new ekizde = OFFSETXD[playerid];
  120. for(new i; i < cache_num_rows(); i++){
  121. cache_get_value_name(i,"NOMBRETELE",nombretele);
  122. cache_get_value_name(i,"Creador",nombrecreador);
  123. format(lista,sizeof(lista),"%s\n#%d\t%s\t%s\n",lista,ekizde,nombretele,nombrecreador);
  124. ekizde ++;
  125. }
  126. ShowPlayerDialog(playerid,DIALOGO_TELESXD,DIALOG_STYLE_TABLIST_HEADERS,"{FFFFFF}Teleports",lista,"+Teleports","Exit");
  127. cache_delete(R);
  128. return 1;
  129. }
  130. return 1;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement