Advertisement
Paulo_AttacK

GzEditor By Paulo v1.0

Oct 7th, 2012
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.71 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. //        #### ########   ######     ######## ########    ###    ##     ##
  5. //         ##  ##     ## ##    ##       ##    ##         ## ##   ###   ###
  6. //         ##  ##     ## ##             ##    ##        ##   ##  #### ####
  7. //         ##  ########   ######        ##    ######   ##     ## ## ### ##
  8. //         ##  ##              ##       ##    ##       ######### ##     ##
  9. //         ##  ##        ##    ##       ##    ##       ##     ## ##     ##
  10. //        #### ##         ######        ##    ######## ##     ## ##     ##
  11. //
  12. //
  13. //                              GzEditor v1.0
  14. //
  15. /*                   ______          ______           _
  16. //                   | ___ \         | ___ \         | |
  17. //                   | |_/ /_   _    | |_/ /_ _ _   _| | ___
  18. //                   | ___ \ | | |   |  __/ _` | | | | |/ _ \
  19. //                   | |_/ / |_| |_  | | | (_| | |_| | | (_) |
  20. //                   \____/ \__, (_) \_|  \__,_|\__,_|_|\___/
  21. //                           __/ |
  22. //                          |___/
  23. */
  24. //            !!!   Crie e Edite suas Gz's Facilmente com esse FS   !!!
  25. //
  26. //          [iPs]TeaM soluções de programação em geral (agora com cursos)
  27. //
  28. //                  http://ips-team.forumeiros.com/ (contate-nos)
  29. //
  30. /////////////////////////////////////////////////////////////////////////////////
  31.  
  32. #include <a_samp>
  33.  
  34. #define MAX_GZ      50
  35. #define DialogID    1996
  36.  
  37. new pCount,
  38.     pMaxPlayers,
  39.     pGzSave,
  40.     Float: pX,
  41.     Float: pY,
  42.     Float: pZ,
  43.     pGzName[MAX_GZ][24],
  44.     pGz[MAX_GZ] = {0xFFFF, ...},
  45.     pEditGz = 0xFFFF,
  46.     Float: pMinX[MAX_GZ],
  47.     Float: pMinY[MAX_GZ],
  48.     Float: pMaxX[MAX_GZ],
  49.     Float: pMaxY[MAX_GZ],
  50.     pColor[MAX_GZ] = {0xFF0000AA, ...};
  51.  
  52. public OnPlayerConnect(playerid) {
  53.     if(pMaxPlayers) SendClientMessage(playerid, -1, "Info: Máximo 1 Player conectado!!"), Kick(playerid);
  54.     for(new i = (pCount - 1); i > -1; --i) GangZoneShowForPlayer(playerid, pGz[i], pColor[i]);
  55.     pMaxPlayers++;
  56.     return 1;
  57. }
  58.  
  59. public OnPlayerDisconnect(playerid, reason) {
  60.     pMaxPlayers--;
  61.     return 1;
  62. }
  63.  
  64. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  65.     switch(dialogid) {
  66.         case DialogID: {
  67.             if(response) {
  68.                 switch(listitem) {
  69.                     case 0: {
  70.                         if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  71.  
  72.                         GetPlayerPos(playerid, pX, pY, pZ);
  73.                         pGz[pCount] = GangZoneCreate(pX, pY, pX, pY);
  74.                         SendClientMessage(playerid, -1, "Info: Agora vá até a outra ponta da Gz, formando um Retângulo.");
  75.                     } case 1: {
  76.                         if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  77.  
  78.                         new Str[1200], i;
  79.                         for(; i != pCount; ++i) {
  80.                             strcat(Str, pGzName[i]);
  81.                             strcat(Str, "\n");
  82.                         }
  83.                         ShowPlayerDialog(playerid, (DialogID + 1), DIALOG_STYLE_LIST, "GzEditor » By Paulo", Str, "Ok", "Voltar");
  84.                     } case 2: {
  85.                         if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  86.  
  87.                         new Str[1200], i;
  88.                         for(; i != pCount; ++i) {
  89.                             strcat(Str, pGzName[i]);
  90.                             strcat(Str, "\n");
  91.                         }
  92.                         ShowPlayerDialog(playerid, (DialogID + 2), DIALOG_STYLE_LIST, "GzEditor » By Paulo", Str, "Ok", "Voltar");
  93.                     } case 3: {
  94.                         if(pEditGz == 0xFFFF) ShowPlayerDialog(playerid, (DialogID + 3), DIALOG_STYLE_INPUT, "GzEditor » By Paulo", "Digite o Nome da Gz.", "Ok", "Voltar");
  95.                         else {
  96.                             if(strlen(inputtext) > 23) return SendClientMessage(playerid, -1, "Erro: Máximo de Caracteres atingido.");
  97.  
  98.                             new Float: gX, Float: gY, Float: gZ;
  99.                             GetPlayerPos(playerid, gX, gY, gZ);
  100.                             pMinX[pEditGz] = (pX > gX ? gX : pX), pMinY[pEditGz] = (pY > gY ? gY : pY);
  101.                             pMaxX[pEditGz] = (pX < gX ? gX : pX), pMaxY[pEditGz] = (pY < gY ? gY : pY);
  102.                             pEditGz = 0xFFFF;
  103.  
  104.                             SendClientMessage(playerid, -1, "Info: Gz refeita com Sucesso!!");
  105.                         }
  106.                     } case 4: {
  107.                         if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  108.  
  109.                         new Str[1200], i;
  110.                         for(; i != pCount; ++i) {
  111.                             strcat(Str, pGzName[i]);
  112.                             strcat(Str, "\n");
  113.                         }
  114.                         ShowPlayerDialog(playerid, (DialogID + 5), DIALOG_STYLE_LIST, "GzEditor » By Paulo", Str, "Ok", "Voltar");
  115.                     } case 5: {
  116.                         if(!pCount) return SendClientMessage(playerid, -1, "Erro: Você não criou nenhuma Gz.");
  117.  
  118.                         new File: pFile = fopen("GzEditor_By.Paulo.pwn", io_write), i, pStr[128];
  119.                         if(pCount > 1) {
  120.                             format(pStr, 128, "new pGz[%i];\r\n\r\n", pCount);
  121.                             fwrite(pFile, pStr);
  122.                             fwrite(pFile, "main() {\r\n");
  123.                             fwrite(pFile, " print(\"|---------------------------|\");\r\n");
  124.                             fwrite(pFile, " print(\"| -- GzEditor By Paulo -- |\");\r\n");
  125.                             fwrite(pFile, " print(\"|---------------------------|\");\r\n");
  126.                             fwrite(pFile, "}\r\n\r\n");
  127.                             fwrite(pFile, "public OnGameModeInit() {\r\n");
  128.                             for(; i != pCount; ++i) {
  129.                                 format(pStr, 128, " pGz[%i] = GangZoneCreate(%f, %f, %f, %f); // %s\r\n", i, pMinX[i], pMinY[i], pMaxX[i], pMaxY[i], pGzName[i]);
  130.                                 fwrite(pFile, pStr);
  131.                             }
  132.                             fwrite(pFile, " return 1;\r\n}\r\n\r\n");
  133.                             fwrite(pFile, "public OnPlayerConnect(playerid) {\r\n");
  134.                             for(i = 0; i != pCount; ++i) {
  135.                                 format(pStr, 128, " GangZoneShowForPlayer(playerid, pGz[%i], %s); // %s\r\n", i, HexForStr(pColor[i]), pGzName[i]);
  136.                                 fwrite(pFile, pStr);
  137.                             }
  138.                             fwrite(pFile, " return 1;\r\n}\r\n\r\n");
  139.                             fclose(pFile);
  140.                         } else {
  141.                             fwrite(pFile, "new pGz;\r\n\r\n");
  142.                             fwrite(pFile, "main() {\r\n");
  143.                             fwrite(pFile, " print(\"|---------------------------|\");\r\n");
  144.                             fwrite(pFile, " print(\"| -- GzEditor By Paulo -- |\");\r\n");
  145.                             fwrite(pFile, " print(\"|---------------------------|\");\r\n");
  146.                             fwrite(pFile, "}\r\n\r\n");
  147.                             fwrite(pFile, "public OnGameModeInit() {\r\n");
  148.                             format(pStr, 128, " pGz = GangZoneCreate(%f, %f, %f, %f); // %s\r\n", pMinX[0], pMinY[0], pMaxX[0], pMaxY[0], pGzName[0]);
  149.                             fwrite(pFile, pStr);
  150.                             fwrite(pFile, " return 1;\r\n}\r\n\r\n");
  151.                             fwrite(pFile, "public OnPlayerConnect(playerid) {\r\n");
  152.                             format(pStr, 128, " GangZoneShowForPlayer(playerid, pGz, %s); // %s\r\n", HexForStr(pColor[0]), pGzName[0]);
  153.                             fwrite(pFile, pStr);
  154.                             fwrite(pFile, " return 1;\r\n}\r\n\r\n");
  155.                             fclose(pFile);
  156.                         }
  157.                         SendClientMessage(playerid, -1, "Info: Gz's exportadas com Sucesso!!");
  158.                     }
  159.                 }
  160.             }
  161.         } case (DialogID + 1): {
  162.             if(response) {
  163.                 pGzSave = listitem;
  164.                 ShowPlayerDialog(playerid, (DialogID + 4), DIALOG_STYLE_INPUT, "GzEditor » By Paulo", "Digite a Cor na forma \"0xFFFFFFFF\"", "Ok", "Voltar");
  165.             } else ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, "GzEditor » By Paulo", "Criar\nCor\nRefazer\nSalvar\nExcluir\nExportar", "Ok", "Sair");
  166.         } case (DialogID + 2): {
  167.             if(response) {
  168.                 if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  169.  
  170.                 GangZoneDestroy(pGz[listitem]);
  171.  
  172.                 GetPlayerPos(playerid, pX, pY, pZ);
  173.                 pGz[(pEditGz = listitem)] = GangZoneCreate(pX, pY, pX, pY);
  174.                 SendClientMessage(playerid, -1, "Info: Agora vá até a outra ponta da Gz, formando um Retângulo.");
  175.             } else ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, "GzEditor » By Paulo", "Criar\nCor\nRefazer\nSalvar\nExcluir\nExportar", "Ok", "Sair");
  176.         } case (DialogID + 3): {
  177.             if(response) {
  178.                 if(strlen(inputtext) > 23) return SendClientMessage(playerid, -1, "Erro: Máximo de Caracteres atingido.");
  179.  
  180.                 new Float: gX, Float: gY, Float: gZ;
  181.                 strcat(pGzName[pCount], inputtext);
  182.                 GetPlayerPos(playerid, gX, gY, gZ);
  183.                 pMinX[pCount] = (pX > gX ? gX : pX), pMinY[pCount] = (pY > gY ? gY : pY);
  184.                 pMaxX[pCount] = (pX < gX ? gX : pX), pMaxY[pCount] = (pY < gY ? gY : pY);
  185.                 pCount++;
  186.  
  187.                 SendClientMessage(playerid, -1, "Info: Gz salva com Sucesso!!");
  188.             } else ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, "GzEditor » By Paulo", "Criar\nCor\nRefazer\nSalvar\nExcluir\nExportar", "Ok", "Sair");
  189.         } case (DialogID + 4): {
  190.             if(response) {
  191.                 if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  192.                
  193.                 new Str[1200], i;
  194.                 for(; i != pCount; ++i) {
  195.                     strcat(Str, pGzName[i]);
  196.                     strcat(Str, "\n");
  197.                 }
  198.                 if(strfind(inputtext, "0x") == -1 || strlen(inputtext) != 10) return ShowPlayerDialog(playerid, (DialogID + 1), DIALOG_STYLE_INPUT, "GzEditor » By Paulo", Str, "Ok", "Voltar");
  199.  
  200.                 pColor[pGzSave] = StrForHex(inputtext);
  201.                 GangZoneHideForPlayer(playerid, pGz[pGzSave]);
  202.                 GangZoneShowForPlayer(playerid, pGz[pGzSave], pColor[pGzSave]);
  203.             } else ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, "GzEditor » By Paulo", "Criar\nCor\nRefazer\nSalvar\nExcluir\nExportar", "Ok", "Sair");
  204.         } case (DialogID + 5): {
  205.             if(response) {
  206.                 if(pGz[pCount] != 0xFFFF) return SendClientMessage(playerid, -1, "Erro: Salve essa Gz Primeiro.");
  207.                
  208.                 GangZoneHideForPlayer(playerid, pGz[listitem]);
  209.                 GangZoneDestroy(pGz[listitem]);
  210.                
  211.                 if(listitem != --pCount) {
  212.                     pGzName[listitem] = pGzName[pCount];
  213.                     pMinX[listitem] = pMinX[pCount];
  214.                     pMinY[listitem] = pMinY[pCount];
  215.                     pMaxX[listitem] = pMaxX[pCount];
  216.                     pMaxY[listitem] = pMaxY[pCount];
  217.                     pColor[listitem] = pColor[pCount];
  218.                     GangZoneHideForPlayer(playerid, pGz[pCount]);
  219.                     GangZoneDestroy(pGz[pCount]);
  220.                     pGzName[pCount] = pGzName[(pCount + 1)];
  221.                     pGz[pCount] = 0xFFFF;
  222.                     pMinX[pCount] = 0.0;
  223.                     pMinY[pCount] = 0.0;
  224.                     pMaxX[pCount] = 0.0;
  225.                     pMaxY[pCount] = 0.0;
  226.                     pColor[pCount] = 0xFF0000AA;
  227.                     pGz[listitem] = GangZoneCreate(pMinX[listitem], pMinY[listitem], pMaxX[listitem], pMaxY[listitem]);
  228.                     GangZoneShowForPlayer(playerid, pGz[listitem], pColor[listitem]);
  229.                 } else {
  230.                     pGzName[listitem] = pGzName[(listitem + 1)];
  231.                     pGz[listitem] = 0xFFFF;
  232.                     pMinX[listitem] = 0.0;
  233.                     pMinY[listitem] = 0.0;
  234.                     pMaxX[listitem] = 0.0;
  235.                     pMaxY[listitem] = 0.0;
  236.                     pColor[listitem] = 0xFF0000AA;
  237.                 }
  238.                 SendClientMessage(playerid, -1, "Info: Gz deletada com sucesso!!");
  239.             }
  240.         }
  241.     }
  242.     return 1;
  243. }
  244.  
  245. public OnPlayerCommandText(playerid, cmdtext[]) {
  246.     if(!strcmp(cmdtext, "/gz")) {
  247.         if(pCount == MAX_GZ) return SendClientMessage(playerid, -1, "Erro: Você já criou o Máximo de Gz's, Salve-as para criar mais.");
  248.         return ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, "GzEditor » By Paulo", "Criar\nCor\nRefazer\nSalvar\nExcluir\nExportar", "Ok", "Sair");
  249.     }
  250.     return 0;
  251. }
  252.  
  253. public OnPlayerUpdate(playerid) {
  254.     if(pGz[pCount] != 0xFFFF || pEditGz != 0xFFFF) {
  255.         new Float: gX, Float: gY, Float: gZ, i = (pEditGz == 0xFFFF ? pCount : pEditGz);
  256.         GangZoneHideForPlayer(playerid, pGz[i]);
  257.         GangZoneDestroy(pGz[i]);
  258.         GetPlayerPos(playerid, gX, gY, gZ);
  259.         pGz[i] = GangZoneCreate((pX > gX ? gX : pX), (pY > gY ? gY : pY), (pX < gX ? gX : pX), (pY < gY ? gY : pY));
  260.         GangZoneShowForPlayer(playerid, pGz[i], pColor[i]);
  261.     }
  262.     return 1;
  263. }
  264.  
  265. HexForStr(Hex) {
  266.     new Caracters[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }, Var[11] = "0x";
  267.     for (new i = 0; i < 8; ++i) Var[(i + 2)] = Caracters[(Hex >>> ((7 - i) << 2)) & 0x0F];
  268.     return Var;
  269. }
  270.  
  271. StrForHex(Str[]) {
  272.     new i, Hex;
  273.     if(Str[0] == '0' && (Str[1] == 'x' || Str[1] == 'X')) i = 2;
  274.  
  275.     for(; Str[i]; ++i) {
  276.         Hex <<= 4;
  277.         switch(Str[i]) {
  278.             case '0' .. '9': Hex |= (Str[i] - '0');
  279.             case 'A' .. 'F': Hex |= ((Str[i] - 'A') + 10);
  280.             case 'a' .. 'f': Hex |= ((Str[i] - 'a') + 10);
  281.             default: return 0;
  282.         }
  283.     }
  284.     return Hex;
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement