Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////////////Dynamic Teleport System///////////////////////////////
- //////////////////////////////////By Tony///////////////////////////////////////
- //////////////////////////////Created: 16.1.2016////////////////////////////////
- /////////////////////////Please don't remove credits////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- #include <a_samp>
- #include <zcmd>
- #include <sscanf2>
- #include <YSI\y_ini>
- #include <FileManager>
- #define DIALOG_TEDIT 32000
- #define DIALOG_CATEGORY 32001
- #define DIALOG_CLOCATION 32002
- #define DIALOG_DELETECAT 32003
- #define DIALOG_DELETELOC 32004
- #define DIALOG_CORDLOCATION 32005
- #define DIALOG_TELE 32006
- #define DIALOG_CTELE 32007
- #define DIALOG_MOVELOC 32008
- #define DIALOG_MOVECAT 32009
- #define TELE_PATH "/Locations/%s/%d.ini"
- #define MAX_TELE 100
- //Teleport
- enum tInfo
- {
- Name[90],
- Float:teX,
- Float:teY,
- Float:teZ,
- Float:teA
- }
- new TeleInfo[20][MAX_TELE][tInfo];
- new Category[20][90];
- new NameCat[MAX_PLAYERS][90];
- new IDCate=-1;
- new IDLoc=-1;
- new Cate=-1;
- stock udb_hash(buf[])
- {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++)
- {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- stock TelePath(id,katid)
- {
- new string[128];
- format(string,sizeof(string),TELE_PATH,Category[katid],id);
- return string;
- }
- stock SaveLocations2(id,katid)
- {
- new INI:File = INI_Open(TelePath(id-1,katid));
- INI_WriteString(File,"Name",TeleInfo[katid][id][Name]);
- INI_WriteFloat(File,"X",TeleInfo[katid][id][teX]);
- INI_WriteFloat(File,"Y",TeleInfo[katid][id][teY]);
- INI_WriteFloat(File,"Z",TeleInfo[katid][id][teZ]);
- INI_WriteFloat(File,"A",TeleInfo[katid][id][teA]);
- INI_Close(File);
- TeleInfo[katid][id][teX]=0;
- TeleInfo[katid][id][teY]=0;
- TeleInfo[katid][id][teZ]=0;
- TeleInfo[katid][id][teA]=0;
- return 1;
- }
- stock SaveLocations(id,katid)
- {
- new INI:File = INI_Open(TelePath(id,katid));
- INI_WriteString(File,"Name",TeleInfo[katid][id][Name]);
- INI_WriteFloat(File,"X",TeleInfo[katid][id][teX]);
- INI_WriteFloat(File,"Y",TeleInfo[katid][id][teY]);
- INI_WriteFloat(File,"Z",TeleInfo[katid][id][teZ]);
- INI_WriteFloat(File,"A",TeleInfo[katid][id][teA]);
- INI_Close(File);
- return 1;
- }
- stock SaveCategory()
- {
- new INI:File = INI_Open("Locations/Categorys.ini");
- for(new i=0;i<20;i++)
- {
- new string[90];
- format(string,sizeof(string),"Category_%d",i);
- INI_WriteString(File,string,Category[i]);
- }
- INI_Close(File);
- return 1;
- }
- stock SaveCategory2(id)
- {
- new INI:File = INI_Open("Locations/Categorys.ini");
- for(new i=id+1;i<20;i++)
- {
- new string[90];
- format(string,sizeof(string),"Category_%d",i-1);
- INI_WriteString(File,string,Category[i]);
- }
- INI_Close(File);
- return 1;
- }
- forward LoadCategorys(id,name[],value[]);
- public LoadCategorys(id,name[],value[])
- {
- new string[90];
- format(string,sizeof(string),"Category_%d",id);
- INI_String(string,Category[id],90);
- return 1;
- }
- forward LoadLocations(id,name[],value[]);
- public LoadLocations(id,name[],value[])
- {
- INI_String("Name",TeleInfo[IDCate][id][Name],90);
- INI_Float("X",TeleInfo[IDCate][id][teX]);
- INI_Float("Y",TeleInfo[IDCate][id][teY]);
- INI_Float("Z",TeleInfo[IDCate][id][teZ]);
- INI_Float("A",TeleInfo[IDCate][id][teA]);
- return 1;
- }
- forward Port(playerid);
- public Port(playerid)
- {
- TogglePlayerControllable(playerid,0);
- SetTimerEx("Unfreeze", 2000,false,"i",playerid);
- return 1;
- }
- forward Unfreeze(playerid);
- public Unfreeze(playerid)
- {
- TogglePlayerControllable(playerid, 1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i=0;i<MAX_TELE;i++)
- {
- for(new a=0;a<20;a++)
- {
- if(TeleInfo[a][i][teX] != 0 && TeleInfo[a][i][teY] != 0)
- {
- SaveLocations(i,a);
- }
- }
- }
- return 1;
- }
- public OnFilterScriptInit()
- {
- print("////////////////////////////////////////////////////////////////////////////////");
- print("//////////////////////////Dynamic Teleport System///////////////////////////////");
- print("//////////////////////////////////By Tony///////////////////////////////////////");
- print("//////////////////////////////Created: 16.1.2016////////////////////////////////");
- print("/////////////////////////Please don't remove credits////////////////////////////");
- print("////////////////////////////////////////////////////////////////////////////////");
- for(new j=0;j<20;j++)
- {
- strmid(Category[j],"Empty",0,strlen("Empty"),255);
- INI_ParseFile("Locations/Categorys.ini", "LoadCategorys", .bExtra = true, .extra = j);
- for(new i = 0; i < sizeof(TeleInfo); i++)
- {
- strmid(TeleInfo[j][i][Name],"a",0,strlen("a"),255);
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[j],i);
- if(fexist(str))
- {
- IDCate=j;
- INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = i);
- }
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == DIALOG_CATEGORY)
- {
- new name[90];
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_CATEGORY, DIALOG_STYLE_INPUT, "Name", "Enter the name of category", "Okay", "Cancel");
- for(new i=0;i<20;i++)
- {
- if(udb_hash(Category[i]) != udb_hash(name))
- {
- if(udb_hash(Category[i]) == udb_hash("Empty"))
- {
- new str[128];
- format(str,sizeof(str),"scriptfiles/Locations/%s",name);
- if(dir_create(str))
- {
- strmid(Category[i],name,0,strlen(name),255);
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Successfully added category!");
- }
- else
- {
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Unsuccessfully added category!");
- }
- SaveCategory();
- break;
- }
- }else return SendClientMessage(playerid, -1, "{ff0000}[ERROR] {FFFFFF}Category with that name already exists!");
- }
- }
- if(dialogid == DIALOG_CLOCATION)
- {
- new name[90],check=0;
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_CLOCATION, DIALOG_STYLE_INPUT, "Enter the name of category", "Enter the name of the category under which you want to put a new location!", "Okay", "Cancel");
- for(new i=0;i<20;i++)
- {
- if(udb_hash(Category[i]) == udb_hash(name))
- {
- strmid(NameCat[playerid],Category[i],0,strlen(Category[i]),255);
- ShowPlayerDialog(playerid, DIALOG_CORDLOCATION, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
- check=1;
- break;
- }
- }
- if(check==0) return ShowPlayerDialog(playerid, DIALOG_CLOCATION, DIALOG_STYLE_INPUT, "Enter the name of category", "Enter the name of the category under which you want to put a new location!", "Okay", "Cancel");
- }
- if(dialogid == DIALOG_CORDLOCATION)
- {
- new name[90],j=-1;
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_CORDLOCATION, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
- for(new i=0;i<sizeof(TeleInfo);i++)
- {
- for(new e=0;e<20;e++)
- {
- if(udb_hash(Category[e]) == udb_hash(NameCat[playerid]))
- {
- j=e;
- }
- }
- if(!fexist(TelePath(i,j)))
- {
- new Float:Poz[4];
- GetPlayerPos(playerid,Poz[0],Poz[1],Poz[2]);
- GetPlayerFacingAngle(playerid,Poz[3]);
- strmid(TeleInfo[j][i][Name],name,0,strlen(name),255);
- TeleInfo[j][i][teX]=Poz[0];
- TeleInfo[j][i][teY]=Poz[1];
- TeleInfo[j][i][teZ]=Poz[2];
- TeleInfo[j][i][teA]=Poz[3];
- SaveLocations(i,j);
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Successfully added location!");
- break;
- }
- }
- }
- if(dialogid == DIALOG_DELETECAT)
- {
- new name[90];
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_DELETECAT, DIALOG_STYLE_INPUT, "Name", "Enter name of category to delete", "Okay", "Cancel");
- for(new i=0;i<20;i++)
- {
- if(udb_hash(Category[i]) == udb_hash(name) && udb_hash(Category[i]) != udb_hash("Empty"))
- {
- new str[128];
- format(str,sizeof(str),"scriptfiles/Locations/%s",name);
- for(new j=0;j<sizeof(TeleInfo);j++)
- {
- new str2[128];
- format(str2,sizeof(str2),"Locations/%s/%d.ini",Category[i],j);
- if(fexist(str2))
- {
- TeleInfo[i][j][teX] = 0;
- TeleInfo[i][j][teY] = 0;
- TeleInfo[i][j][teZ] = 0;
- TeleInfo[i][j][teA] = 0;
- strmid(TeleInfo[i][j][Name],"a",0,strlen("a"),255);
- fremove(str2);
- }
- }
- if(dir_delete(str))
- {
- strmid(Category[i],"Empty",0,strlen("Empty"),255);
- SaveCategory2(i);
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Category is deleted!");
- for(new j=0;j<20;j++)
- {
- strmid(Category[j],"Empty",0,strlen("Empty"),255);
- INI_ParseFile("Locations/Categorys.ini", "LoadCategorys", .bExtra = true, .extra = j);
- for(new eh = 0; eh < sizeof(TeleInfo); eh++)
- {
- new str3[128];
- format(str3,sizeof(str3),"Locations/%s/%d.ini",Category[j],eh);
- if(fexist(str3))
- {
- TeleInfo[j][eh][teX] = 0;
- TeleInfo[j][eh][teY] = 0;
- TeleInfo[j][eh][teZ] = 0;
- TeleInfo[j][eh][teA] = 0;
- strmid(TeleInfo[j][eh][Name],"a",0,strlen("a"),255);
- IDCate=j;
- INI_ParseFile(str3, "LoadLocations", .bExtra = true, .extra = eh);
- }
- }
- }
- }
- else
- {
- SendClientMessage(playerid,-1,"{ff0000}[ERROR] {FFFFFF}Folder does not exist!");
- }
- break;
- }
- }
- }
- if(dialogid == DIALOG_DELETELOC)
- {
- new name[90],check=0;
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
- for(new i=0;i<sizeof(TeleInfo);i++)
- {
- for(new a=0;a<20;a++)
- {
- if(udb_hash(TeleInfo[a][i][Name]) == udb_hash(name))
- {
- TeleInfo[a][i][teX] = 0;
- TeleInfo[a][i][teY] = 0;
- TeleInfo[a][i][teZ] = 0;
- TeleInfo[a][i][teA] = 0;
- strmid(TeleInfo[a][i][Name],"a",0,strlen("a"),255);
- fremove(TelePath(i,a));
- check=1;
- new id=i;
- for(new j=id+1;j<sizeof(TeleInfo);j++)
- {
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[a],j);
- if(fexist(str))
- {
- fremove(str);
- SaveLocations2(j,a);
- }
- }
- for(new k=0;k<sizeof(TeleInfo);k++)
- {
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[a],k);
- strmid(TeleInfo[a][k][Name],"a",0,strlen("a"),255);
- IDCate=a;
- INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = k);
- }
- }
- }
- }
- if(check==0) return ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Wrong name", "Enter the name of location!", "Okay", "Cancel");
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Successfully deleted location!");
- }
- if(dialogid == DIALOG_MOVELOC)
- {
- new name[90],check=0;
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_MOVELOC, DIALOG_STYLE_INPUT, "Name", "Enter the name of location which you want move", "Okay", "Cancel");
- for(new a=0;a<20;a++)
- {
- for(new i=0;i<sizeof(TeleInfo);i++)
- {
- if(udb_hash(TeleInfo[a][i][Name]) == udb_hash(name) && udb_hash(TeleInfo[a][i][Name]) != udb_hash("a"))
- {
- IDCate=a;
- IDLoc=i;
- ShowPlayerDialog(playerid, DIALOG_MOVECAT, DIALOG_STYLE_INPUT, "Name", "Enter the name of category where you want to move selected location", "Okay", "Cancel");
- check=1;
- break;
- }
- }
- }
- if(check==0) return ShowPlayerDialog(playerid, DIALOG_MOVELOC, DIALOG_STYLE_INPUT, "Wrong Name", "Enter the name of location which you want move", "Okay", "Cancel");
- }
- if(dialogid == DIALOG_MOVECAT)
- {
- new name[90],check=0;
- if(!response) return 1;
- if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_MOVECAT, DIALOG_STYLE_INPUT, "Name", "Enter the name of category where you want to move selected location", "Okay", "Cancel");
- for(new e=0;e<20;e++)
- {
- if(udb_hash(Category[e]) == udb_hash(name))
- {
- for(new j=0;j<sizeof(TeleInfo);j++)
- {
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[e],j);
- if(!fexist(str))
- {
- strmid(TeleInfo[e][j][Name],TeleInfo[IDCate][IDLoc][Name],0,strlen(TeleInfo[IDCate][IDLoc][Name]),255);
- TeleInfo[e][j][teX]=TeleInfo[IDCate][IDLoc][teX];
- TeleInfo[e][j][teY]=TeleInfo[IDCate][IDLoc][teY];
- TeleInfo[e][j][teZ]=TeleInfo[IDCate][IDLoc][teZ];
- TeleInfo[e][j][teA]=TeleInfo[IDCate][IDLoc][teA];
- SaveLocations(j,e);
- check=1;
- break;
- }
- }
- }
- }
- TeleInfo[IDCate][IDLoc][teX] = 0;
- TeleInfo[IDCate][IDLoc][teY] = 0;
- TeleInfo[IDCate][IDLoc][teZ] = 0;
- TeleInfo[IDCate][IDLoc][teA] = 0;
- strmid(TeleInfo[IDCate][IDLoc][Name],"a",0,strlen("a"),255);
- fremove(TelePath(IDLoc,IDCate));
- new id=IDLoc;
- for(new j=id+1;j<sizeof(TeleInfo);j++)
- {
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[IDCate],j);
- if(fexist(str))
- {
- fremove(str);
- SaveLocations2(j,IDCate);
- }
- }
- for(new k=0;k<sizeof(TeleInfo);k++)
- {
- new str[128];
- format(str,sizeof(str),"Locations/%s/%d.ini",Category[IDCate],k);
- strmid(TeleInfo[IDCate][k][Name],"a",0,strlen("a"),255);
- INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = k);
- }
- if(check==0) return ShowPlayerDialog(playerid, DIALOG_MOVECAT, DIALOG_STYLE_INPUT, "Wrong Name", "Enter the name of category where you want to move selected location", "Okay", "Cancel");
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Successfully moved location!");
- }
- if(dialogid == DIALOG_TEDIT)
- {
- if(response)
- {
- if(listitem == 0)
- {
- ShowPlayerDialog(playerid, DIALOG_CATEGORY, DIALOG_STYLE_INPUT, "Name", "Enter the name of category", "Okay", "Cancel");
- }
- if(listitem == 1)
- {
- SendClientMessage(playerid,-1,"{FF9900}[Info] {FFFFFF}Location will save on your current coordinates!");
- ShowPlayerDialog(playerid, DIALOG_CLOCATION, DIALOG_STYLE_INPUT, "Name of category", "Enter the name of category where you want to put location!", "Okay", "Cancel");
- }
- if(listitem == 2)
- {
- ShowPlayerDialog(playerid, DIALOG_DELETECAT, DIALOG_STYLE_INPUT, "Name", "Enter name of category to delete", "Okay", "Cancel");
- }
- if(listitem == 3)
- {
- ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Name", "Enter the name of location", "Okay", "Cancel");
- }
- if(listitem == 4)
- {
- ShowPlayerDialog(playerid, DIALOG_MOVELOC, DIALOG_STYLE_INPUT, "Name", "Enter the name of location which you want to move", "Okay", "Cancel");
- }
- }
- }
- if(dialogid == DIALOG_TELE)
- {
- if(response)
- {
- new id=listitem;
- if(IsPlayerInAnyVehicle(playerid))
- {
- SetVehiclePos(GetPlayerVehicleID(playerid), TeleInfo[Cate][id][teX],TeleInfo[Cate][id][teY],TeleInfo[Cate][id][teZ]);
- SetVehicleZAngle(GetPlayerVehicleID(playerid),TeleInfo[Cate][id][teA]);
- PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), 0);
- }
- else
- {
- SetPlayerPos(playerid,TeleInfo[Cate][id][teX],TeleInfo[Cate][id][teY],TeleInfo[Cate][id][teZ]);
- SetPlayerFacingAngle(playerid, TeleInfo[Cate][id][teA]);
- }
- Port(playerid);
- new str[128];
- format(str,sizeof(str),"{FF9900}You are teleported to {FFFFFF}%s!",TeleInfo[Cate][id][Name]);
- SendClientMessage(playerid,-1,str);
- }
- }
- if(dialogid == DIALOG_CTELE)
- {
- if(response)
- {
- Cate=listitem;
- new info[2100];
- for(new i=0;i<MAX_TELE;i++)
- {
- if(TeleInfo[Cate][i][teX] != 0 && TeleInfo[Cate][i][teY] != 0)
- {
- new str[128];
- format(str,sizeof(str),"%s\n",TeleInfo[Cate][i][Name]);
- strcat(info, str, sizeof(info));
- }
- }
- ShowPlayerDialog(playerid, DIALOG_TELE, DIALOG_STYLE_LIST, "Teleport", info, "Okay", "Cancel");
- }
- }
- return 1;
- }
- CMD:edittele(playerid,params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"[#Sikora] Just rcon admin!");
- if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,-1,"[#Sikora] You may not be in the vehicle!");
- ShowPlayerDialog(playerid, DIALOG_TEDIT, DIALOG_STYLE_LIST, "Edit", "Add category\nAdd location\nDelete category\nDelete location\nMove location", "Okay", "Cancel");
- return 1;
- }
- CMD:tele(playerid, params[])
- {
- if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid,-1,"You are not connected!");
- new info[1024];
- for(new i=0;i<20;i++)
- {
- if(udb_hash(Category[i]) != udb_hash("Empty"))
- {
- new str[128];
- format(str,sizeof(str),"%s\n",Category[i]);
- strcat(info, str, sizeof(info));
- }
- }
- ShowPlayerDialog(playerid, DIALOG_CTELE, DIALOG_STYLE_LIST, "Teleport", info, "Next", "Cancel");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement