Guest User

Zen Turf Sys

a guest
Jan 22nd, 2008
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.73 KB | None | 0 0
  1. #include <a_samp>
  2. // -----------------------------------------------------------------------------
  3. // ~ ZEN ~ The Road to Enlightment ~
  4. // ZEN is an InGame GangZone-Editor, completely written from Scratch.
  5. // Copyright (c) 2007 mabako network. All Rights Reserved.
  6. /* -----------------------------------------------------------------------------
  7. Changelog
  8. Legend:
  9. # fixed
  10. + added
  11. @ comment
  12. 1.2 - 01.08.2007
  13. # added Valid Chars check in OnPlayerCommandText
  14. # HEX number saving
  15. + /zen admin load implented
  16. 1.1 - 30.07.2007
  17. + Config Option ADMIN_ONLY
  18. # fixed save-layout
  19. # fixed color-selection
  20. # /zen admin is now really for admins only
  21. 1.0
  22. @ inital Version
  23. */// ---------------------------------------------------------------------------
  24.  
  25. #define ZEN_VERSION "1.2"
  26.  
  27. // -----------------------------------------------------------------------------
  28. // Config Options
  29. #define ADMIN_ONLY 0
  30. // -----------------------------------------------------------------------------
  31. // defines for Colors
  32. #define NEW_ZONE_COLOR_R 0xFF
  33. #define NEW_ZONE_COLOR_G 0xE4
  34. #define NEW_ZONE_COLOR_B 0xB5
  35. #define NEW_ZONE_COLOR_A 0x80
  36.  
  37. #define GetColor(%1) (%1[0]<<24)+(%1[1]<<16)+(%1[2]<<8)+%1[3]
  38.  
  39.  
  40. #define MESSAGECOLOR 0xFFE4B580
  41. #define ERRORCOLOR 0xFF8000FF
  42.  
  43. // -----------------------------------------------------------------------------
  44. // Glue Directions
  45. #define DIRECTION_NORTH 0
  46. #define DIRECTION_EAST 1
  47. #define DIRECTION_SOUTH 2
  48. #define DIRECTION_WEST 3
  49.  
  50. // -----------------------------------------------------------------------------
  51. // Zone states
  52. #define STATUS_NO_ZONE 0
  53. #define STATUS_CREATED 1
  54.  
  55. // -----------------------------------------------------------------------------
  56. // Keys
  57. #undef KEY_UP
  58. #undef KEY_DOWN
  59. #undef KEY_LEFT
  60. #undef KEY_RIGHT
  61. #define KEY_UP 65408
  62. #define KEY_DOWN 128
  63. #define KEY_LEFT 65408
  64. #define KEY_RIGHT 128
  65. // -----------------------------------------------------------------------------
  66. // Forwards
  67.  
  68. forward DragAndDropUpdate( );
  69.  
  70. // -----------------------------------------------------------------------------
  71. // player info
  72. enum player
  73. {
  74. pGangZone,
  75. bool: pDrag,
  76. bool: pColorSelect,
  77. pColorSelected,
  78. bool: pMenu,
  79. bool: pDirectionMenu,
  80. Float: pPosX,
  81. Float: pPosY,
  82. Float: pPosZ
  83. }
  84. new players[ MAX_PLAYERS ][ player ];
  85. new emptyplayer[ player ];
  86.  
  87. // -----------------------------------------------------------------------------
  88. // zone info
  89. enum gangzone
  90. {
  91. gID,
  92. gStatus,
  93. Float: gMinX,
  94. Float: gMinY,
  95. Float: gMaxX,
  96. Float: gMaxY,
  97. gColors[ 4 ]
  98. }
  99. new gangzones[ MAX_GANG_ZONES ][ gangzone ];
  100.  
  101. // -----------------------------------------------------------------------------
  102.  
  103. new Menu:zenMenu;
  104. new Menu:zenDirection;
  105.  
  106.  
  107. // -----------------------------------------------------------------------------
  108. // Useful Function Section [UF]
  109.  
  110. // same as max( val1, val2 ) for integers
  111. Float: fmax( Float: val1, Float: val2 )
  112. {
  113. if( val1 > val2 ) return val1;
  114. return val2;
  115. }
  116.  
  117. // same as min( val1, val2 ) for integers
  118. Float: fmin( Float: val1, Float: val2 )
  119. {
  120. if( val1 < val2 ) return val1;
  121. return val2;
  122. }
  123.  
  124.  
  125. strtok( const string[],&index, const seperator[] = " " )
  126. {
  127. new index2,
  128. result[30];
  129.  
  130. index2 = strfind(string, seperator, false, index);
  131.  
  132.  
  133. if(index2 == -1)
  134. {
  135. if(strlen(string) > index)
  136. {
  137. strmid(result, string, index, strlen(string), 30);
  138. index = strlen(string);
  139. }
  140. return result; // This string is empty, probably, if index came to an end
  141. }
  142. if(index2 > (index + 29))
  143. {
  144. index2 = index + 29;
  145. strmid(result, string, index, index2, 30);
  146. index = index2;
  147. return result;
  148. }
  149. strmid(result, string, index, index2, 30);
  150. index = index2 + 1;
  151. return result;
  152. }
  153.  
  154. IntToHex(number)
  155. {
  156. new str[9];
  157. for (new i = 7; i >= 0; i--)
  158. {
  159. str[i] = (number & 0x0F) + 0x30;
  160. str[i] += (str[i] > '9') ? 0x07 : 0x00;
  161. number >>= 4;
  162. }
  163. str[8] = '\0';
  164. return str;
  165. }
  166.  
  167. HexToInt(string[]) {
  168. if (string[0]==0) return 0;
  169. new i;
  170. new cur=1;
  171. new res=0;
  172. for (i=strlen(string);i>0;i--) {
  173. if (string[i-1]<58) res=res+cur*(string[i-1]-48); else res=res+cur*(string[i-1]-65+10);
  174. cur=cur*16;
  175. }
  176. return res;
  177. }
  178.  
  179. // -----------------------------------------------------------------------------
  180.  
  181. public OnFilterScriptInit( )
  182. {
  183. print(" ");
  184. print(" ~ ZEN ~ The Road to Enlightenment ~");
  185. print(" Inline GangZone-Editor");
  186. print(" by mabako");
  187. print(" ");
  188.  
  189. // Initalizing Variables
  190. emptyplayer[ pGangZone ] = -1;
  191.  
  192. OnGameModeInit();
  193.  
  194. for( new playerid = 0; playerid < GetMaxPlayers(); playerid ++ )
  195. {
  196. if( IsPlayerConnected( playerid ) )
  197. {
  198. OnPlayerConnect( playerid );
  199. }
  200. }
  201.  
  202. SetTimer("DragAndDropUpdate", 500, 1);
  203. return 1;
  204. }
  205.  
  206. // -----------------------------------------------------------------------------
  207.  
  208. public OnFilterScriptExit( )
  209. {
  210. for( new zoneID = 0; zoneID < MAX_GANG_ZONES; zoneID ++ )
  211. {
  212. if( gangzones[ zoneID ][ gID ] != -1 )
  213. {
  214. GangZoneHideForAll( gangzones[ zoneID ][ gID ] );
  215. GangZoneDestroy( gangzones[ zoneID ][ gID ] );
  216. }
  217. }
  218. for( new playerid = 0; playerid < GetMaxPlayers(); playerid ++ )
  219. {
  220. if( players[ playerid ][ pColorSelect ] == true )
  221. {
  222. GameTextForPlayer( playerid, " ", 5000, 3 );
  223. TogglePlayerControllable( playerid, 1 );
  224. }
  225. }
  226.  
  227. return 1;
  228. }
  229.  
  230. // -----------------------------------------------------------------------------
  231.  
  232. public OnGameModeExit( )
  233. {
  234. OnFilterScriptExit( );
  235.  
  236. return 1;
  237. }
  238.  
  239. // -----------------------------------------------------------------------------
  240.  
  241. public OnGameModeInit( )
  242. {
  243. for( new zoneID = 0; zoneID < MAX_GANG_ZONES; zoneID ++ )
  244. {
  245. gangzones[ zoneID ][ gID ] = -1;
  246. }
  247.  
  248. return 1;
  249. }
  250.  
  251. // -----------------------------------------------------------------------------
  252.  
  253. public OnPlayerConnect( playerid )
  254. {
  255. SendClientMessage( playerid, MESSAGECOLOR, "This Server uses ZEN Version " ZEN_VERSION ".");
  256. players[ playerid ] = emptyplayer;
  257.  
  258. return 1;
  259. }
  260.  
  261. // -----------------------------------------------------------------------------
  262. public OnPlayerSpawn( playerid )
  263. {
  264. for( new zoneID = 0; zoneID < MAX_GANG_ZONES; zoneID ++ )
  265. {
  266. if( gangzones[ zoneID ][ gStatus ] == STATUS_CREATED )
  267. {
  268. GangZoneShowForPlayer( playerid, gangzones[ zoneID ][ gID ], GetColor( gangzones[ zoneID ][ gColors ] ));
  269. }
  270. }
  271. return 1;
  272. }
  273.  
  274. // -----------------------------------------------------------------------------
  275.  
  276. public OnPlayerDeath( playerid, killerid, reason )
  277. {
  278. #pragma unused killerid,reason
  279. if( players[ playerid ][ pDrag ] == true )
  280. {
  281. players[ playerid ][ pMenu ] = true;
  282. OnPlayerSelectedMenuRow(playerid, 4); // call the DROP function
  283. }
  284. return 1;
  285. }
  286.  
  287. // -----------------------------------------------------------------------------
  288.  
  289. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  290. {
  291. #if ADMIN_ONLY == 1
  292. if(!IsPlayerAdmin(playerid)) return 1;
  293. #endif
  294. if( players[ playerid ][ pColorSelect ] == true )
  295. {
  296. if( KEY_SECONDARY_ATTACK & newkeys && !(KEY_SECONDARY_ATTACK & oldkeys ))
  297. {
  298. players[ playerid ][ pColorSelect ] = false;
  299. players[ playerid ][ pGangZone ] = INVALID_GANG_ZONE;
  300. TogglePlayerControllable( playerid, 1 );
  301. GameTextForPlayer( playerid, " ", 5000, 3 );
  302. }
  303. }
  304. else if( KEY_CROUCH & newkeys && KEY_SPRINT & newkeys )
  305. {
  306. if( players[ playerid ][ pMenu ] == false )
  307. {
  308. if( !IsValidMenu( zenMenu ) )
  309. {
  310. zenMenu = CreateMenu("GangZone Editor", 1, 10.0, 100.0, 200.0, 0.0);
  311. if( _:zenMenu == INVALID_MENU )
  312. {
  313. return 1;
  314. }
  315. AddMenuItem( zenMenu, 0, "Create Zone"); // 0
  316. AddMenuItem( zenMenu, 0, "Pick a Zone-Color"); // 1
  317. AddMenuItem( zenMenu, 0, "Destroy Zone"); // 2
  318. AddMenuItem( zenMenu, 0, "Drag (nearest edge)"); // 3
  319. AddMenuItem( zenMenu, 0, "Drop (current pos)"); // 4
  320. AddMenuItem( zenMenu, 0, "Glue Edge to next zones"); // 5
  321. AddMenuItem( zenMenu, 0, "Exit"); // 6
  322. }
  323. if( _:zenMenu != INVALID_MENU )
  324. {
  325. ShowMenuForPlayer( zenMenu, playerid );
  326. players[ playerid ][ pMenu ] = true;
  327. }
  328. }
  329. }
  330. return 1;
  331. }
  332.  
  333. // -----------------------------------------------------------------------------
  334.  
  335. public OnPlayerCommandText( playerid, cmdtext[] )
  336. {
  337. #if ADMIN_ONLY == 1
  338. if(!IsPlayerAdmin(playerid)) return 0;
  339. #endif
  340.  
  341. new b, c;
  342. while ((c = cmdtext[b++])) if (c < 0x20 || c > 0x7E) return 0; // Fix by Y_Less
  343.  
  344. if( !strcmp(cmdtext, "/zen", true, 4 ) )
  345. {
  346. switch( strlen( cmdtext ))
  347. {
  348. case 4:
  349. {
  350. SendClientMessage( playerid, MESSAGECOLOR, " " );
  351. SendClientMessage( playerid, MESSAGECOLOR, "Use '/zen help' to get a list of commands");
  352. SendClientMessage( playerid, MESSAGECOLOR, "'/zen basics' will show you some basics for ZEN");
  353. SendClientMessage( playerid, MESSAGECOLOR, "CROUCH + SPRINT keys will open the ZEN menu");
  354. return 1;
  355. }
  356. case 5:
  357. {
  358. if( cmdtext[4] == ' ' )
  359. {
  360. return OnPlayerCommandText( playerid, "/zen" );
  361. }
  362. return 0;
  363. }
  364. default:
  365. {
  366. new cmd[ 30 ], index = strfind(cmdtext," ") + 1;
  367. cmd = strtok( cmdtext, index );
  368.  
  369. if(!strcmp(cmd,"help",true))
  370. {
  371. SendClientMessage( playerid, MESSAGECOLOR, " " );
  372. SendClientMessage( playerid, MESSAGECOLOR, "ZEN ~ The Road to Enlightenment" );
  373. if( players[ playerid ][ pGangZone ] == INVALID_GANG_ZONE )
  374. {
  375. SendClientMessage( playerid, MESSAGECOLOR, " /zen create - Create a zone | /zen drag - Drags zone" );
  376. }
  377. else
  378. {
  379. SendClientMessage( playerid, MESSAGECOLOR, " /zen destroy - Destroys current Zone. | /zen color - chooses color" );
  380. SendClientMessage( playerid, MESSAGECOLOR, " /zen drop - Saves Zone Positions");
  381. }
  382. SendClientMessage( playerid, MESSAGECOLOR, " /zen glue - will Glue the zone you're in to NORTH/EAST/SOUTH/WEST zones" );
  383. SendClientMessage( playerid, MESSAGECOLOR, " /zen basics - shows some intro to ZEN | /zen about - will show some credit" );
  384. SendClientMessage( playerid, MESSAGECOLOR, " /zen cset [R] [G] [B] [A] - sets a RGBA color for your current zone" );
  385. if( IsPlayerAdmin( playerid ))
  386. {
  387. SendClientMessage( playerid, MESSAGECOLOR, " To view all Admin functions, type /zen admin help" );
  388. }
  389. return 1;
  390. }
  391.  
  392. if(!strcmp(cmd,"admin",true) && IsPlayerAdmin(playerid))
  393. {
  394. cmd = strtok( cmdtext, index );
  395. if( strlen( cmd ) == 0 || !strcmp(cmd,"help",true) )
  396. {
  397. SendClientMessage( playerid, MESSAGECOLOR, " " );
  398. SendClientMessage( playerid, MESSAGECOLOR, "ZEN ~ Admin" );
  399. SendClientMessage( playerid, MESSAGECOLOR, "/zen admin su [playerid] [command] - executes the command as another user" );
  400. SendClientMessage( playerid, MESSAGECOLOR, "/zen admin clear - deletes all Gang Zones" );
  401. SendClientMessage( playerid, MESSAGECOLOR, "/zen admin save - output a file with GangZoneCreate() stuff" );
  402. return 1;
  403. }
  404. if( !strcmp(cmd,"su",true) )
  405. {
  406. new temp[30];
  407.  
  408. temp = strtok( cmdtext, index );
  409. if( strlen( temp ) == 0 )
  410. {
  411. SendClientMessage( playerid, ERRORCOLOR, "Syntax: /zen admin su [playerid] [command]" );
  412. return 1;
  413. }
  414.  
  415. new targetid = strval( temp );
  416. if( !IsPlayerConnected( targetid ))
  417. {
  418. SendClientMessage( playerid, ERRORCOLOR, "No Player with that ID connected" );
  419. return 1;
  420. }
  421. if( strlen( cmdtext ) <= index )
  422. {
  423. SendClientMessage( playerid, ERRORCOLOR, "Syntax: /zen admin su [playerid] [command]" );
  424. return 1;
  425. }
  426.  
  427. new command[ 128 ];
  428. format( command, 128, "/zen %s", cmdtext[ index ]);
  429. OnPlayerCommandText( targetid, command );
  430.  
  431.  
  432. SendClientMessage( playerid, MESSAGECOLOR, "[ZEN ADMIN] SU Command Executed" );
  433. return 1;
  434. }
  435. if( !strcmp(cmd,"clear",true) )
  436. {
  437. SendClientMessage( playerid, MESSAGECOLOR, "[ZEN ADMIN] Map Cleared from all Gang Zones" );
  438. OnGameModeExit();
  439.  
  440. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  441. {
  442.  
  443. }
  444.  
  445. return 1;
  446. }
  447. if( !strcmp(cmd,"save",true))
  448. {
  449. new File:fhandle;
  450. fhandle = fopen("zen.pwn", io_write);
  451. if(!fhandle) return 0;
  452.  
  453. fwrite( fhandle, "#include <a_samp>\r\n\r\n// ZEN Output File\r\n// This File has been created by ZEN - InGame GangZone Editor by mabako\r\n\r\nenum GangZone\r\n{\r\n\009gzID,\r\n\009Float: gzPos[4],\r\n\009gzColor\r\n}\r\n");
  454.  
  455. new gangzone_count;
  456. for( new zoneID = 0; zoneID < MAX_GANG_ZONES; zoneID ++ )
  457. {
  458. if( gangzones[ zoneID ][ gStatus ] == STATUS_CREATED )
  459. {
  460. gangzone_count++;
  461. }
  462. }
  463. fwrite( fhandle, "new GangZones[][ GangZone ] = {\r\n");
  464.  
  465.  
  466. for( new zoneID = 0; zoneID < MAX_GANG_ZONES; zoneID ++ )
  467. {
  468. if( gangzones[ zoneID ][ gStatus ] == STATUS_CREATED )
  469. {
  470. gangzone_count--;
  471. new line[ 300 ];
  472. format( line, 300, "\009{ INVALID_GANG_ZONE, {%.1f, %.1f, %.1f, %.1f}, 0x%s }", gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxX ], gangzones[ zoneID ][ gMaxY ], IntToHex(GetColor(gangzones[ zoneID ][ gColors ])) );
  473. fwrite( fhandle, line );
  474. if( gangzone_count != 0 ) fwrite( fhandle, ",");
  475. fwrite( fhandle, "\r\n");
  476. }
  477. }
  478. fwrite( fhandle,"};\r\n\r\npublic OnGameModeInit( )\r\n{\r\n");
  479. fwrite( fhandle,"\009for( new gz = 0; gz < sizeof( GangZones ); gz ++ )\r\n\009{\r\n");
  480. fwrite( fhandle,"\009\009GangZones[ gz ][ gzID ] = GangZoneCreate( GangZones[ gz ][ gzPos ][ 0 ], GangZones[ gz ][ gzPos ][ 1 ], GangZones[ gz ][ gzPos ][ 2 ], GangZones[ gz ][ gzPos ][ 3 ]);" );
  481. fwrite( fhandle,"\r\n\009}\r\n}" );
  482. fwrite( fhandle,"\r\n\r\npublic OnPlayerSpawn( playerid )\r\n{\r\n");
  483. fwrite( fhandle,"\009for( new gz = 0; gz < sizeof( GangZones ); gz ++ )\r\n\009{\r\n");
  484. fwrite( fhandle,"\009\009GangZoneShowForPlayer( playerid, GangZones[ gz ][ gzID ], GangZones[ gz ][ gzColor ]);" );
  485. fwrite( fhandle,"\r\n\009}\r\n}" );
  486. fclose(fhandle);
  487. SendClientMessage( playerid, MESSAGECOLOR, "[ZEN ADMIN] Map has been saved!");
  488. return 1;
  489. }
  490. if(!strcmp(cmd,"load",true))
  491. {
  492. LoadZENFile();
  493. return 1;
  494. }
  495. return 0;
  496. }
  497.  
  498. if(!strcmp(cmd,"basics",true) || !strcmp(cmd,"basic",true))
  499. {
  500. SendClientMessage( playerid, MESSAGECOLOR, "ZEN: Inline GangZone Editor" );
  501. SendClientMessage( playerid, MESSAGECOLOR, " With ZEN, you can live CREATE, DESTROY and DRAG & DROP Gang zones,");
  502. SendClientMessage( playerid, MESSAGECOLOR, " It's also possible to change their COLOR or GLUE two GangZones together");
  503. SendClientMessage( playerid, MESSAGECOLOR, " means there will be no gap between those both.");
  504. return 1;
  505. }
  506. if(!strcmp(cmd,"create",true))
  507. {
  508. players[ playerid ][ pMenu ] = true;
  509. OnPlayerSelectedMenuRow(playerid, 0);
  510. return 1;
  511. }
  512. if(!strcmp(cmd,"color",true))
  513. {
  514. players[ playerid ][ pMenu ] = true;
  515. OnPlayerSelectedMenuRow(playerid, 1);
  516. return 1;
  517. }
  518. if(!strcmp(cmd,"cset",true))
  519. { // COLOR SET, a useful function to just set the color instead of having GameText stuff
  520. new zoneID = GetPlayerGangZone( playerid );
  521. if( zoneID < 0 )
  522. {
  523. return 1;
  524. }
  525.  
  526. for( new i = 0; i < 4; i ++ )
  527. {
  528. gangzones[ zoneID ][ gColors ][ i ] = strval( strtok(cmdtext, index) );
  529. }
  530.  
  531. // re-draw the gangzone
  532. Zen_ReDraw( zoneID );
  533.  
  534. return 1;
  535. }
  536. if(!strcmp(cmd,"destroy",true))
  537. {
  538. players[ playerid ][ pMenu ] = true;
  539. OnPlayerSelectedMenuRow(playerid, 2);
  540. return 1;
  541. }
  542. if(!strcmp(cmd,"drag",true))
  543. {
  544. players[ playerid ][ pMenu ] = true;
  545. OnPlayerSelectedMenuRow(playerid, 3);
  546. return 1;
  547. }
  548. if(!strcmp(cmd,"drop",true))
  549. {
  550. players[ playerid ][ pMenu ] = true;
  551. OnPlayerSelectedMenuRow(playerid, 4);
  552. return 1;
  553. }
  554. if(!strcmp(cmd,"glue",true))
  555. {
  556. new direction[ 30 ];
  557. direction = strtok( cmdtext, index );
  558.  
  559. if( strlen( direction ) > 0 )
  560. {
  561. new zoneID = GetPlayerGangZone( playerid );
  562.  
  563. if( zoneID < 0 )
  564. {
  565. return 1;
  566. }
  567.  
  568. if(!strcmp(direction,"n",true)||!strcmp(direction,"north",true))
  569. {
  570. Zen_Glue( zoneID, DIRECTION_NORTH );
  571. return 1;
  572. }
  573. if(!strcmp(direction,"e",true)||!strcmp(direction,"east",true))
  574. {
  575. Zen_Glue( zoneID, DIRECTION_EAST );
  576. return 1;
  577. }
  578. if(!strcmp(direction,"s",true)||!strcmp(direction,"south",true))
  579. {
  580. Zen_Glue( zoneID, DIRECTION_SOUTH );
  581. return 1;
  582. }
  583. if(!strcmp(direction,"w",true)||!strcmp(direction,"west",true))
  584. {
  585. Zen_Glue( zoneID, DIRECTION_WEST );
  586. return 1;
  587. }
  588. }
  589.  
  590. // no direction given, open Menu
  591. players[ playerid ][ pMenu ] = true;
  592. OnPlayerSelectedMenuRow(playerid, 5);
  593. return 1;
  594. }
  595. if(!strcmp(cmd,"about",true))
  596. {
  597. SendClientMessage( playerid, MESSAGECOLOR, "ZEN ~ The Road to Enlightenment");
  598. SendClientMessage( playerid, MESSAGECOLOR, " ZEN is an InGame GangZone-Editor, completely written from Scratch.");
  599. SendClientMessage( playerid, MESSAGECOLOR, " Copyright (c) 2007 mabako network. All Rights Reserved.");
  600. SendClientMessage( playerid, MESSAGECOLOR, " This Server uses ZEN Version " ZEN_VERSION ".");
  601. return 1;
  602. }
  603. return 0;
  604. }
  605. }
  606. }
  607. return 0;
  608. }
  609.  
  610. // -----------------------------------------------------------------------------
  611.  
  612. public OnPlayerSelectedMenuRow(playerid, row)
  613. {
  614. #if ADMIN_ONLY == 1
  615. if(!IsPlayerAdmin(playerid)) return 1;
  616. #endif
  617. if( players[ playerid ][ pMenu ] == true )
  618. {
  619. players[ playerid ][ pMenu ] = false;
  620. switch( row )
  621. {
  622. case 0:
  623. {
  624. // Create a Zone
  625. new Float:x, Float:y, Float:z;
  626. GetPlayerPos( playerid, x, y, z );
  627. new zoneID = Zen_CreateZone( x, y, floatround( x + 0.1 ), floatround( y + 0.1 ) );
  628. Zen_Drag( playerid, zoneID, x, y ); // tell the script where we start dragging stuff
  629. SendClientMessage( playerid, MESSAGECOLOR, "You can now drag this Zone around!");
  630. }
  631. case 1:
  632. {
  633. // color-picker
  634. new zoneID = GetPlayerGangZone( playerid );
  635. if( zoneID < 0 )
  636. {
  637. return 1;
  638. }
  639.  
  640. players[ playerid ][ pColorSelect ] = true;
  641. players[ playerid ][ pColorSelected ] = 2;
  642.  
  643. TogglePlayerControllable( playerid, 0 );
  644. }
  645. case 2:
  646. {
  647. // destroy the zone
  648. new zoneID = GetPlayerGangZone( playerid );
  649. if( zoneID < 0 )
  650. {
  651. return 1;
  652. }
  653.  
  654. Zen_Destroy( zoneID );
  655. }
  656. case 3:
  657. {
  658. // drag the zone
  659. if( players[ playerid ][ pDrag ] == true )
  660. {
  661. return 1;
  662. }
  663.  
  664. new zoneID = GetPlayerGangZone( playerid );
  665. if( zoneID < 0 )
  666. {
  667. return 1;
  668. }
  669.  
  670. new Float: px, Float: py, Float: pz;
  671. GetPlayerPos( playerid, px, py, pz );
  672. // ---
  673. // nearest x-point
  674. if( floatabs( px - gangzones[ zoneID ][ gMinX ] ) < floatabs( px - gangzones[ zoneID ][ gMaxX ] ) )
  675. {
  676. // nearer to point MinX
  677. gangzones[ zoneID ][ gMinX ] = px;
  678. }
  679. else
  680. {
  681. gangzones[ zoneID ][ gMaxX ] = px;
  682. }
  683.  
  684. // nearest y-point
  685. if( floatabs( py - gangzones[ zoneID ][ gMinY ] ) < floatabs( py - gangzones[ zoneID ][ gMaxY ] ) )
  686. {
  687. // nearer to point MinX
  688. gangzones[ zoneID ][ gMinY ] = py;
  689. }
  690. else
  691. {
  692. gangzones[ zoneID ][ gMaxY ] = py;
  693. }
  694.  
  695. players[ playerid ][ pDrag ] = true;
  696. players[ playerid ][ pGangZone ] = zoneID;
  697.  
  698. players[ playerid ][ pPosX ] = px;
  699. players[ playerid ][ pPosY ] = py;
  700. players[ playerid ][ pPosZ ] = pz;
  701.  
  702. Zen_Drag( playerid, zoneID, px, py );
  703.  
  704. }
  705. case 4:
  706. {
  707. // drop the zone
  708. if( players[ playerid ][ pDrag ] == false )
  709. {
  710. return 1;
  711. }
  712.  
  713. new zoneID = players[ playerid ][ pGangZone ];
  714.  
  715. players[ playerid ][ pGangZone ] = INVALID_GANG_ZONE;
  716. players[ playerid ][ pDrag ] = false;
  717.  
  718. // Round positions, there isn't that much high-precision there
  719. gangzones[ zoneID ][ gMinX ] = floatround( gangzones[ zoneID ][ gMinX ] );
  720. gangzones[ zoneID ][ gMinY ] = floatround( gangzones[ zoneID ][ gMinY ] );
  721. gangzones[ zoneID ][ gMaxX ] = floatround( gangzones[ zoneID ][ gMaxX ] );
  722. gangzones[ zoneID ][ gMaxY ] = floatround( gangzones[ zoneID ][ gMaxY ] );
  723.  
  724. // Fix that'll show some odd zone
  725. new zone[ gangzone ];
  726. zone = gangzones[ zoneID ];
  727. zone[ gMinX ] = fmin( gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMaxX ] );
  728. zone[ gMaxX ] = fmax( gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMaxX ] );
  729. zone[ gMinY ] = fmin( gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxY ] );
  730. zone[ gMaxY ] = fmax( gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxY ] );
  731. gangzones[ zoneID ] = zone;
  732.  
  733. Zen_ReCreate( zoneID );
  734. }
  735. case 5:
  736. {
  737. // Glue Edge to next zones
  738. if( !IsValidMenu( zenDirection ))
  739. {
  740. zenDirection = CreateMenu("Glue to ...", 1, 10.0, 100.0, 100.0, 0.0);
  741. if( _:zenDirection == INVALID_MENU )
  742. {
  743. return 1;
  744. }
  745. AddMenuItem( zenDirection, 0, "North"); // 0
  746. AddMenuItem( zenDirection, 0, "East"); // 1
  747. AddMenuItem( zenDirection, 0, "South"); // 2
  748. AddMenuItem( zenDirection, 0, "West"); // 3
  749. AddMenuItem( zenDirection, 0, "Exit"); // 4
  750. }
  751. if( _:zenDirection != INVALID_MENU )
  752. {
  753. ShowMenuForPlayer( zenDirection, playerid );
  754. players[ playerid ][ pDirectionMenu ] = true;
  755. return 1;
  756. }
  757. }
  758. case 6:
  759. {
  760. // We went to EXIT MENU... which's pretty no function
  761. return 1;
  762. }
  763. }
  764. return 1;
  765. }
  766.  
  767. if( players[ playerid ][ pDirectionMenu ] == true )
  768. {
  769. players[ playerid ][ pDirectionMenu ] = false;
  770. switch(row)
  771. {
  772. case DIRECTION_NORTH .. DIRECTION_WEST:
  773. {
  774. new zoneID = GetPlayerGangZone( playerid );
  775. if( zoneID < 0 )
  776. {
  777. return 1;
  778. }
  779. Zen_Glue( zoneID, row );
  780. }
  781. case 4:
  782. {
  783. // Exit... nothing
  784. return 1;
  785. }
  786. }
  787. return 1;
  788. }
  789. return 1;
  790. }
  791.  
  792. // -----------------------------------------------------------------------------
  793. public OnPlayerExitedMenu(playerid)
  794. {
  795. #if ADMIN_ONLY == 1
  796. if(!IsPlayerAdmin(playerid)) return 1;
  797. #endif
  798. players[ playerid ][ pMenu ] = false;
  799. players[ playerid ][ pDirectionMenu ] = false;
  800. return 1;
  801. }
  802.  
  803.  
  804. // -----------------------------------------------------------------------------
  805. // Our ZEN functions [ZEN]
  806.  
  807. // Zen_CreateZone
  808. // Creates a Zone
  809. Zen_CreateZone( Float: minx, Float: miny, Float: maxx, Float: maxy )
  810. {
  811. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  812. {
  813. if( gangzones[ i ][ gStatus ] == STATUS_NO_ZONE )
  814. {
  815. gangzones[ i ][ gStatus ] = STATUS_CREATED;
  816. gangzones[ i ][ gMinX ] = fmin( minx, maxx );
  817. gangzones[ i ][ gMinY ] = fmin( miny, maxy );
  818. gangzones[ i ][ gMaxX ] = fmax( minx, maxx );
  819. gangzones[ i ][ gMaxY ] = fmax( miny, maxy );
  820. gangzones[ i ][ gColors ] = { NEW_ZONE_COLOR_R, NEW_ZONE_COLOR_G, NEW_ZONE_COLOR_B, NEW_ZONE_COLOR_A };
  821.  
  822. gangzones[ i ][ gID ] = GangZoneCreate( gangzones[ i ][ gMinX ], gangzones[ i ][ gMinY ], gangzones[ i ][ gMaxX ], gangzones[ i ][ gMaxY ] );
  823.  
  824. GangZoneShowForAll( gangzones[ i ][ gID ], GetColor( gangzones[ i ][ gColors ] ));
  825.  
  826. return i;
  827. }
  828. }
  829. return INVALID_GANG_ZONE;
  830. }
  831.  
  832. // -----------------------------------------------------------------------------
  833.  
  834. Zen_Destroy( zoneID )
  835. {
  836. GangZoneHideForAll( gangzones[ zoneID ][ gID ] );
  837. GangZoneDestroy( gangzones[ zoneID ][ gID ] );
  838.  
  839. new no_zone[ gangzone ];
  840. gangzones[ zoneID ] = no_zone;
  841.  
  842. for( new playerid = 0; playerid < GetMaxPlayers(); playerid ++ )
  843. {
  844. if( players[ playerid ][ pGangZone ] == zoneID )
  845. {
  846. players[ playerid ][ pGangZone ] = INVALID_GANG_ZONE;
  847. players[ playerid ][ pDrag ] = false;
  848. }
  849. }
  850. }
  851.  
  852. // -----------------------------------------------------------------------------
  853.  
  854. Zen_Drag( playerid, zoneID, Float: start_x, Float: start_y )
  855. {
  856. players[ playerid ][ pDrag ] = true;
  857. players[ playerid ][ pGangZone ] = zoneID;
  858.  
  859.  
  860. if( floatabs( start_x - gangzones[ zoneID ][ gMinX ] ) < floatabs( start_x - gangzones[ zoneID ][ gMaxX ] ) )
  861. {
  862. gangzones[ zoneID ][ gMinX ] = start_x;
  863. }
  864. else
  865. {
  866. gangzones[ zoneID ][ gMaxX ] = start_x;
  867. }
  868.  
  869.  
  870. if( floatabs( start_y - gangzones[ zoneID ][ gMinY ] ) < floatabs( start_y - gangzones[ zoneID ][ gMaxY ] ) )
  871. {
  872. gangzones[ zoneID ][ gMinY ] = start_y;
  873. }
  874. else
  875. {
  876. gangzones[ zoneID ][ gMaxY ] = start_y;
  877. }
  878.  
  879. Zen_ReCreate( zoneID );
  880.  
  881. players[ playerid ][ pPosX ] = start_x;
  882. players[ playerid ][ pPosY ] = start_y;
  883. }
  884.  
  885. // -----------------------------------------------------------------------------
  886.  
  887. public DragAndDropUpdate( )
  888. {
  889. for( new playerid = 0; playerid < GetMaxPlayers(); playerid ++ )
  890. {
  891. if( players[ playerid ][ pDrag ] == true && players[ playerid ][ pColorSelect ] == false)
  892. {
  893. // Player is dragging a gang Zone...
  894. new zoneID = players[ playerid ][ pGangZone ];
  895.  
  896. // get new coords of the player
  897. new Float: px, Float: py, Float: pz;
  898. GetPlayerPos( playerid, px, py, pz );
  899.  
  900. // let's see what coords are changed
  901. if( players[ playerid ][ pPosX ] == gangzones[ zoneID ][ gMaxX ] )
  902. {
  903. // Max X was it before, now see how it changed
  904. if( px < gangzones[ zoneID ][ gMinX ] )
  905. {
  906. // it is smaller than previous gMinX was...
  907. gangzones[ zoneID ][ gMaxX ] = gangzones[ zoneID ][ gMinX ];
  908. gangzones[ zoneID ][ gMinX ] = px;
  909. }
  910. else
  911. {
  912. // larger as gMinX
  913. gangzones[ zoneID ][ gMaxX ] = px;
  914. }
  915. }
  916. else
  917. {
  918. // Min X was it before, now see how it changed
  919. if( px > gangzones[ zoneID ][ gMaxX ] )
  920. {
  921. // it is smaller than previous gMinX was...
  922. gangzones[ zoneID ][ gMinX ] = gangzones[ zoneID ][ gMaxX ];
  923. gangzones[ zoneID ][ gMaxX ] = px;
  924. }
  925. else
  926. {
  927. // smaller than gMaxX
  928. gangzones[ zoneID ][ gMinX ] = px;
  929. }
  930. }
  931.  
  932.  
  933. if( players[ playerid ][ pPosY ] == gangzones[ zoneID ][ gMaxY ] )
  934. {
  935. // Max Y was it before, now see how it changed
  936. if( py < gangzones[ zoneID ][ gMinY ] )
  937. {
  938. // it is smaller than previous gMinY was...
  939. gangzones[ zoneID ][ gMaxY ] = gangzones[ zoneID ][ gMinY ];
  940. gangzones[ zoneID ][ gMinY ] = py;
  941. }
  942. else
  943. {
  944. // larger as gMinY
  945. gangzones[ zoneID ][ gMaxY ] = py;
  946. }
  947. }
  948. else
  949. {
  950. // Min Y was it before, now see how it changed
  951. if( px > gangzones[ zoneID ][ gMaxY ] )
  952. {
  953. // it is smaller than previous gMinY was...
  954. gangzones[ zoneID ][ gMinY ] = gangzones[ zoneID ][ gMaxY ];
  955. gangzones[ zoneID ][ gMaxY ] = py;
  956. }
  957. else
  958. {
  959. // smaller than gMaxY
  960. gangzones[ zoneID ][ gMinY ] = py;
  961. }
  962. }
  963.  
  964. players[ playerid ][ pPosX ] = px;
  965. players[ playerid ][ pPosY ] = py;
  966.  
  967. new zone[ gangzone ];
  968. zone = gangzones[ zoneID ];
  969. zone[ gMinX ] = fmin( gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMaxX ] );
  970. zone[ gMaxX ] = fmax( gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMaxX ] );
  971. zone[ gMinY ] = fmin( gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxY ] );
  972. zone[ gMaxY ] = fmax( gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxY ] );
  973. gangzones[ zoneID ] = zone;
  974.  
  975. Zen_ReCreate( zoneID );
  976. }
  977.  
  978. else if( players[ playerid ][ pColorSelect ] == true )
  979. {
  980. new zoneID = players[ playerid ][ pGangZone ];
  981.  
  982.  
  983. // Let's see which keys are pressed
  984. new keys, updown, leftright;
  985. GetPlayerKeys( playerid, keys, updown, leftright );
  986.  
  987. if( updown == KEY_DOWN )
  988. {
  989. gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] -= 5;
  990. if( gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] < 0 ) gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] = 0;
  991.  
  992. // re-draw the gangzone
  993. Zen_ReDraw( zoneID );
  994. }
  995. else if( updown == KEY_UP )
  996. {
  997. gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] += 5;
  998. if( gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] > 0xFF ) gangzones[ zoneID ][ gColors ][ players[ playerid ][ pColorSelected ] ] = 0xFF;
  999.  
  1000. // re-draw the gangzone
  1001. Zen_ReDraw( zoneID );
  1002. }
  1003.  
  1004.  
  1005.  
  1006. if( leftright == KEY_LEFT )
  1007. {
  1008. players[ playerid ][ pColorSelected ] = (players[ playerid ][ pColorSelected ] - 1) % 4;
  1009. }
  1010. else if( leftright == KEY_RIGHT )
  1011. {
  1012. players[ playerid ][ pColorSelected ] = (players[ playerid ][ pColorSelected ] + 1) % 4;
  1013. }
  1014.  
  1015.  
  1016. new ctext[128];
  1017. new colors[ 4 ][ 4 ] = {"~r~","~g~","~b~","~w~"};
  1018. for( new i = 0; i < 4; i ++)
  1019. {
  1020. if( players[ playerid ][ pColorSelected ] == i )
  1021. {
  1022. format( ctext, sizeof(ctext), "%s ~u~%s%d~d~", ctext, colors[ i ], gangzones[ zoneID ][ gColors ][ i ]);
  1023. }
  1024. else
  1025. {
  1026. format( ctext, sizeof(ctext), "%s %s%d", ctext, colors[ i ], gangzones[ zoneID ][ gColors ][ i ]);
  1027. }
  1028. }
  1029. format(ctext, sizeof(ctext), "%s~n~~w~Use ~y~~k~~VEHICLE_ENTER_EXIT~~w~ to save this color.", ctext);
  1030. GameTextForPlayer( playerid, ctext, 5000, 3 );
  1031. }
  1032. }
  1033. }
  1034.  
  1035. // -----------------------------------------------------------------------------
  1036.  
  1037. Zen_Glue( zoneID, direction )
  1038. {
  1039. // this is the hard part... GLUE the zone to the next north/east/south/west ones.
  1040. new Float:distance;
  1041. new Float:minDist = 9999.0;
  1042. new minZone = INVALID_GANG_ZONE;
  1043. switch( direction )
  1044. {
  1045. case DIRECTION_NORTH:
  1046. {
  1047. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  1048. {
  1049. if( gangzones[ i ][ gStatus ] == STATUS_CREATED )
  1050. {
  1051. distance = gangzones[ i ][ gMinY ] - gangzones[ zoneID ][ gMaxY ];
  1052. if( distance > 0 && distance < minDist )
  1053. {
  1054. /* is above the zone, see if it's just Y above the zone or in the zone corridor */
  1055. if(gangzones[ i ][ gMaxX ] > gangzones[ zoneID ][ gMinX ] && gangzones[ i ][ gMinX ] < gangzones[ zoneID ][ gMaxX ] )
  1056. {
  1057. minDist = distance;
  1058. minZone = i;
  1059. }
  1060. }
  1061. }
  1062. }
  1063.  
  1064. if( minZone != INVALID_GANG_ZONE )
  1065. {
  1066. gangzones[ zoneID ][ gMaxY ] += minDist;
  1067. Zen_ReCreate( zoneID );
  1068. return;
  1069. }
  1070. }
  1071. case DIRECTION_EAST:
  1072. {
  1073. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  1074. {
  1075. if( gangzones[ i ][ gStatus ] == STATUS_CREATED )
  1076. {
  1077. distance = gangzones[ i ][ gMinX ] - gangzones[ zoneID ][ gMaxX ];
  1078. if( distance > 0 && distance < minDist )
  1079. {
  1080. /* is above the zone, see if it's just Y above the zone or in the zone corridor */
  1081. if(gangzones[ i ][ gMaxY ] > gangzones[ zoneID ][ gMinY ] && gangzones[ i ][ gMinY ] < gangzones[ zoneID ][ gMaxY ] )
  1082. {
  1083. minDist = distance;
  1084. minZone = i;
  1085. }
  1086. }
  1087. }
  1088. }
  1089.  
  1090. if( minZone != INVALID_GANG_ZONE )
  1091. {
  1092. gangzones[ zoneID ][ gMaxX ] += minDist;
  1093. Zen_ReCreate( zoneID );
  1094. return;
  1095. }
  1096. }
  1097. case DIRECTION_SOUTH:
  1098. {
  1099. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  1100. {
  1101. if( gangzones[ i ][ gStatus ] == STATUS_CREATED )
  1102. {
  1103. distance = gangzones[ zoneID ][ gMinY ] - gangzones[ i ][ gMaxY ];
  1104. if( distance > 0 && distance < minDist )
  1105. {
  1106. /* is above the zone, see if it's just Y above the zone or in the zone corridor */
  1107. if(gangzones[ i ][ gMaxX ] > gangzones[ zoneID ][ gMinX ] && gangzones[ i ][ gMinX ] < gangzones[ zoneID ][ gMaxX ] )
  1108. {
  1109. minDist = distance;
  1110. minZone = i;
  1111. }
  1112. }
  1113. }
  1114. }
  1115.  
  1116. if( minZone != INVALID_GANG_ZONE )
  1117. {
  1118. gangzones[ zoneID ][ gMinY ] -= minDist;
  1119. Zen_ReCreate( zoneID );
  1120. return;
  1121. }
  1122. }
  1123. case DIRECTION_WEST:
  1124. {
  1125. for( new i = 0; i < MAX_GANG_ZONES; i ++ )
  1126. {
  1127. if( gangzones[ i ][ gStatus ] == STATUS_CREATED )
  1128. {
  1129. distance = gangzones[ zoneID ][ gMinX ] - gangzones[ i ][ gMaxX ];
  1130. if( distance > 0 && distance < minDist )
  1131. {
  1132. /* is above the zone, see if it's just Y above the zone or in the zone corridor */
  1133. if(gangzones[ i ][ gMaxY ] > gangzones[ zoneID ][ gMinY ] && gangzones[ i ][ gMinY ] < gangzones[ zoneID ][ gMaxY ] )
  1134. {
  1135. minDist = distance;
  1136. minZone = i;
  1137. }
  1138. }
  1139. }
  1140. }
  1141.  
  1142. if( minZone != INVALID_GANG_ZONE )
  1143. {
  1144. gangzones[ zoneID ][ gMinX ] -= minDist;
  1145. Zen_ReCreate( zoneID );
  1146. return;
  1147. }
  1148. }
  1149. }
  1150. }
  1151.  
  1152. // -----------------------------------------------------------------------------
  1153.  
  1154. GetPlayerGangZone( playerid )
  1155. {
  1156. new zoneID = INVALID_GANG_ZONE;
  1157. if( players[ playerid ][ pGangZone ] >= 0 )
  1158. {
  1159. zoneID = players[ playerid ][ pGangZone ];
  1160. }
  1161. else
  1162. {
  1163. new Float:px, Float:py, Float:pz;
  1164. GetPlayerPos( playerid, px, py, pz );
  1165. for( new j = 0; j < MAX_GANG_ZONES; j ++ )
  1166. {
  1167. if( gangzones[ j ][ gStatus ] == STATUS_CREATED )
  1168. {
  1169. if( px > gangzones[ j ][ gMinX ] && px < gangzones[ j ][ gMaxX ]
  1170. && py > gangzones[ j ][ gMinY ] && py < gangzones[ j ][ gMaxY ] )
  1171. {
  1172. // First find out if another user edits this Gang Zone
  1173.  
  1174. for( new i = 0; i < GetMaxPlayers(); i ++ )
  1175. {
  1176. if( players[ i ][ pGangZone ] == j && players[ i ][ pDrag ] == true )
  1177. {
  1178. SendClientMessage( playerid, ERRORCOLOR, "This Zone is edited by another user");
  1179. return -2;
  1180. }
  1181. }
  1182. zoneID = j;
  1183. break;
  1184. }
  1185. }
  1186. }
  1187. }
  1188.  
  1189. if( zoneID == INVALID_GANG_ZONE )
  1190. {
  1191. SendClientMessage( playerid, ERRORCOLOR, "You're not in a zone");
  1192. return -2;
  1193. }
  1194. return zoneID;
  1195. }
  1196.  
  1197. // -----------------------------------------------------------------------------
  1198.  
  1199. Zen_ReCreate( zoneID )
  1200. {
  1201. GangZoneHideForAll( gangzones[ zoneID ][ gID ] );
  1202. GangZoneDestroy( gangzones[ zoneID ][ gID ] );
  1203.  
  1204. Zen_Create( zoneID );
  1205. }
  1206.  
  1207. // -----------------------------------------------------------------------------
  1208.  
  1209. Zen_Create( zoneID )
  1210. {
  1211. gangzones[ zoneID ][ gID ] = GangZoneCreate( gangzones[ zoneID ][ gMinX ], gangzones[ zoneID ][ gMinY ], gangzones[ zoneID ][ gMaxX ], gangzones[ zoneID ][ gMaxY ] );
  1212. GangZoneShowForAll( gangzones[ zoneID ][ gID ], GetColor( gangzones[ zoneID ][ gColors ] ));
  1213. }
  1214.  
  1215. // -----------------------------------------------------------------------------
  1216.  
  1217. Zen_ReDraw( zoneID )
  1218. {
  1219. GangZoneHideForAll( gangzones[ zoneID ][ gID ] );
  1220. GangZoneShowForAll( gangzones[ zoneID ][ gID ], GetColor( gangzones[ zoneID ][ gColors ] ));
  1221. }
  1222.  
  1223. // -----------------------------------------------------------------------------
  1224.  
  1225. LoadZENFile( )
  1226. {
  1227. if(!fexist("zen.pwn")) return 0;
  1228. new File: fhandle = fopen("zen.pwn", io_read );
  1229. if( !fhandle ) return 0;
  1230.  
  1231. new templine[ 200 ], bool:block = false;
  1232. while( fread( fhandle, templine ))
  1233. {
  1234. if( strlen( templine ) > 0 )
  1235. {
  1236. if(!strcmp( "new GangZones[][ GangZone ] = {", templine, true, strlen("new GangZones[][ GangZone ] = {") ))
  1237. {
  1238. block = true;
  1239. }
  1240. else if( block == true )
  1241. {
  1242. if(!strcmp("};", templine, true, 2 ))
  1243. {
  1244. block = false;
  1245. fclose( fhandle );
  1246. return 1;
  1247. }
  1248. else
  1249. {
  1250. strdel( templine, 0, strfind( templine, ", {" )+3);
  1251. while( strfind( templine, " ", true, 0 ) != -1 )
  1252. {
  1253. // now we need to delete all spaces
  1254. new position = strfind( templine, " ", true, 0 );
  1255. strdel( templine, position, position + 1 );
  1256. }
  1257. // now let's get the coords
  1258. new index, Float: c[4];
  1259. c[ 0 ] = floatstr( strtok( templine, index,"," ));
  1260. c[ 1 ] = floatstr( strtok( templine, index,"," ));
  1261. c[ 2 ] = floatstr( strtok( templine, index,"," ));
  1262. c[ 3 ] = floatstr( strtok( templine, index,"}" ));
  1263. strdel( templine, 0, index + 3 );
  1264.  
  1265. // colorz
  1266. new colors[ 4 ], temp[3];
  1267. for( new i = 0; i < 4; i ++ )
  1268. {
  1269. strmid( temp, templine, (2 * i), 2 * (i + 1) );
  1270. colors[ i ] = HexToInt( temp );
  1271. }
  1272. new zoneID = Zen_CreateZone( c[0], c[1], c[2], c[3] );
  1273. if(zoneID != INVALID_GANG_ZONE )
  1274. {
  1275. gangzones[ zoneID ][ gColors ] = colors;
  1276. Zen_ReDraw( zoneID );
  1277. }
  1278. }
  1279. }
  1280. }
  1281.  
  1282. }
  1283. fclose( fhandle );
  1284. return 1;
  1285. }
  1286.  
Advertisement
Add Comment
Please, Sign In to add comment