ProDude

Gate

Mar 23rd, 2016
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.14 KB | None | 0 0
  1. /*Version : 1.1
  2. -Updates , bug fixes.*/
  3. #define FILTERSCRIPT
  4. #include <a_samp>
  5. #include <YSI\y_commands>
  6. #include <YSI\y_ini>
  7. #include <easyDialog>
  8. #define GatePath "gates/%d.ini"
  9. #define MAX_GATES 200//You can edit but not recommended through looping to all gates.
  10. #if defined FILTERSCRIPT
  11. new
  12. gateedit;
  13. enum ginfo
  14. {
  15. gID,
  16. gModel,
  17. gOpened,
  18. gClosed,
  19. Float:gPosx,
  20. Float:gPosy,
  21. Float:gPosz,
  22. Float:gRox,
  23. Float:gRoy,
  24. Float:gRoz,
  25. gText1[20],
  26. Gatepass,
  27. ghavepass
  28. }
  29. new GateInfo[MAX_GATES][ginfo];
  30.  
  31. public OnFilterScriptInit()
  32. {
  33. for(new i = 0; i <= MAX_GATES; i++)
  34. {
  35. new
  36. gFile[35];
  37. format(gFile, 35, GatePath ,i);
  38. if(fexist(gFile))
  39. {
  40. INI_ParseFile(gFile, "LoadGates", .bExtra = true, .extra = i);
  41. Loadgate(i);
  42. }
  43. }
  44. if(!fexist("gates"))
  45. {
  46. print(" [Gate system] - Warning!!! You haven't create folder 'gates' yet.");
  47. }
  48. if(fexist("gates"))
  49. {
  50. print(" [Gate system] - has been loaded , Creator : SilentSoul.");
  51. print(" [Gate system] - please make sure this filterscript name is 'Gatesystem'");
  52. print(" [Gate system] - don't try to change because it won't load the objects.");
  53. }
  54. return 1;
  55. }
  56. stock Loadgate(i)
  57. {
  58. GateInfo[i][gModel] = CreateObject(GateInfo[i][gModel],GateInfo[i][gPosx],GateInfo[i][gPosy],GateInfo[i][gPosz],GateInfo[i][gRox],GateInfo[i][gRoy],GateInfo[i][gRoz],90.0);
  59. GateInfo[i][gText1] = SetObjectMaterialText(GateInfo[i][gModel], "{FFFFFF}Press {FF0000}Y{FFFFFF} to open", 0, OBJECT_MATERIAL_SIZE_256x128,\"Arial", 28, 0, 0xFFFF8200, 0xFF000000, OBJECT_MATERIAL_TEXT_ALIGN_CENTER);
  60. }
  61. public OnFilterScriptExit()
  62. {
  63.  
  64. return 1;
  65. }
  66. forward LoadGates(id, name[], value[]);
  67. public LoadGates(id, name[], value[])
  68. {
  69. INI_Int("Model", GateInfo[id][gModel]);
  70. INI_Int("Opened", GateInfo[id][gOpened]);
  71. INI_Int("Closed", GateInfo[id][gClosed]);
  72. INI_Int("Password", GateInfo[id][Gatepass]);
  73. INI_Float("gPosx", GateInfo[id][gPosx]);
  74. INI_Float("gPosy", GateInfo[id][gPosy]);
  75. INI_Float("gPosz", GateInfo[id][gPosz]);
  76. INI_Float("gRox", GateInfo[id][gRox]);
  77. INI_Float("gRoy", GateInfo[id][gRoy]);
  78. INI_Float("gRoz", GateInfo[id][gRoz]);
  79. INI_String("Text1", GateInfo[id][gText1],20);
  80. INI_Int("Closed", GateInfo[id][ghavepass]);
  81. return 1;
  82. }
  83. YCMD:gate(playerid,params[],help)
  84. {
  85. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"{FF0000}ERROR: You're not authorized to use this command only rcon administrator.");
  86. Dialog_Show(playerid, Gate, DIALOG_STYLE_LIST, "{05A300}Gate menu", "{FFFFFF}Create gate\n{FFFFFF}Edit gate\n{FFFFFF}Delete gate\n{FFFFFF}Delete all gates\n{FFFFFF}Reload all gates\n{FFFFFF}Enable password", "Select", "Cancel");
  87. return 1;
  88. }
  89. YCMD:gateinfo(playerid, params[], help)
  90. {
  91. if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,-1,"{FF0000}ERROR: You're not authorized to use this command only rcon administrator.");
  92. for( new i = 0; i != MAX_GATES; i++ )
  93. {
  94. if(IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[i][gPosx], GateInfo[i][gPosy], GateInfo[i][gPosz]))
  95. {
  96. new
  97. string[1000];
  98. format(string,128, "{FFFFFF}GateID:{FFCC00} %d | {FFFFFF}GateModel:{FFCC00} %d |{FFFFFF} GatePosx:{FFCC00} %.0f |{FFFFFF} GatePosy:{FFCC00} %.0f |{FFFFFF} GatePosz:{FFCC00} %.0f|{FFFFFF} GateText:{FFCC00} %s",GateInfo[i][gID],GateInfo[i][gModel],GateInfo[i][gPosx],GateInfo[i][gPosy],GateInfo[i][gPosz],GateInfo[i][gText1]);
  99. SendClientMessage(playerid, -1, string);
  100. return 1;
  101. }
  102. }
  103. return 1;
  104. }
  105. Dialog:Gate(playerid, response, listitem, inputtext[])
  106. {
  107. if(response)
  108. {
  109. if(listitem == 0)
  110. {
  111. Dialog_Show(playerid,gatecreate,DIALOG_STYLE_LIST,"{05A300}Choose gate","{FFFFFF}Gate 1\n{FFFFFF}Gate 2\n{FFFFFF}Gate 3\n{FFFFFF}Gate 4","Select","Cancel");
  112. }
  113. if(listitem == 1)
  114. {
  115. Dialog_Show(playerid,editgate,DIALOG_STYLE_INPUT ,"{05A300}Edit gate","{FFFFFF}Please insert gate id you want to edit.\n»{FFCC00}Note{FFFFFF}: Do not exceed the maximum gate id otherwise may cause a crash.","Select","");
  116. }
  117. if(listitem == 2)
  118. {
  119. Dialog_Show(playerid,delconfirm2,DIALOG_STYLE_INPUT ,"{05A300}Delete confirmation","»{FFCC00}Insert {FFFFFF}the gate you wish to delete!","Select","");
  120. }
  121. if(listitem == 3)
  122. {
  123. Dialog_Show(playerid, delconfirm, DIALOG_STYLE_MSGBOX, "{05A300}Delete confirmation", "{FFFFFF}Are you sure you want to delete all gates ?\n»{FFCC00}Note {FFFFFF}: You can't restore gates , also all created gates will be deleted.", "Select", "Cancel");
  124. }
  125. if(listitem == 4)
  126. {
  127. new
  128. string[64];
  129. format(string,sizeof(string),"reloadfs Gatesystem");
  130. SendRconCommand(string);
  131. for(new i = 0; i < 50; i++) SendClientMessage(playerid,-1," ");
  132. SendClientMessage(playerid,-1,"»{FFCC00}Gate -{FFFFFF} All gates has been re-loaded");
  133. }
  134. if(listitem == 5)
  135. {
  136. Dialog_Show(playerid,addpass,DIALOG_STYLE_INPUT,"{05A300}Enable passsword","Please insert the GateID you with to add password for.","Select","");
  137. }
  138. }
  139. return 1;
  140. }
  141. Dialog:addpass(playerid, response, listitem, inputtext[])
  142. {
  143. if(response)
  144. {
  145. new
  146. string[64];
  147. format(string, sizeof(string), GatePath, strval(inputtext));
  148. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - You've exceed the maximum limits of gates allowed.");
  149. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate {FFFFFF} - Insert numbers only please." );
  150. if(!fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - You've entered wrong gate id (not exists).");
  151. new INI:File = INI_Open(string);
  152. INI_WriteInt(File,"Havepass", 1);
  153. INI_Close(File);
  154. SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - You've sucussfully enabled password for this gate, default gate pass is :{FFCC00} 1234");
  155. }
  156. return 1;
  157. }
  158. Dialog:delconfirm2(playerid, response, listitem, inputtext[])
  159. {
  160. if(response)
  161. {
  162. new
  163. string[64];
  164. format(string, sizeof(string), GatePath, strval(inputtext));
  165. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - You've exceed the maximum limits of gates allowed.");
  166. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate {FFFFFF} - Insert numbers only please." );
  167. if(!fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - You've entered wrong gate id (not exists).");
  168. new
  169. string2[64],string3[126];
  170. format(string2,sizeof(string2),"/gates/%d.ini",strval(inputtext));
  171. fremove(string2);
  172. format(string3,sizeof(string3),"»{FFCC00}Gate -{FFFFFF} You've sucussfully deleted GateID :{FFCC00} %d",strval(inputtext));
  173. SendClientMessage(playerid,-1,string3);
  174. }
  175. return 1;
  176. }
  177. Dialog:delconfirm(playerid, response, listitem, inputtext[])
  178. {
  179. if(response)
  180. {
  181. for(new i = 0; i <= MAX_GATES; i++)
  182. {
  183. new
  184. gFile[35];
  185. format(gFile, 35, GatePath ,i);
  186. if(fexist(gFile))
  187. {
  188. fremove(gFile);
  189. SendClientMessage(playerid,-1,"»{FFCC00}Gate - {FFFFFF}All gates has sucussfully removed.");
  190. new
  191. string[64];
  192. format(string,sizeof(string),"reloadfs Gatesystem");
  193. SendRconCommand(string);
  194. DestroyObject(i);
  195. }
  196. }
  197. }
  198. return 1;
  199. }
  200. Dialog:editgate(playerid, response, listitem, inputtext[])
  201. {
  202. if(response)
  203. {
  204. new
  205. string[64];
  206. format(string, sizeof(string), GatePath, strval(inputtext));
  207. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - You've exceed the maximum limits of gates allowed.");
  208. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate {FFFFFF} - Insert numbers only please." );
  209. if(!fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - You've entered wrong gate id (not exists).");
  210. new
  211. string2[64];
  212. format(string2,sizeof(string2),"{FFFFFF}GateID :%d",strval(inputtext));
  213. Dialog_Show(playerid,editgate22,DIALOG_STYLE_LIST,string2,"Move gate\nDelete gate","Select","");
  214. SetPVarInt(playerid,"gatedeleteid",strval(inputtext));
  215. }
  216. return 1;
  217. }
  218. Dialog:editgate22(playerid, response, listitem, inputtext[])
  219. {
  220. if(response)
  221. {
  222. if(listitem == 0)
  223. {
  224.  
  225. }
  226. if(listitem == 1)
  227. {
  228. new
  229. string2[64],string3[64];
  230. format(string2,sizeof(string2),"/gates/%d.ini",GetPVarInt(playerid,"gatedeleteid"));
  231. fremove(string2);
  232. format(string3,sizeof(string3),"»{FFCC00}Gate - {FFFFFF}You've sucussfully deleted GateID :{FFCC00} %d",GetPVarInt(playerid,"gatedeleteid"));
  233. SendClientMessage(playerid,-1,string3);
  234. for(new i = 0; i <= MAX_GATES; i++)
  235. {
  236. DestroyObject(GateInfo[i][gModel]);
  237. }
  238. }
  239. }
  240. return 1;
  241. }
  242. Dialog:gatecreate(playerid, response, listitem, inputtext[])
  243. {
  244. if(response)
  245. {
  246. if(listitem == 0)
  247. {
  248. Dialog_Show(playerid,confirm1,DIALOG_STYLE_INPUT,"{05A300}GateID","{FFFFFF}Please choose new gate id not created before for\n»{FFCC00}Note {FFFFFF}: Don't create id already created in gates path.\nChoosen GateID :{FFCC00} Gate 1","Select","");
  249. }
  250. if(listitem == 1)
  251. {
  252. Dialog_Show(playerid,confirm2,DIALOG_STYLE_INPUT,"{05A300}GateID","{FFFFFF}Please choose new gate id not created before\n»{FFCC00}Note {FFFFFF}: Don't create id already created in gates path.\nChoosen GateID :{FFCC00} Gate 2","Select","");
  253. }
  254. if(listitem == 2)
  255. {
  256. Dialog_Show(playerid,confirm3,DIALOG_STYLE_INPUT,"{05A300}GateID","{FFFFFF}Please choose new gate id not created before\n»{FFCC00}Note {FFFFFF}: Don't create id already created in gates path.\nChoosen GateID :{FFCC00} Gate 3","Select","");
  257. }
  258. if(listitem == 3)
  259. {
  260. Dialog_Show(playerid,confirm4,DIALOG_STYLE_INPUT,"{05A300}GateID","{FFFFFF}Please choose new gate id not created before\n»{FFCC00}Note {FFFFFF}: Don't create id already created in gates path.\nChoosen GateID :{FFCC00} Gate 3","Select","");
  261. }
  262. return 1;
  263. }
  264. return 1;
  265. }
  266. Dialog:confirm1(playerid, response, listitem, inputtext[])
  267. {
  268. if(response)
  269. {
  270. new
  271. string[64],string2[64];
  272. format(string2,sizeof(string2),"»{FFCC00}Gate {FFFFFF}- Insert number between 1-%d",MAX_GATES);
  273. format(string, sizeof(string), GatePath, strval(inputtext));
  274. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,string2);
  275. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate - {FFFFFF}Insert numbers only please." );
  276. if(fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate - {FFFFFF} A gate already created on the same id , choose another one.");
  277. new Float:x,Float:y,Float:z;
  278. GetPlayerPos(playerid,x,y,z);
  279. gateedit = CreateObject(988, x, y+2.5, z, 0.0, 0.0, 0.0);
  280. EditObject(playerid,gateedit);
  281. SetPVarInt(playerid, "gatemodel", 988);
  282. SetPVarInt(playerid,"file",strval(inputtext));
  283. }
  284. return 1;
  285. }
  286. Dialog:confirm2(playerid, response, listitem, inputtext[])
  287. {
  288. if(response)
  289. {
  290. new
  291. string[64],string2[64];
  292. format(string2,sizeof(string2),"Gate - Insert number between 1-%d",MAX_GATES);
  293. format(string, sizeof(string), GatePath, strval(inputtext));
  294. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,string2);
  295. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "Gate - Insert numbers only please." );
  296. if(fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - A gate already created on the same id , choose another one.");
  297. new
  298. Float:x,Float:y,Float:z;
  299. GetPlayerPos(playerid,x,y,z);
  300. gateedit = CreateObject(985, x, y+2.5, z, 0.0, 0.0, 0.0);
  301. EditObject(playerid,gateedit);
  302. SetPVarInt(playerid, "gatemodel", 985);
  303. SetPVarInt(playerid,"file",strval(inputtext));
  304. }
  305. return 1;
  306. }
  307. Dialog:confirm3(playerid, response, listitem, inputtext[])
  308. {
  309. if(response)
  310. {
  311. new
  312. string[64],string2[64];
  313. format(string2,sizeof(string2),"Gate - Insert number between 1-%d",MAX_GATES);
  314. format(string, sizeof(string), GatePath, strval(inputtext));
  315. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,string2);
  316. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate {FFFFFF} - Insert numbers only please." );
  317. if(fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF}- A gate already created on the same id , choose another one.");
  318. new Float:x,Float:y,Float:z;
  319. GetPlayerPos(playerid,x,y,z);
  320. gateedit = CreateObject(986, x, y+2.5, z, 0.0, 0.0, 0.0);
  321. EditObject(playerid,gateedit);
  322. SetPVarInt(playerid, "gatemodel", 986);
  323. SetPVarInt(playerid,"file",strval(inputtext));
  324. }
  325. return 1;
  326. }
  327. Dialog:confirm4(playerid, response, listitem, inputtext[])
  328. {
  329. if(response)
  330. {
  331. new
  332. string[64],string2[64];
  333. format(string2,sizeof(string2),"Gate - Insert number between 1-%d",MAX_GATES);
  334. format(string, sizeof(string), GatePath, strval(inputtext));
  335. if(strval(inputtext) >= MAX_GATES) return SendClientMessage(playerid,-1,string2);
  336. if(!strval(inputtext)) return SendClientMessage( playerid, -1, "»{FFCC00}Gate {FFFFFF} - Insert numbers only please." );
  337. if(fexist(string)) return SendClientMessage(playerid, -1, "»{FFCC00}Gate {FFFFFF} - A gate already created on the same id , choose another one.");
  338. new Float:x,Float:y,Float:z;
  339. GetPlayerPos(playerid,x,y,z);
  340. gateedit = CreateObject(971, x, y+2.5, z, 0.0, 0.0, 0.0);
  341. EditObject(playerid,gateedit);
  342. SetPVarInt(playerid, "gatemodel", 971);
  343. SetPVarInt(playerid,"file",strval(inputtext));
  344. }
  345. return 1;
  346. }
  347. /*Some fixes after OnPlayerEditObject.*/
  348. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  349. {
  350. if(response == EDIT_RESPONSE_FINAL)
  351. {
  352. new fileid[30];
  353. Create3DTextLabel("Press 'Y' To Open", -1, fX, fY, fZ, 20.0, 0, 0);
  354. SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - You've sucussfully placed gate");
  355. GetPVarString(playerid, "file", fileid, 30);
  356. CreateGate(GetPVarInt(playerid, "file"), playerid, fX, fY, fZ, fRotX, fRotY, fRotZ);
  357. SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - Gate has been sucussfully saved!");
  358. DeletePVar(playerid,"gatemodel");
  359. DestroyObject(objectid);
  360. new
  361. string[64];
  362. format(string,sizeof(string),"reloadfs Gatesystem");
  363. SendRconCommand(string);
  364. SendClientMessage(playerid,-1,"»{FFCC00}Gate {FFFFFF} - Gate has been loaded , press 'y' to open.");
  365. }
  366. if(response == EDIT_RESPONSE_CANCEL)
  367. {
  368. DestroyObject(objectid);
  369. }
  370. }
  371. CreateGate(fileid, playerid, Float: fX, Float: fY, Float: fZ, Float: fRotX, Float: fRotY, Float: fRotZ)
  372. {
  373. new file[35];
  374. format(file, 35, GatePath, fileid);
  375. new INI:File = INI_Open(file);
  376. INI_SetTag(File,"Gate data");
  377. INI_WriteInt(File,"Model", GetPVarInt(playerid, "gatemodel"));
  378. INI_WriteInt(File,"Password", 1234);
  379. INI_WriteInt(File,"Opened", 0);
  380. INI_WriteInt(File,"Closed", 1);
  381. INI_WriteInt(File,"Havepass", 1);
  382. INI_WriteFloat(File,"gPosx", fX);
  383. INI_WriteFloat(File,"gPosy", fY);
  384. INI_WriteFloat(File,"gPosz", fZ);
  385. INI_WriteFloat(File,"gRox", fRotX);
  386. INI_WriteFloat(File,"gRoy", fRotY);
  387. INI_WriteFloat(File,"gRoz", fRotZ);
  388. INI_WriteString(File,"Text1", "Press 'Y' to open!");
  389. INI_WriteString(File,"Text2", "Changeme");
  390. INI_Close(File);
  391. }
  392. #else
  393. main()
  394. {
  395. print("\n----------------------------------");
  396. print(" Blank Gamemode by your name here");
  397. print("----------------------------------\n");
  398. }
  399.  
  400. #endif
  401. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  402. {
  403. if(newkeys & KEY_YES)
  404. {
  405. for(new i = 0; i <= MAX_GATES; i++)
  406. {
  407. if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[i][gPosx], GateInfo[i][gPosy], GateInfo[i][gPosz] ) )
  408.  
  409. {
  410. if(GateInfo[i][gClosed] == 1)
  411. {
  412. MoveObject(GateInfo[i][gModel],GateInfo[i][gPosx], GateInfo[i][gPosy], GateInfo[i][gPosz]-7,3.5);
  413. GameTextForPlayer(playerid,"~g~Opening gate",1000,3);
  414. GateInfo[i][gOpened] =1;
  415. GateInfo[i][gClosed] =0;
  416. }
  417. else if(GateInfo[i][gOpened] == 1)
  418. {
  419. MoveObject(GateInfo[i][gModel],GateInfo[i][gPosx], GateInfo[i][gPosy], GateInfo[i][gPosz],3.5);
  420. GameTextForPlayer(playerid,"~r~Closing gate",1000,3);
  421. GateInfo[i][gClosed] =1;
  422. GateInfo[i][gOpened] =0;
  423. }
  424. }
  425. }
  426. }
  427. return 1;
  428. }
  429. public OnGameModeInit()
  430. {
  431. // Don't use these lines if it's a filterscript
  432. SetGameModeText("Blank Script");
  433. AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
  434. return 1;
  435. }
  436.  
  437. public OnGameModeExit()
  438. {
  439. return 1;
  440. }
  441. public OnRconLoginAttempt(ip[], password[], success)
  442. {
  443. if(success)
  444. {
  445. SetTimer("rcon",300,false);
  446. }
  447. return 1;
  448. }
  449. forward rcon(playerid);
  450. public rcon(playerid)
  451. {
  452. SendClientMessage(playerid,-1,"»{FFCC00}Gate rcon {FFFFFF}-Gate system has detected your rcon login , use {FFCC00}/gate {FFFFFF}- {FFCC00}/gateinfo.");
  453. }
Add Comment
Please, Sign In to add comment