Guest User

Label Create

a guest
Jan 29th, 2014
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.04 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dof2>
  3. #include <zcmd>
  4.  
  5. #if !defined MAX_TEXT
  6.     #define MAX_TEXT ( 1024 )
  7. #endif
  8.  
  9. #if !defined MAX_STRING
  10.     #define MAX_STRING ( 1024 )
  11. #endif
  12.  
  13. #define FileLoad "3DTexts/%d.ini"
  14. #define cPadrao 0xE9433FFF
  15.  
  16. #define DIALOG_MAKE_LABEL 777
  17. #define DIALOG_MAKE_LABEL1 778
  18. #define DIALOG_MAKE_LABEL2 779
  19. #define DIALOG_MAKE_LABEL3 800
  20. #define DIALOG_MAKE_LABEL4 801
  21. #define DIALOG_EDIT_LABEL 802
  22. #define DIALOG_EDIT_LABELDESC 803
  23. #define DIALOG_EDIT_LABELDIST 804
  24. #define DIALOG_EDIT_LABELCOR 805
  25.  
  26. new dStr[500];
  27.  
  28. enum Params
  29. {
  30.     Float:X,
  31.     Float:Y,
  32.     Float:Z,
  33.     Float:DD,
  34.     Text[128],
  35.     VirtualW,
  36.     bool:Loaded
  37. };
  38.  
  39. new TextInfo[MAX_TEXT][Params];
  40.  
  41. new Text3D:label[MAX_TEXT];
  42.  
  43. new labelid[MAX_PLAYERS],
  44.     Float: nX[MAX_PLAYERS],
  45.     Float: nZ[MAX_PLAYERS],
  46.     Float: nY[MAX_PLAYERS],
  47.     nDD[MAX_PLAYERS],
  48.     nText[MAX_PLAYERS][128],
  49.     nColor[MAX_PLAYERS][128],
  50.     bool:Editando[MAX_PLAYERS];
  51.  
  52. public OnFilterScriptInit()
  53. {
  54.     LoadTexts();
  55.     return 1;
  56. }
  57.  
  58. public OnFilterScriptExit()
  59. {
  60.     UnLoadSaveTexts();
  61.     return 1;
  62. }
  63.  
  64. CMD:makelabel(playerid)
  65. {
  66.     if ( !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, cPadrao, "Você não tem permissão para isso.");
  67.     new Str[500];
  68.     GetPlayerPos(playerid, nX[playerid], nY[playerid], nZ[playerid]);
  69.     format ( Str, sizeof ( Str ), "{FFFFFF}Olá, bem vindo ao assiste de 3DLabel\n\nPos X: {E9433F}%f\n{FFFFFF}Pos Y: {E9433F}%f\n{FFFFFF}Pos Z: {E9433F}%f\n\n{FFFFFF}Deseja criar uma label neste local ?", nX, nY, nZ);
  70.     ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL, DIALOG_STYLE_MSGBOX, "{FFFFFF}Label Create", Str, "Sim", "Não");
  71.     return 1;
  72. }
  73.  
  74. CMD:editlabel(playerid)
  75. {
  76.     for ( new t = 0; t < MAX_TEXT; t++)
  77.     {
  78.         if ( IsPlayerInRangeOfPoint(playerid, 1.0, TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z]))
  79.         {
  80.             ShowPlayerDialog(playerid, DIALOG_EDIT_LABEL, DIALOG_STYLE_LIST, "{FFFFFF}Edit Label", "{FFFFFF}Deletar\nTexto\nDistância\nCor\nPosição", "Selecionar", "Sair");
  81.             labelid[playerid] = t;
  82.             break;
  83.         }
  84.         else
  85.         {
  86.             SendClientMessage(playerid, cPadrao, "Nenhuma label criada neste local.");
  87.             break;
  88.         }
  89.     }
  90.     return 1;
  91. }
  92. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  93. {
  94.     if ( dialogid == DIALOG_MAKE_LABEL)
  95.     {
  96.         if ( response )
  97.         {
  98.             ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL1, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", "{FFFFFF}Vamos em frente!\n\nPor favor, nos informe o texto a ser exibido:", "Proximo", "Sair");
  99.         }
  100.         else
  101.         {
  102.             nX[playerid] = 0;
  103.             nZ[playerid] = 0;
  104.             nY[playerid] = 0;
  105.             nDD[playerid] = 0;
  106.             nColor[playerid] = "";
  107.             nText[playerid] = "";
  108.         }
  109.     }
  110.     if ( dialogid == DIALOG_MAKE_LABEL1)
  111.     {
  112.         if ( response )
  113.         {
  114.             new deStr[MAX_STRING];
  115.             format ( nText[playerid], 128, "%s" ,inputtext);
  116.             format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s{FFFFFF}\n\n Agora nos informe uma distancia para a label ser exibida:", nText[playerid]);
  117.             ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL2, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", deStr, "Proximo", "Sair");
  118.         }
  119.         else
  120.         {
  121.             nX[playerid] = 0;
  122.             nZ[playerid] = 0;
  123.             nY[playerid] = 0;
  124.             nDD[playerid] = 0;
  125.             nColor[playerid] = "";
  126.             nText[playerid] = "";
  127.         }
  128.     }
  129.     if ( dialogid == DIALOG_MAKE_LABEL2)
  130.     {
  131.         if ( response )
  132.         {
  133.             new deStr[MAX_STRING];
  134.             nDD[playerid] = strval(inputtext);
  135.             format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s\n{FFFFFF}Distância: {E9433F}%d{E9433F}\n\n Insira uma cor:", nText[playerid], nDD[playerid]);
  136.             ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL3, DIALOG_STYLE_INPUT, "{FFFFFF}Label Create", deStr, "Proximo", "Sair");
  137.         }
  138.         else
  139.         {
  140.             nX[playerid] = 0;
  141.             nZ[playerid] = 0;
  142.             nY[playerid] = 0;
  143.             nDD[playerid] = 0;
  144.             nColor[playerid] = "";
  145.             nText[playerid] = "";
  146.         }
  147.     }
  148.     if ( dialogid == DIALOG_MAKE_LABEL3)
  149.     {
  150.         if ( response )
  151.         {
  152.             new deStr[MAX_STRING];
  153.             format ( nColor[playerid], 128, "%s", inputtext);
  154.             format ( deStr, MAX_STRING, "{FFFFFF}Precesso Atual:\n\nTexto: {E9433F}%s\n{FFFFFF}Distância: {E9433F}%d{FFFFFF}\nCor: {E9433F}%s{FFFFFF}\n\n Deseja criar ?", nText[playerid], nDD[playerid], nColor[playerid]);
  155.             ShowPlayerDialog(playerid, DIALOG_MAKE_LABEL4, DIALOG_STYLE_MSGBOX, "{FFFFFF}Label Create", deStr, "Criar", "Sair");
  156.         }
  157.         else
  158.         {
  159.             nX[playerid] = 0;
  160.             nZ[playerid] = 0;
  161.             nY[playerid] = 0;
  162.             nDD[playerid] = 0;
  163.             nColor[playerid] = "";
  164.             nText[playerid] = "";
  165.         }
  166.     }
  167.     if ( dialogid == DIALOG_MAKE_LABEL4)
  168.     {
  169.         if ( response )
  170.         {
  171.             Make3DText(nText[playerid], nColor[playerid], nX[playerid], nY[playerid], nZ[playerid], nDD[playerid], 0);
  172.         }
  173.         else
  174.         {
  175.             nX[playerid] = 0;
  176.             nZ[playerid] = 0;
  177.             nY[playerid] = 0;
  178.             nDD[playerid] = 0;
  179.             nColor[playerid] = "";
  180.             nText[playerid] = "";
  181.         }
  182.     }
  183.     if ( dialogid == DIALOG_EDIT_LABEL)
  184.     {
  185.         if ( response )
  186.         {
  187.             if ( listitem == 0 )
  188.             {
  189.                 new deStr[128], lid = labelid[playerid];
  190.                 format ( deStr, 128, FileLoad, lid);
  191.                 TextInfo[lid][Loaded] = false;
  192.                 DOF2::RemoveFile(deStr);
  193.                 Delete3DTextLabel(label[lid]);
  194.                 UnLoadSaveTexts();
  195.                 LoadTexts();
  196.             }
  197.             if ( listitem == 1 )
  198.             {
  199.                 new deStr[MAX_STRING], lid = labelid[playerid];
  200.                 format ( deStr, MAX_STRING, "Descrição atual: {E9433F}%s{FFFFFF}\n\nInsira uma nova descrição:", TextInfo[lid][Text]);
  201.                 ShowPlayerDialog(playerid, DIALOG_EDIT_LABELDESC, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  202.             }
  203.             if ( listitem == 2 )
  204.             {
  205.                 new xStr[128], deStr[MAX_STRING], lid = labelid[playerid];
  206.                 format  (xStr, 128, FileLoad, lid);
  207.                 format ( deStr, MAX_STRING, "Distância atual: %s\n\nInsira uma nova distãncia:", DOF2::GetString(xStr, "TEXT3D_DrawDistance"));
  208.                 ShowPlayerDialog(playerid, DIALOG_EDIT_LABELDIST, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  209.             }
  210.             if ( listitem == 3 )
  211.             {
  212.                 new xStr[128], deStr[MAX_STRING], lid = labelid[playerid];
  213.                 format  (xStr, 128, FileLoad, lid);
  214.                 format ( deStr, MAX_STRING, "Cor atual: %s\n\nInsira uma nova cor:", DOF2::GetString(xStr, "TEXT3D_COLOR"));
  215.                 ShowPlayerDialog(playerid, DIALOG_EDIT_LABELCOR, DIALOG_STYLE_INPUT, "Edit Label", deStr, "Editar", "Sair");
  216.             }
  217.             if ( listitem == 4 )
  218.             {
  219.                 SendClientMessage(playerid, cPadrao, "Dirija-se ao novo local e pressione ' y '");
  220.                 Editando[playerid] = true;
  221.             }
  222.         }
  223.         else
  224.         {
  225.             labelid[playerid] = INVALID_3DTEXT_ID;
  226.             nX[playerid] = 0;
  227.             nZ[playerid] = 0;
  228.             nY[playerid] = 0;
  229.             nDD[playerid] = 0;
  230.             nColor[playerid] = "";
  231.             nText[playerid] = "";
  232.         }
  233.     }
  234.     if ( dialogid == DIALOG_EDIT_LABELDESC)
  235.     {
  236.         if ( response )
  237.         {
  238.             new lid = labelid[playerid];
  239.             format ( TextInfo[lid][Text], 128, "%s", inputtext);
  240.             UnLoadSaveTexts();
  241.             LoadTexts();
  242.         }
  243.         else
  244.         {
  245.             labelid[playerid] = INVALID_3DTEXT_ID;
  246.             nX[playerid] = 0;
  247.             nZ[playerid] = 0;
  248.             nY[playerid] = 0;
  249.             nDD[playerid] = 0;
  250.             nColor[playerid] = "";
  251.             nText[playerid] = "";
  252.         }
  253.     }
  254.     if ( dialogid == DIALOG_EDIT_LABELDIST)
  255.     {
  256.         if ( response )
  257.         {
  258.             new xStr[128], lid = labelid[playerid];
  259.             format  (xStr, 128, FileLoad, lid);
  260.             TextInfo[lid][DD] = strval(inputtext);
  261.             UnLoadSaveTexts();
  262.             LoadTexts();
  263.         }
  264.         else
  265.         {
  266.             labelid[playerid] = INVALID_3DTEXT_ID;
  267.             nX[playerid] = 0;
  268.             nZ[playerid] = 0;
  269.             nY[playerid] = 0;
  270.             nDD[playerid] = 0;
  271.             nColor[playerid] = "";
  272.             nText[playerid] = "";
  273.         }
  274.     }
  275.     if ( dialogid == DIALOG_EDIT_LABELCOR)
  276.     {
  277.         if ( response )
  278.         {
  279.             new xStr[128], lid = labelid[playerid];
  280.             format  (xStr, 128, FileLoad, lid);
  281.             DOF2::SetString(xStr, "TEXT3D_COLOR", inputtext);
  282.             UnLoadSaveTexts();
  283.             LoadTexts();
  284.         }
  285.         else
  286.         {
  287.             labelid[playerid] = INVALID_3DTEXT_ID;
  288.             nX[playerid] = 0;
  289.             nZ[playerid] = 0;
  290.             nY[playerid] = 0;
  291.             nDD[playerid] = 0;
  292.             nColor[playerid] = "";
  293.             nText[playerid] = "";
  294.         }
  295.     }
  296.     return 1;
  297. }
  298.  
  299. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  300. {
  301.     if ( newkeys == 65536)
  302.     {
  303.         if ( Editando[playerid] == true)
  304.         {
  305.             new textt = labelid[playerid];
  306.             GetPlayerPos(playerid, nX[playerid], nY[playerid], nZ[playerid]);
  307.             TextInfo[textt][X] = nX[playerid];
  308.             TextInfo[textt][Y] = nY[playerid];
  309.             TextInfo[textt][Z] = nZ[playerid];
  310.             UnLoadSaveTexts();
  311.             LoadTexts();
  312.             return 1;
  313.         }
  314.     }
  315.     return 1;
  316. }
  317.  
  318. LoadTexts()
  319. {
  320.     for ( new t = 0; t < MAX_TEXT; t++)
  321.     {
  322.         format ( dStr, sizeof ( dStr ), FileLoad, t);
  323.         if ( DOF2::FileExists(dStr))
  324.         {
  325.             TextInfo[t][Loaded] = DOF2::GetBool(dStr, "TEXT3D_Created");
  326.             TextInfo[t][X] = DOF2::GetFloat(dStr, "TEXT3D_PosX");
  327.             TextInfo[t][Y] = DOF2::GetFloat(dStr, "TEXT3D_PosY");
  328.             TextInfo[t][Z] = DOF2::GetFloat(dStr, "TEXT3D_PosZ");
  329.             TextInfo[t][DD] = DOF2::GetFloat(dStr, "TEXT3D_DrawDistance");
  330.             TextInfo[t][VirtualW] = DOF2::GetInt(dStr, "TEXT3D_VirtualW");
  331.             format ( TextInfo[t][Text], 128, "%s", DOF2::GetString(dStr, "TEXT3D_STRING"));
  332.             label[t] = Create3DTextLabel(TextInfo[t][Text], DOF2::GetHex(dStr, "TEXT3D_COLOR"), TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z], TextInfo[t][DD], TextInfo[t][VirtualW], 0);
  333.         }
  334.     }
  335. }
  336.  
  337. UnLoadSaveTexts()
  338. {
  339.     for ( new t = 0; t < MAX_TEXT; t++)
  340.     {
  341.         format ( dStr, sizeof ( dStr ), FileLoad, t);
  342.         if ( !DOF2::FileExists(dStr) && TextInfo[t][Loaded] == true) DOF2::CreateFile(dStr);
  343.         if ( TextInfo[t][Loaded] == true )
  344.         {
  345.             DOF2::SetBool(dStr, "TEXT3D_Created", TextInfo[t][Loaded]);
  346.             DOF2::SetFloat(dStr, "TEXT3D_PosX", TextInfo[t][X]);
  347.             DOF2::SetFloat(dStr, "TEXT3D_PosY", TextInfo[t][Y]);
  348.             DOF2::SetFloat(dStr, "TEXT3D_PosZ", TextInfo[t][Z]);
  349.             DOF2::SetFloat(dStr, "TEXT3D_DrawDistance", TextInfo[t][DD]);
  350.             DOF2::SetInt(dStr, "TEXT3D_VirtualW", TextInfo[t][VirtualW]);
  351.             DOF2::SetString(dStr, "TEXT3D_STRING", TextInfo[t][Text]);
  352.             DOF2::SaveFile();
  353.             TextInfo[t][Loaded] =false;
  354.             Delete3DTextLabel(label[t]);
  355.         }
  356.     }
  357.     return 1;
  358. }
  359.  
  360. Make3DText(text[], dcolor[], Float: dX, Float: dY, Float: dZ, Float: Distance, VW)
  361. {
  362.     for ( new t = 0; t < MAX_TEXT; t++)
  363.     {
  364.         if ( TextInfo[t][Loaded] == false)
  365.         {
  366.             format ( dStr, sizeof ( dStr ), FileLoad, t);
  367.             DOF2::CreateFile(dStr);
  368.             if ( !DOF2::FileExists(dStr)) return printf ("O 3DText %d não foi criado", t);
  369.             TextInfo[t][Loaded] = true;
  370.             TextInfo[t][X] = dX;
  371.             TextInfo[t][Y] = dY;
  372.             TextInfo[t][Z] = dZ;
  373.             TextInfo[t][DD] = Distance;
  374.             TextInfo[t][VirtualW] = VW;
  375.             format ( TextInfo[t][Text], 128, "%s", text);
  376.             DOF2::SetString(dStr, "TEXT3D_COLOR", dcolor);
  377.             label[t] = Create3DTextLabel(TextInfo[t][Text], DOF2::GetHex(dStr, "TEXT3D_COLOR"), TextInfo[t][X], TextInfo[t][Y], TextInfo[t][Z], TextInfo[t][DD], TextInfo[t][VirtualW], 0);
  378.             UnLoadSaveTexts();
  379.             LoadTexts();
  380.             break;
  381.         }
  382.     }
  383.     return 1;
  384. }
Advertisement
Add Comment
Please, Sign In to add comment