Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /System dynamic teleports SOLVER PROBLEMS. 14-10-2018
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- new MySQL:mysqldb;
- #define mysql_host "localhost"
- #define mysql_usuario "root"
- #define mysql_clave ""
- #define mysql_db "basededatosxd"
- new OFFSETXD[MAX_PLAYERS];
- new enum {
- SIN_USO,
- DIALOG_TELESXD,
- }
- stock Nombre(playerid){
- new namek[24];
- GetPlayerName(playerid,namek,sizeof(namek));
- return namek;}
- public OnGameModeInit(){
- mysqldb = mysql_connect(mysql_host,mysql_usuario,mysql_clave,mysql_db);
- if(mysqldb == MYSQL_INVALID_HANDLE || mysql_errno(mysqldb)!=0){
- print("There was a failure in the connection to the database");
- SendRconCommand("exit");}
- else {
- print("The connection to the database was successful.");}
- 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);
- return 1;
- }
- public OnGameModeExit(){
- mysql_close(mysqldb);
- return 1;
- }
- //COMANDOS
- CMD:createteleport(playerid,params[]){
- new nombretele[12];
- if(sscanf(params,"s[16]",nombretele)) return SendClientMessage(playerid,-1,"*Use: /createteleport [name]");
- if(strlen(nombretele) > 15 || strlen(nombretele) < 3) return SendClientMessage(playerid,-1,"* Character numbers must be between <0-15>");
- new consult[120];
- mysql_format(mysqldb,consult,sizeof(consult),"SELECT * FROM teles WHERE NOMBRETELE = '%s'",nombretele);
- new Cache:R = mysql_query(mysqldb,consult,true);
- if(cache_num_rows()) return SendClientMessage(playerid,-1,"* A teleport with that name already exists.");
- new Float:Position[3];
- GetPlayerPos(playerid,Position[0],Position[1],Position[2]);
- new interiorXD = GetPlayerInterior(playerid);
- new string[120],query[180];
- 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));
- mysql_query(mysqldb,query,false);
- format(string,sizeof(string),"{FFFFFF}New {00FF00}teleport {FFFFFF}created!\nName: '%s'\nTake a snapshot of this to remember!",nombretele);
- ShowPlayerDialog(playerid,SIN_USO,DIALOG_STYLE_MSGBOX,"Teleports",string,"Okay","");
- cache_delete(R);
- return 1;
- }
- CMD:teleport(playerid,params[]){
- new telexd[12];
- if(sscanf(params,"s[12]",telexd)) return SendClientMessage(playerid,-1,"*Use: /teleport [name]");
- new query[120],nametele[12];
- mysql_format(mysqldb,query,sizeof(query),"SELECT * FROM teles WHERE NOMBRETELE = '%s'",telexd);
- new Cache:W = mysql_query(mysqldb,query,true);
- new Float:posxxd, Float:posyxd,Float:poszxd,interiorp;
- if(cache_num_rows()){
- cache_get_value_name(0,"NOMBRETELE",nametele);
- cache_get_value_name_float(0,"POSX",posxxd);
- cache_get_value_name_float(0,"POSY",posyxd);
- cache_get_value_name_float(0,"POSZ",poszxd);
- cache_get_value_name_int(0,"Interior",interiorp);
- SetPlayerPos(playerid,posxxd,posyxd,poszxd);
- new string[120];
- format(string,sizeof(string),"* You have teleported to the teleport: {00FF00}'%s'",nametele);
- }else SendClientMessage(playerid,-1,"* That teleport does not exist in our database.");
- cache_delete(W);
- return 1;
- }
- CMD:deleteteleport(playerid,params[]){
- if(!IsPlayerAdmin(playerid)) return 0;
- new nombretele[12];
- if(sscanf(params,"s[12]",nombretele)) return SendClientMessage(playerid,-1,"*Use: /deleteteleport [name]");
- new query[120],string[50];
- mysql_format(mysqldb,query,sizeof(query),"DELETE FROM teles WHERE NOMBRETELE = '%s'",nombretele);
- mysql_query(mysqldb,query,false);
- format(string,sizeof(string),"You have removed the teleport: {FF0000}%s",nombretele);
- SendClientMessage(playerid,-1,string);
- return 1;
- }
- COMMAND:teleports(playerid,params[]){// //teleports
- OFFSETXD[playerid] = 0;
- new nombretele[12],nombrecreador[24],lista[62+ 20 * (24+32+24+26)];
- new Cache: R = mysql_query(mysqldb,"SELECT `NOMBRETELE`,`Creador` FROM `teles` WHERE `ID` > -1 LIMIT 10");
- if(!cache_num_rows()){OFFSETXD[playerid] = 0;cache_delete(R);SendClientMessage(playerid,-1,"* There are no teleports in the database.");return 1;}
- strcat(lista,"{FFFFFF}#ID\t{FF0000}Name\t{00FF00}Creator\n");
- for(new i; i< cache_num_rows(); i++){
- cache_get_value_name(i,"NOMBRETELE",nombretele);
- cache_get_value_name(i,"Creador",nombrecreador);
- format(lista,sizeof(lista),"%s\n#%d\t%s\t%s\n",lista, i,nombretele,nombrecreador);
- }
- ShowPlayerDialog(playerid,DIALOGO_TELESXD,DIALOG_STYLE_TABLIST_HEADERS,"{FFFFFF}Teleports",lista,"+Teleports","Exit");
- return 1;
- }
- public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[]){
- if(dialogid == DIALOGO_TELESXD)
- {
- if(!response) return OFFSETXD[playerid] = 0;
- OFFSETXD[playerid] += 10;
- new nombretele[12],nombrecreador[24],lista[62+ 20 * (24+32+24+26)],query[128];
- mysql_format(mysqldb,query,sizeof(query),"SELECT `NOMBRETELE`,'Creador' FROM `teles` WHERE `ID` > 0 LIMIT 10 OFFSET %d",OFFSETXD[playerid]);
- new Cache:R = mysql_query(mysqldb,query,true);
- if(!cache_num_rows()){OFFSETXD[playerid] = 0;cache_delete(R);SendClientMessage(playerid,-1,"* There are no more teles in the database");return 1;}
- strcat(lista,"{FFFFFF}#ID\t{FF0000}Name\t{00FF00}Creator\n");
- new ekizde = OFFSETXD[playerid];
- for(new i; i < cache_num_rows(); i++){
- cache_get_value_name(i,"NOMBRETELE",nombretele);
- cache_get_value_name(i,"Creador",nombrecreador);
- format(lista,sizeof(lista),"%s\n#%d\t%s\t%s\n",lista,ekizde,nombretele,nombrecreador);
- ekizde ++;
- }
- ShowPlayerDialog(playerid,DIALOGO_TELESXD,DIALOG_STYLE_TABLIST_HEADERS,"{FFFFFF}Teleports",lista,"+Teleports","Exit");
- cache_delete(R);
- return 1;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement