OsamaKurdi200

gate-v2

May 1st, 2018
2,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.95 KB | None | 0 0
  1. //This is done by Osama Kurdi all credits to those creators of includes I usesd.
  2. #define FILTERSCRIPT
  3. #include <a_samp>
  4. #include <dini>
  5. #include <sscanf2>
  6. #include <zcmd>
  7.  
  8. #define GATE_PATH "Gates/gate_%i.ini"
  9. #define MAX_GATES 500
  10. #define GATE_OBJECT 980
  11. #define CLOSED 0
  12. #define OPENED 1
  13. new killtimer1[MAX_PLAYERS];
  14. enum GInf{
  15. Created,
  16. Password[256],
  17. Float:ox,
  18. Float:oy,
  19. Float:oz,
  20. Float:cx,
  21. Float:cy,
  22. Float:cz,
  23. Float:rox,
  24. Float:roy,
  25. Float:roz,
  26. Float:rcx,
  27. Float:rcy,
  28. Float:rcz,
  29. Autogate,
  30. Status,
  31. Object,
  32. Float:Speed
  33.  
  34. };
  35. new GInfo[MAX_GATES][GInf];
  36. new idob[MAX_PLAYERS];
  37. new bool:open[MAX_PLAYERS], bool:close[MAX_PLAYERS], bool:remove[MAX_PLAYERS];
  38. public OnFilterScriptInit()
  39. {
  40. printf("Dynamic Gate System runned");
  41. new file[256];
  42. for(new i = 1, j = MAX_GATES; i<=j; i++)
  43. {
  44. format(file, sizeof(file), GATE_PATH, i);
  45. if(fexist(file))
  46. {
  47. new objectid;
  48. objectid = CreateObject( GATE_OBJECT, dini_Float(file, "CX"), dini_Float(file, "CY"), dini_Float(file, "CZ"), dini_Float(file, "RCX"), dini_Float(file, "RCY"), dini_Float(file, "RCZ"));
  49. GInfo[i][Created] = 1;
  50. GInfo[i][Status] = CLOSED;
  51. GInfo[i][ox] = dini_Float(file, "OX");
  52. GInfo[i][oy] = dini_Float(file, "OY");
  53. GInfo[i][oz] = dini_Float(file, "OZ");
  54.  
  55. GInfo[i][cx] = dini_Float(file, "CX");
  56. GInfo[i][cy] = dini_Float(file, "CY");
  57. GInfo[i][cz] = dini_Float(file, "CZ");
  58.  
  59. GInfo[i][rcx] = dini_Float(file, "RCX");
  60. GInfo[i][rcy] = dini_Float(file, "RCY");
  61. GInfo[i][rcz] = dini_Float(file, "RCZ");
  62.  
  63. GInfo[i][rox] = dini_Float(file, "ROX");
  64. GInfo[i][roy] = dini_Float(file, "ROY");
  65. GInfo[i][roz] = dini_Float(file, "ROZ");
  66.  
  67. GInfo[i][Autogate] = dini_Int(file, "Autogate");
  68. GInfo[i][Speed] = dini_Int(file, "Speed");
  69. GInfo[i][Object] = objectid;
  70. new pass[256];
  71. pass = dini_Get(file, "Password");
  72. GInfo[i][Password] = pass;
  73. }else{
  74. printf("The Gates that are created:%i", i-1);
  75. break;
  76. }
  77. }
  78. return 1;
  79. }
  80.  
  81. public OnFilterScriptExit()
  82. {
  83. printf("Dynamic Gate System has stopped");
  84. return 1;
  85. }
  86. public OnPlayerConnect(playerid)
  87. {
  88. killtimer1[playerid] = SetTimerEx("auto", 500, 1, "i", playerid);
  89. return 1;
  90. }
  91.  
  92. forward auto(playerid);
  93.  
  94. public auto(playerid)
  95. {
  96. //new neargate = 0;
  97. for(new i = 0, j = MAX_GATES; i!=j; i++)
  98. {
  99. new file[256];
  100. format(file, sizeof(file), GATE_PATH, i);
  101. if(fexist(file))
  102. {
  103. if(dini_Int(file, "Autogate") == 1)
  104. {
  105. new pass[256];
  106. pass = dini_Get(file, "Password");
  107. if(!strcmp(pass, "None", true, 4))
  108. {
  109. for(new g = 0, k = MAX_PLAYERS; g!=k; g++)
  110. {
  111. if(IsPlayerConnected(g))
  112. {
  113. if(IsPlayerInRangeOfPoint(playerid, 6, dini_Float(file, "CX"), dini_Float(file, "CY"), dini_Float(file, "CZ")))
  114. {
  115. MoveObject( GInfo[i][Object], GInfo[i][ox], GInfo[i][oy], GInfo[i][oz], GInfo[i][Speed], GInfo[i][rox], GInfo[i][roy], GInfo[i][roz]);
  116. GInfo[i][Status] = OPENED;
  117. }else{
  118. MoveObject( GInfo[i][Object], GInfo[i][cx], GInfo[i][cy], GInfo[i][cz], GInfo[i][Speed], GInfo[i][rcx], GInfo[i][rcy], GInfo[i][rcz]);
  119. GInfo[i][Status] = CLOSED;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. //MoveObject( GInfo[i][Object], GInfo[i][ox], GInfo[i][oy], GInfo[i][oz], GInfo[i][Speed], GInfo[i][rox], GInfo[i][roy], GInfo[i][roz]); open
  128. //MoveObject( GInfo[i][Object], GInfo[i][cx], GInfo[i][cy], GInfo[i][cz], GInfo[i][Speed], GInfo[i][rcx], GInfo[i][rcy], GInfo[i][rcz]); close
  129. return 1;
  130. }
  131.  
  132. public OnPlayerDisconnect(playerid, reason)
  133. {
  134. KillTimer(killtimer1[playerid]);
  135. return 1;
  136. }
  137.  
  138. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  139. {
  140. if(newkeys == KEY_CROUCH)
  141. {
  142. new id = WhichGateIsNearPlayerForHorn(playerid);
  143. if(id == 0) return 0;
  144. new file[256];
  145. format(file, sizeof(file), GATE_PATH, id);
  146. new pass[256];
  147. pass = dini_Get(file, "Password");
  148. if(!strcmp(pass, "None", true, 4))
  149. {
  150. OpenOrCloseGate(id);
  151. }
  152. }
  153. return 1;
  154. }
  155. CMD:creategate(playerid, params[])
  156. {
  157. new password[256], containspass, speed;
  158. new Float:x, Float:y, Float:z;
  159. GetPlayerPos(playerid, Float:x, Float:y, Float:z);
  160. if(sscanf(params, "i", containspass)) return SendClientMessage(playerid, -1, "USAGE:/creategate <1-Has password || 0-Has not password>");
  161. if(containspass == 0)
  162. {
  163. new autog;
  164. if(sscanf(params, "s[128]ii", params, speed, autog)) return SendClientMessage(playerid, -1, "USAGE:/creategate 0 <speed> <autogate: 1-ON || 0-OFF>");
  165. CreateGate("None", x, y, z, 0, autog, speed);
  166. }
  167. if(containspass == 1)
  168. {
  169. if(sscanf(params, "s[128]is[256]", params, speed, password)) return SendClientMessage(playerid, -1, "USAGE:/creategate 1 <speed> <password>");
  170. CreateGate(password, x, y, z, 0, 0, speed);
  171. }
  172. SendClientMessage(playerid, -1, "Now do /editgate open then /editgate close");
  173. SetPlayerPos(playerid, Float:x+1, Float:y+1, Float:z+1);
  174.  
  175. return true;
  176. }
  177. CMD:gate(playerid, params[])
  178. {
  179. new gatesnear = 0;
  180. for(new i = 1; i!=MAX_GATES; i++)
  181. {
  182. if(GInfo[i][Created] == 1)
  183. {
  184. new file[256];
  185. format(file, sizeof(file), GATE_PATH, i);
  186. if(IsPlayerInRangeOfPoint(playerid, 6, dini_Float(file, "OX"), dini_Float(file, "OY"), dini_Float(file, "OZ")))
  187. {
  188. gatesnear++;
  189. if(!strcmp(GInfo[i][Password], "None"))
  190. {
  191. OpenOrCloseGate(i);
  192. break;
  193. }else
  194. {
  195. new password[80];
  196. if(sscanf(params, "s[80]", password)) return SendClientMessage(playerid, -1, "USAGE:/gate <password>");
  197. if(!strcmp(password, GInfo[i][Password]))
  198. {
  199. OpenOrCloseGate(i);
  200. break;
  201. }else return SendClientMessage(playerid, -1, "Wrong password");
  202. }
  203. }
  204. }
  205. }
  206. if(gatesnear < 1) return SendClientMessage(playerid, -1, "You are not near any gate.");
  207. return 1;
  208. }
  209. CMD:removegate(playerid, params[])
  210. {
  211. SelectObject(playerid);
  212. remove[playerid] = true;
  213. return 1;
  214. }
  215. CMD:editgate(playerid, params[])
  216. {
  217. new file[256], pass[256];
  218. pass = dini_Get(file, "Password");
  219. new Float:speed = 0;
  220. if(sscanf(params, "s[128]", params)) return SendClientMessage(playerid, -1, "USAGE:/editgate <speed || password || autogate || open || close>");
  221. if(!strcmp(params, "speed", true, 5))
  222. {
  223. new i;
  224. if(HowManyGatesNearPlayer(playerid) == 0) return SendClientMessage(playerid, -1, "You arn't near any gate");
  225. i = WhichGateIsNearPlayer(playerid);
  226. format(file, sizeof(file), GATE_PATH, i);
  227. if(sscanf(params, "s[128]f", params, speed)) return SendClientMessage(playerid, -1, "USAGE:/editgate speed <speed>");
  228. GInfo[i][Speed] = speed;
  229. dini_FloatSet(file, "Speed", speed);
  230. SendClientMessage(playerid, -1, "Gate's speed changed.");
  231. }
  232. if(!strcmp(params, "password", true, 8))
  233. {
  234. new i;
  235. if(HowManyGatesNearPlayer(playerid) == 0) return SendClientMessage(playerid, -1, "You arn't near any gate");
  236. i = WhichGateIsNearPlayer(playerid);
  237. format(file, sizeof(file), GATE_PATH, i);
  238. new pas[256];
  239. if(sscanf(params, "s[128]s[256]", params, pas)) return SendClientMessage(playerid, -1, "USAGE:/editgate password <password>");
  240. GInfo[i][Password] = pas;
  241. dini_Set(file, "Password", pas);
  242. SendClientMessage(playerid, -1, "Gate's password changed");
  243. }
  244. if(!strcmp(params, "autogate", true, 8))
  245. {
  246. new i;
  247. if(HowManyGatesNearPlayer(playerid) == 0) return SendClientMessage(playerid, -1, "You arn't near any gate");
  248. i = WhichGateIsNearPlayer(playerid);
  249. format(file, sizeof(file), GATE_PATH, i);
  250. new option;
  251. if(sscanf(params, "s[128]i", params, option)) return SendClientMessage(playerid, -1, "USAGE:/editgate autogate <1=ON || 0= OFF>");
  252. if(!strcmp(GInfo[i][Password], "None", true, 4))
  253. {
  254. GInfo[i][Autogate] = option;
  255. dini_IntSet(file, "Autogate", option);
  256. SendClientMessage(playerid, -1, "Gate's autogate has been changed.");
  257. }else{
  258. return SendClientMessage(playerid, -1, "You can't set autogate for a gate that have password.");
  259. }
  260. }
  261. if(!strcmp(params, "open", true, 4))
  262. {
  263. SelectObject(playerid);
  264. open[playerid] = true;
  265. close[playerid] = false;
  266. }
  267. if(!strcmp(params, "close", true, 5))
  268. {
  269. SelectObject(playerid);
  270. open[playerid] = false;
  271. close[playerid] = true;
  272. }
  273.  
  274. return 1;
  275. }
  276. CMD:gotogate(playerid, params[])
  277. {
  278. new gateid;
  279. if(sscanf(params, "i", gateid)) return SendClientMessage(playerid, -1, "USAGE:/gotogate <gate_id>");
  280. new file[256];
  281. format(file, sizeof(file), GATE_PATH, gateid);
  282. if(GInfo[gateid][Created] == 1 && fexist(file))
  283. {
  284. SetPlayerPos(playerid, dini_Float(file, "CX")+1, dini_Float(file, "CY")+1, dini_Float(file, "CZ")+1);
  285. SendClientMessage(playerid, -1, "You have been teleported to your choosen gate location.");
  286. }else{
  287. SendClientMessage(playerid, -1, "Gate not found.");
  288. }
  289. return 1;
  290. }
  291. CMD:nearestgate(playerid)
  292. {
  293. new str[180], id = WhichGateIsNearPlayer(playerid);
  294. if(id == 0) return SendClientMessage(playerid, -1, "No gates near you");
  295. format(str, sizeof(str), "Gate's id that is near you: %i", id);
  296. SendClientMessage(playerid, -1, str);
  297. return true;
  298. }
  299. CreateGate(password[256], Float:x, Float:y, Float:z, Float:a, Auto, Float:speed)
  300. {
  301. new file[256];
  302. for(new i = 1, j = MAX_GATES; i<=j; i++)
  303. {
  304. format(file, sizeof(file), GATE_PATH, i);
  305. if(GInfo[i][Created] == 0)
  306. {
  307. new objectid;
  308. objectid = CreateObject( GATE_OBJECT, x, y, z+1.5, 0, 0, a );
  309. dini_Create(file);
  310. dini_Set(file, "Password", password);
  311. dini_FloatSet(file, "OX", x);
  312. dini_FloatSet(file, "OY", y);
  313. dini_FloatSet(file, "OZ", z);
  314.  
  315. dini_FloatSet(file, "CX", x);
  316. dini_FloatSet(file, "CY", y);
  317. dini_FloatSet(file, "CZ", z);
  318.  
  319. dini_FloatSet(file, "ROX", 0.0);
  320. dini_FloatSet(file, "ROY", 0.0);
  321. dini_FloatSet(file, "ROZ", 0.0);
  322.  
  323. dini_FloatSet(file, "RCX", 0.0);
  324. dini_FloatSet(file, "RCY", 0.0);
  325. dini_FloatSet(file, "RCZ", 0.0);
  326.  
  327. dini_IntSet(file, "Autogate", Auto);
  328. dini_FloatSet(file, "Speed", speed);
  329. GInfo[i][Created] = 1;
  330. GInfo[i][Status] = CLOSED;
  331. GInfo[i][ox] = x;
  332. GInfo[i][oy] = y;
  333. GInfo[i][oz] = z;
  334.  
  335. GInfo[i][cx] = x;
  336. GInfo[i][cy] = y;
  337. GInfo[i][cz] = z;
  338.  
  339. GInfo[i][rcx] = x;
  340. GInfo[i][rcy] = z;
  341. GInfo[i][rcz] = y;
  342.  
  343. GInfo[i][rox] = x;
  344. GInfo[i][roy] = y;
  345. GInfo[i][roz] = z;
  346.  
  347. GInfo[i][Autogate] = Auto;
  348. GInfo[i][Object] = objectid;
  349. GInfo[i][Password] = password;
  350. GInfo[i][Speed] = speed;
  351. break;
  352. }
  353. }
  354. return 1;
  355. }
  356. OpenOrCloseGate(i)
  357. {
  358. if(GInfo[i][Status] == CLOSED)
  359. {
  360. MoveObject( GInfo[i][Object], GInfo[i][ox], GInfo[i][oy], GInfo[i][oz], GInfo[i][Speed], GInfo[i][rox], GInfo[i][roy], GInfo[i][roz]);
  361. GInfo[i][Status] = OPENED;
  362. return 1;
  363. }
  364. if(GInfo[i][Status] == OPENED)
  365. {
  366. MoveObject( GInfo[i][Object], GInfo[i][cx], GInfo[i][cy], GInfo[i][cz], GInfo[i][Speed], GInfo[i][rcx], GInfo[i][rcy], GInfo[i][rcz]);
  367. GInfo[i][Status] = CLOSED;
  368. return 1;
  369. }
  370. return 1;
  371. }
  372. WhichGateIsNearPlayer(playerid)
  373. {
  374. new gate = 0;
  375. for(new i = 0; i!=MAX_GATES; i++)
  376. {
  377. if(GInfo[i][Created] == 1)
  378. {
  379. new file[256];
  380. format(file, sizeof(file), GATE_PATH, i);
  381. if(fexist(file))
  382. {
  383. if(IsPlayerInRangeOfPoint(playerid, 4.0, dini_Float(file, "CX"), dini_Float(file, "CY"), dini_Float(file, "CZ")))
  384. {
  385. gate = i;
  386. break;
  387. }
  388. }
  389. }
  390. }
  391. return gate;
  392. }
  393. WhichGateIsNearPlayerForHorn(playerid)
  394. {
  395. new gate = 0;
  396. for(new i = 0; i!=MAX_GATES; i++)
  397. {
  398. if(GInfo[i][Created] == 1)
  399. {
  400. new file[256];
  401. format(file, sizeof(file), GATE_PATH, i);
  402. if(fexist(file))
  403. {
  404. if(IsPlayerInRangeOfPoint(playerid, 7.0, dini_Float(file, "CX"), dini_Float(file, "CY"), dini_Float(file, "CZ")))
  405. {
  406. gate = i;
  407. break;
  408. }
  409. }
  410. }
  411. }
  412. return gate;
  413. }
  414. HowManyGatesNearPlayer(playerid)
  415. {
  416. new gatesnear = 0;
  417. for(new i = 0; i!=MAX_GATES; i++)
  418. {
  419. if(GInfo[i][Created] == 1)
  420. {
  421. new file[256];
  422. format(file, sizeof(file), GATE_PATH, i);
  423. if(fexist(file))
  424. {
  425. if(IsPlayerInRangeOfPoint(playerid, 4.0, dini_Float(file, "CX"), dini_Float(file, "CY"), dini_Float(file, "CZ")))
  426. {
  427. gatesnear++;
  428. }
  429. }
  430. }
  431. }
  432. return gatesnear;
  433. }
  434.  
  435. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ )
  436. {
  437. objectid = idob[playerid];
  438. new Float:pos[3], Float:rpos[3];
  439. GetObjectPos(objectid, pos[0], pos[1], pos[2]);
  440. GetObjectRot(objectid, rpos[0], rpos[1], rpos[2]);
  441. if(response == EDIT_RESPONSE_FINAL)
  442. {
  443. SetObjectPos(objectid, Float:fX, Float:fY, Float:fZ);
  444. SetObjectRot(objectid, Float:fRotX, Float:fRotY, Float:fRotZ);
  445. if(open[playerid] == true)
  446. {
  447. new file[256];
  448. format(file, sizeof(file), GATE_PATH, objectid);
  449. GInfo[objectid][ox] = fX;
  450. GInfo[objectid][oy] = fY;
  451. GInfo[objectid][oz] = fZ;
  452.  
  453. GInfo[objectid][rox] = fRotX;
  454. GInfo[objectid][roy] = fRotY;
  455. GInfo[objectid][roz] = fRotZ;
  456.  
  457. dini_FloatSet(file, "ROX", fRotX);
  458. dini_FloatSet(file, "ROY", fRotY);
  459. dini_FloatSet(file, "ROZ", fRotZ);
  460.  
  461. dini_FloatSet(file, "OX", fX);
  462. dini_FloatSet(file, "OY", fY);
  463. dini_FloatSet(file, "OZ", fZ);
  464. GInfo[objectid][Status] = OPENED;
  465. open[playerid] = false;
  466. SendClientMessage(playerid, -1, "You have changed gate's open position");
  467. }
  468. if(close[playerid] == true)
  469. {
  470. new file[256];
  471. format(file, sizeof(file), GATE_PATH, objectid);
  472. GInfo[objectid][cx] = fX;
  473. GInfo[objectid][cy] = fY;
  474. GInfo[objectid][cz] = fZ;
  475.  
  476. GInfo[objectid][rcx] = fRotX;
  477. GInfo[objectid][rcy] = fRotY;
  478. GInfo[objectid][rcz] = fRotZ;
  479.  
  480. dini_FloatSet(file, "RCX", fRotX);
  481. dini_FloatSet(file, "RCY", fRotY);
  482. dini_FloatSet(file, "RCZ", fRotZ);
  483.  
  484. dini_FloatSet(file, "CX", fX);
  485. dini_FloatSet(file, "CY", fY);
  486. dini_FloatSet(file, "CZ", fZ);
  487. GInfo[objectid][Status] = CLOSED;
  488. close[playerid] = false;
  489. SendClientMessage(playerid, -1, "You have changed gate's close position");
  490. }
  491. }
  492. if(response == EDIT_RESPONSE_CANCEL)
  493. {
  494. SetObjectPos(objectid, pos[0], pos[1], pos[2]);
  495. SetObjectRot(objectid, rpos[0], rpos[1], rpos[2]);
  496. }
  497. return 1;
  498. }
  499. public OnPlayerSelectObject(playerid, type, objectid, modelid, Float:fX, Float:fY, Float:fZ)
  500. {
  501. if(open[playerid] == true || close[playerid] == true)
  502. {
  503. EditObject(playerid, objectid);
  504. idob[playerid] = objectid;
  505. }
  506. if(remove[playerid] == true)
  507. {
  508. new file[256], i;
  509. i = WhichGateIsNearPlayer(playerid);
  510. format(file, sizeof(file), GATE_PATH, i);
  511. if(fexist(file))
  512. {
  513. DestroyObject(GInfo[i][Object]);
  514. dini_Remove(file);
  515. GInfo[i][Created] = 0;
  516. GInfo[i][ox] = 0.0;
  517. GInfo[i][oy] = 0.0;
  518. GInfo[i][oz] = 0.0;
  519.  
  520. GInfo[i][cx] = 0.0;
  521. GInfo[i][cy] = 0.0;
  522. GInfo[i][cz] = 0.0;
  523.  
  524. GInfo[i][rcx] = 0.0;
  525. GInfo[i][rcy] = 0.0;
  526. GInfo[i][rcz] = 0.0;
  527.  
  528. GInfo[i][rox] = 0.0;
  529. GInfo[i][roy] = 0.0;
  530. GInfo[i][roz] = 0.0;
  531.  
  532. GInfo[i][Password] = 0;
  533. GInfo[i][Status] = CLOSED;
  534.  
  535. remove[playerid] = false;
  536. SendClientMessage(playerid, -1, "You have removed the gate.");
  537. }
  538. }
  539.  
  540. return 1;
  541. }
Add Comment
Please, Sign In to add comment