Advertisement
TonyVk

Dynamic Teleport System

Jan 16th, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.54 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////Dynamic Teleport System///////////////////////////////
  3. //////////////////////////////////By Tony///////////////////////////////////////
  4. //////////////////////////////Created: 16.1.2016////////////////////////////////
  5. /////////////////////////Please don't remove credits////////////////////////////
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include <a_samp>
  9. #include <zcmd>
  10. #include <sscanf2>
  11. #include <YSI\y_ini>
  12. #include <FileManager>
  13.  
  14.  
  15. #define DIALOG_TEDIT 32000
  16. #define DIALOG_CATEGORY 32001
  17. #define DIALOG_CLOCATION 32002
  18. #define DIALOG_DELETECAT 32003
  19. #define DIALOG_DELETELOC 32004
  20. #define DIALOG_CORDLOCATION 32005
  21. #define DIALOG_TELE 32006
  22. #define DIALOG_CTELE 32007
  23. #define DIALOG_MOVELOC 32008
  24. #define DIALOG_MOVECAT 32009
  25. #define TELE_PATH "/Locations/%s/%d.ini"
  26.  
  27.  
  28. #define MAX_TELE 100
  29. //Teleport
  30. enum tInfo
  31. {
  32. Name[90],
  33. Float:teX,
  34. Float:teY,
  35. Float:teZ,
  36. Float:teA
  37. }
  38. new TeleInfo[20][MAX_TELE][tInfo];
  39. new Category[20][90];
  40. new NameCat[MAX_PLAYERS][90];
  41. new IDCate=-1;
  42. new IDLoc=-1;
  43. new Cate=-1;
  44.  
  45.  
  46. stock udb_hash(buf[])
  47. {
  48. new length=strlen(buf);
  49. new s1 = 1;
  50. new s2 = 0;
  51. new n;
  52. for (n=0; n<length; n++)
  53. {
  54. s1 = (s1 + buf[n]) % 65521;
  55. s2 = (s2 + s1) % 65521;
  56. }
  57. return (s2 << 16) + s1;
  58. }
  59.  
  60. stock TelePath(id,katid)
  61. {
  62. new string[128];
  63. format(string,sizeof(string),TELE_PATH,Category[katid],id);
  64. return string;
  65. }
  66.  
  67. stock SaveLocations2(id,katid)
  68. {
  69. new INI:File = INI_Open(TelePath(id-1,katid));
  70. INI_WriteString(File,"Name",TeleInfo[katid][id][Name]);
  71. INI_WriteFloat(File,"X",TeleInfo[katid][id][teX]);
  72. INI_WriteFloat(File,"Y",TeleInfo[katid][id][teY]);
  73. INI_WriteFloat(File,"Z",TeleInfo[katid][id][teZ]);
  74. INI_WriteFloat(File,"A",TeleInfo[katid][id][teA]);
  75. INI_Close(File);
  76. TeleInfo[katid][id][teX]=0;
  77. TeleInfo[katid][id][teY]=0;
  78. TeleInfo[katid][id][teZ]=0;
  79. TeleInfo[katid][id][teA]=0;
  80. return 1;
  81. }
  82.  
  83. stock SaveLocations(id,katid)
  84. {
  85. new INI:File = INI_Open(TelePath(id,katid));
  86. INI_WriteString(File,"Name",TeleInfo[katid][id][Name]);
  87. INI_WriteFloat(File,"X",TeleInfo[katid][id][teX]);
  88. INI_WriteFloat(File,"Y",TeleInfo[katid][id][teY]);
  89. INI_WriteFloat(File,"Z",TeleInfo[katid][id][teZ]);
  90. INI_WriteFloat(File,"A",TeleInfo[katid][id][teA]);
  91. INI_Close(File);
  92. return 1;
  93. }
  94.  
  95. stock SaveCategory()
  96. {
  97. new INI:File = INI_Open("Locations/Categorys.ini");
  98. for(new i=0;i<20;i++)
  99. {
  100. new string[90];
  101. format(string,sizeof(string),"Category_%d",i);
  102. INI_WriteString(File,string,Category[i]);
  103. }
  104. INI_Close(File);
  105. return 1;
  106. }
  107.  
  108. forward LoadCategorys(id,name[],value[]);
  109. public LoadCategorys(id,name[],value[])
  110. {
  111. new string[90];
  112. format(string,sizeof(string),"Category_%d",id);
  113. INI_String(string,Category[id],90);
  114. return 1;
  115. }
  116.  
  117.  
  118. forward LoadLocations(id,name[],value[]);
  119. public LoadLocations(id,name[],value[])
  120. {
  121. INI_String("Name",TeleInfo[IDCate][id][Name],90);
  122. INI_Float("X",TeleInfo[IDCate][id][teX]);
  123. INI_Float("Y",TeleInfo[IDCate][id][teY]);
  124. INI_Float("Z",TeleInfo[IDCate][id][teZ]);
  125. INI_Float("A",TeleInfo[IDCate][id][teA]);
  126. return 1;
  127. }
  128.  
  129. forward Port(playerid);
  130. public Port(playerid)
  131. {
  132. TogglePlayerControllable(playerid,0);
  133. SetTimerEx("Unfreeze", 2000,false,"i",playerid);
  134. return 1;
  135. }
  136.  
  137. forward Unfreeze(playerid);
  138. public Unfreeze(playerid)
  139. {
  140. TogglePlayerControllable(playerid, 1);
  141. return 1;
  142. }
  143.  
  144. public OnFilterScriptExit()
  145. {
  146. for(new i=0;i<MAX_TELE;i++)
  147. {
  148. for(new a=0;a<20;a++)
  149. {
  150. if(TeleInfo[a][i][teX] != 0 && TeleInfo[a][i][teY] != 0)
  151. {
  152. SaveLocations(i,a);
  153. }
  154. }
  155. }
  156. return 1;
  157. }
  158.  
  159. public OnFilterScriptInit()
  160. {
  161. print("////////////////////////////////////////////////////////////////////////////////");
  162. print("//////////////////////////Dynamic Teleport System///////////////////////////////");
  163. print("//////////////////////////////////By Tony///////////////////////////////////////");
  164. print("//////////////////////////////Created: 16.1.2016////////////////////////////////");
  165. print("/////////////////////////Please don't remove credits////////////////////////////");
  166. print("////////////////////////////////////////////////////////////////////////////////");
  167. for(new j=0;j<20;j++)
  168. {
  169. strmid(Category[j],"Empty",0,strlen("Empty"),255);
  170. INI_ParseFile("Locations/Categorys.ini", "LoadCategorys", .bExtra = true, .extra = j);
  171. for(new i = 0; i < sizeof(TeleInfo); i++)
  172. {
  173. new str[128];
  174. format(str,sizeof(str),"Locations/%s/%d.ini",Category[j],i);
  175. if(fexist(str))
  176. {
  177. IDCate=j;
  178. INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = i);
  179. }
  180. }
  181. }
  182. return 1;
  183. }
  184.  
  185. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  186. {
  187. if(dialogid == DIALOG_CATEGORY)
  188. {
  189. new name[90];
  190. if(!response) return 1;
  191. if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_CATEGORY, DIALOG_STYLE_INPUT, "Name", "Enter the name of category", "Okay", "Cancel");
  192. for(new i=0;i<20;i++)
  193. {
  194. if(udb_hash(Category[i]) == udb_hash("Empty"))
  195. {
  196. new str[128];
  197. format(str,sizeof(str),"scriptfiles/Locations/%s",name);
  198. if(dir_create(str))
  199. {
  200. printf("[SUCCESSFULLY]: Folder '%s' created!",name);
  201. strmid(Category[i],name,0,strlen(name),255);
  202. SendClientMessage(playerid,-1,"Successfully add category!");
  203. }
  204. else
  205. {
  206. print("[UNSUCCESSFULLY]: Folder is not created!");
  207. SendClientMessage(playerid,-1,"Unsuccessfully added category!");
  208. }
  209. SaveCategory();
  210. break;
  211. }
  212. }
  213. }
  214. if(dialogid == DIALOG_CLOCATION)
  215. {
  216. new name[90],check=0;
  217. if(!response) return 1;
  218. 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");
  219. for(new i=0;i<20;i++)
  220. {
  221. if(udb_hash(Category[i]) == udb_hash(name))
  222. {
  223. strmid(NameCat[playerid],Category[i],0,strlen(Category[i]),255);
  224. ShowPlayerDialog(playerid, DIALOG_CORDLOCATION, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
  225. check=1;
  226. break;
  227. }
  228. }
  229. 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");
  230. }
  231. if(dialogid == DIALOG_CORDLOCATION)
  232. {
  233. new name[90],j=-1;
  234. if(!response) return 1;
  235. if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_CORDLOCATION, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
  236. for(new i=0;i<sizeof(TeleInfo);i++)
  237. {
  238. for(new e=0;e<20;e++)
  239. {
  240. if(udb_hash(Category[e]) == udb_hash(NameCat[playerid]))
  241. {
  242. j=e;
  243. }
  244. }
  245. if(!fexist(TelePath(i,j)))
  246. {
  247. new Float:Poz[4];
  248. GetPlayerPos(playerid,Poz[0],Poz[1],Poz[2]);
  249. GetPlayerFacingAngle(playerid,Poz[3]);
  250. strmid(TeleInfo[j][i][Name],name,0,strlen(name),255);
  251. TeleInfo[j][i][teX]=Poz[0];
  252. TeleInfo[j][i][teY]=Poz[1];
  253. TeleInfo[j][i][teZ]=Poz[2];
  254. TeleInfo[j][i][teA]=Poz[3];
  255. SaveLocations(i,j);
  256. SendClientMessage(playerid,-1,"Successfully added location!");
  257. break;
  258. }
  259. }
  260. }
  261. //SOON
  262. /*if(dialogid == DIALOG_DELETECAT)
  263. {
  264. new ime[90];
  265. if(!response) return 1;
  266. if(sscanf(inputtext,"s[90]",ime)) return ShowPlayerDialog(playerid, DIALOG_DELETECAT, DIALOG_STYLE_INPUT, "Ime", "Upisite ime kategorije koju zelite obrisati", "Uredu", "Odustani");
  267. for(new i=0;i<20;i++)
  268. {
  269. if(udb_hash(Category[i]) == udb_hash(ime))
  270. {
  271. new str[128];
  272. format(str,sizeof(str),"scriptfiles/Lokacije/%s",ime);
  273. if(dir_delete(str))
  274. {
  275. strmid(Category[i],"Nema",0,strlen("Nema"),255);
  276. printf("[USPJESNO]: Folder '%s' obrisan",ime);
  277. SendClientMessage(playerid,-1,"Uspjesno obrisana kategorija!");
  278. }
  279. else
  280. {
  281. SendClientMessage(playerid,-1,"[NEUSPJESNO]: Folder ne postoji ili se u njemu nalaze neke lokacije(premjestite ih preko GPanela negdje u drugu kategoriju(folder)!");
  282. }
  283. break;
  284. }
  285. }
  286. }*/
  287. if(dialogid == DIALOG_DELETELOC)
  288. {
  289. new name[90],check=0;
  290. if(!response) return 1;
  291. if(sscanf(inputtext,"s[90]",name)) return ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Enter the name", "Enter the name of location!", "Okay", "Cancel");
  292. for(new i=0;i<sizeof(TeleInfo);i++)
  293. {
  294. for(new a=0;a<20;a++)
  295. {
  296. if(udb_hash(TeleInfo[a][i][Name]) == udb_hash(name))
  297. {
  298. TeleInfo[a][i][teX] = 0;
  299. TeleInfo[a][i][teY] = 0;
  300. TeleInfo[a][i][teZ] = 0;
  301. TeleInfo[a][i][teA] = 0;
  302. fremove(TelePath(i,a));
  303. check=1;
  304. new id=i;
  305. for(new j=id+1;j<sizeof(TeleInfo);j++)
  306. {
  307. new str[128];
  308. format(str,sizeof(str),"Locations/%s/%d.ini",Category[a],j);
  309. if(fexist(str))
  310. {
  311. fremove(str);
  312. SaveLocations2(j,a);
  313. }
  314. }
  315. for(new k=0;k<sizeof(TeleInfo);k++)
  316. {
  317. new str[128];
  318. format(str,sizeof(str),"Locations/%s/%d.ini",Category[a],k);
  319. IDCate=a;
  320. INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = k);
  321. }
  322. }
  323. }
  324. }
  325. if(check==0) return ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Wrong name", "Enter the name of location!", "Okay", "Cancel");
  326. SendClientMessage(playerid,-1,"Successfully added location!");
  327. }
  328. if(dialogid == DIALOG_MOVELOC)
  329. {
  330. new name[90],check=0;
  331. if(!response) return 1;
  332. 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");
  333. for(new i=0;i<sizeof(TeleInfo);i++)
  334. {
  335. for(new a=0;a<20;a++)
  336. {
  337. if(udb_hash(TeleInfo[a][i][Name]) == udb_hash(name))
  338. {
  339. IDCate=a;
  340. IDLoc=i;
  341. ShowPlayerDialog(playerid, DIALOG_MOVECAT, DIALOG_STYLE_INPUT, "Name", "Enter the name of category where you want to move selected location", "Okay", "Cancel");
  342. check=1;
  343. }
  344. }
  345. }
  346. if(check==0) return ShowPlayerDialog(playerid, DIALOG_MOVELOC, DIALOG_STYLE_INPUT, "Wrong Name", "Enter the name of location which you want move", "Okay", "Cancel");
  347. }
  348.  
  349. if(dialogid == DIALOG_MOVECAT)
  350. {
  351. new name[90],check=0;
  352. if(!response) return 1;
  353. 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");
  354. for(new e=0;e<20;e++)
  355. {
  356. if(udb_hash(Category[e]) == udb_hash(name))
  357. {
  358. for(new j=0;j<sizeof(TeleInfo);j++)
  359. {
  360. new str[128];
  361. format(str,sizeof(str),"Locations/%s/%d.ini",Category[e],j);
  362. if(!fexist(str))
  363. {
  364. strmid(TeleInfo[e][j][Name],TeleInfo[IDCate][IDLoc][Name],0,strlen(TeleInfo[IDCate][IDLoc][Name]),255);
  365. TeleInfo[e][j][teX]=TeleInfo[IDCate][IDLoc][teX];
  366. TeleInfo[e][j][teY]=TeleInfo[IDCate][IDLoc][teY];
  367. TeleInfo[e][j][teZ]=TeleInfo[IDCate][IDLoc][teZ];
  368. TeleInfo[e][j][teA]=TeleInfo[IDCate][IDLoc][teA];
  369. SaveLocations(j,e);
  370. check=1;
  371. break;
  372. }
  373. }
  374. }
  375. }
  376. TeleInfo[IDCate][IDLoc][teX] = 0;
  377. TeleInfo[IDCate][IDLoc][teY] = 0;
  378. TeleInfo[IDCate][IDLoc][teZ] = 0;
  379. TeleInfo[IDCate][IDLoc][teA] = 0;
  380. fremove(TelePath(IDLoc,IDCate));
  381. new id=IDLoc;
  382. for(new j=id+1;j<sizeof(TeleInfo);j++)
  383. {
  384. new str[128];
  385. format(str,sizeof(str),"Locations/%s/%d.ini",Category[IDCate],j);
  386. if(fexist(str))
  387. {
  388. fremove(str);
  389. SaveLocations2(j,IDCate);
  390. }
  391. }
  392. for(new k=0;k<sizeof(TeleInfo);k++)
  393. {
  394. new str[128];
  395. format(str,sizeof(str),"Locations/%s/%d.ini",Category[IDCate],k);
  396. INI_ParseFile(str, "LoadLocations", .bExtra = true, .extra = k);
  397. }
  398. 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");
  399. SendClientMessage(playerid,-1,"Successfully moved location!");
  400. }
  401. if(dialogid == DIALOG_TEDIT)
  402. {
  403. if(response)
  404. {
  405. if(listitem == 0)
  406. {
  407. ShowPlayerDialog(playerid, DIALOG_CATEGORY, DIALOG_STYLE_INPUT, "Name", "Enter the name of category", "Okay", "Cancel");
  408. }
  409. if(listitem == 1)
  410. {
  411. SendClientMessage(playerid,-1,"Warning: Location will save on your current coordinates!");
  412. ShowPlayerDialog(playerid, DIALOG_CLOCATION, DIALOG_STYLE_INPUT, "Name of category", "Enter the name of category where you want to put location!", "Okay", "Cancel");
  413. }
  414. if(listitem == 2)//SOON
  415. {
  416. //ShowPlayerDialog(playerid, DIALOG_DELETECAT, DIALOG_STYLE_INPUT, "Ime", "Upisite ime kategorije koju zelite obrisati", "Uredu", "Odustani");
  417. }
  418. if(listitem == 3)
  419. {
  420. ShowPlayerDialog(playerid, DIALOG_DELETELOC, DIALOG_STYLE_INPUT, "Name", "Enter the name of location", "Okay", "Cancel");
  421. }
  422. if(listitem == 4)
  423. {
  424. ShowPlayerDialog(playerid, DIALOG_MOVELOC, DIALOG_STYLE_INPUT, "Name", "Enter the name of location which you want to move", "Okay", "Cancel");
  425. }
  426. }
  427. }
  428. if(dialogid == DIALOG_TELE)
  429. {
  430. if(response)
  431. {
  432. new id=listitem;
  433. if(IsPlayerInAnyVehicle(playerid))
  434. {
  435. SetVehiclePos(GetPlayerVehicleID(playerid), TeleInfo[Cate][id][teX],TeleInfo[Cate][id][teY],TeleInfo[Cate][id][teZ]);
  436. SetVehicleZAngle(GetPlayerVehicleID(playerid),TeleInfo[Cate][id][teA]);
  437. PutPlayerInVehicle(playerid, GetPlayerVehicleID(playerid), 0);
  438. }
  439. else
  440. {
  441. SetPlayerPos(playerid,TeleInfo[Cate][id][teX],TeleInfo[Cate][id][teY],TeleInfo[Cate][id][teZ]);
  442. SetPlayerFacingAngle(playerid, TeleInfo[Cate][id][teA]);
  443. }
  444. Port(playerid);
  445. new str[128];
  446. format(str,sizeof(str),"{FF9900}You are teleported to {FFFFFF}%s!",TeleInfo[Cate][id][Name]);
  447. SendClientMessage(playerid,-1,str);
  448. }
  449. }
  450. if(dialogid == DIALOG_CTELE)
  451. {
  452. if(response)
  453. {
  454. Cate=listitem;
  455. new info[2100];
  456. for(new i=0;i<MAX_TELE;i++)
  457. {
  458. if(TeleInfo[Cate][i][teX] != 0 && TeleInfo[Cate][i][teY] != 0)
  459. {
  460. new str[128];
  461. format(str,sizeof(str),"%s\n",TeleInfo[Cate][i][Name]);
  462. strcat(info, str, sizeof(info));
  463. }
  464. }
  465. ShowPlayerDialog(playerid, DIALOG_TELE, DIALOG_STYLE_LIST, "Teleport", info, "Okay", "Cancel");
  466. }
  467. }
  468. return 1;
  469. }
  470.  
  471. CMD:edittele(playerid,params[])
  472. {
  473. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"[#Sikora] Just rcon admin!");
  474. if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,-1,"[#Sikora] You may not be in the vehicle!");
  475. ShowPlayerDialog(playerid, DIALOG_TEDIT, DIALOG_STYLE_LIST, "Edit", "Add category\nAdd location\nDelete category(SOON)\nDelete location\nMove location", "Okay", "Cancel");
  476. return 1;
  477. }
  478.  
  479. CMD:tele(playerid, params[])
  480. {
  481. if(!IsPlayerConnected(playerid)) return SendClientMessage(playerid,-1,"You are not connected!");
  482. new info[1024];
  483. for(new i=0;i<20;i++)
  484. {
  485. if(udb_hash(Category[i]) != udb_hash("Empty"))
  486. {
  487. new str[128];
  488. format(str,sizeof(str),"%s\n",Category[i]);
  489. strcat(info, str, sizeof(info));
  490. }
  491. }
  492. ShowPlayerDialog(playerid, DIALOG_CTELE, DIALOG_STYLE_LIST, "Teleport", info, "Next", "Cancel");
  493. return 1;
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement