Juuh

xPPontos v1.beta.2

Jul 24th, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.48 KB | None | 0 0
  1. #include <  a_samp  >
  2. #include <  ZCMD    >
  3. #include <  DOF2    >
  4.  
  5. #define MAX_PONTOS      100
  6. #define iMAX_PONTOS     100
  7.  
  8. enum PDATA
  9. {
  10.     TAG[128],
  11.     PID,
  12.     Text3D:PTEXT3D,
  13.     Float:PPOS[3],
  14. }
  15.  
  16. enum iDATA
  17. {
  18.     TAG,
  19.     PID,
  20.     IV[2],
  21.     Text3D:PTEXT3D,
  22.     Float:PPOS[3],
  23. }
  24.  
  25. new iPonto[iMAX_PONTOS][iDATA];
  26. new PPonto[MAX_PONTOS][PDATA];
  27. new PPontoPermitir = 1;
  28.  
  29. public OnFilterScriptInit()
  30. {
  31.     CarregarPPontos();
  32.     return 1;
  33. }
  34.  
  35. public OnFilterScriptExit()
  36. {
  37.     DOF2_Exit();
  38.     return 1;
  39. }
  40.  
  41. CMD:criarponto(playerid, params [])
  42. {
  43.     new opcao, tag[100];
  44.     new Local[100];
  45.     new Texto[100];
  46.     new e = MAX_PONTOS+1;
  47.     new i = iMAX_PONTOS+1;
  48.     if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  49.     if(sscanf(params, "ds", opcao, tag)) return SendClientMessage(playerid, 0x33AA3300, "<opções = entrada(1), saida(2)><tag = nome>");
  50.     if(opcao == 1)
  51.     {
  52.         if(PPontoPermitir == 1)
  53.         {
  54.             for(new a = 0; a < MAX_PONTOS; a++)
  55.             {
  56.                 if(PPonto[a][PPOS][0] == 0.0)
  57.                 {
  58.                     e = a;
  59.                     break;
  60.                 }
  61.             }
  62.             PPontoPermitir = 2;
  63.             if(e > MAX_PONTOS) return SendClientMessage(playerid, 0x33AA3300, "Você não pode criar mais.");
  64.             printf("[Porta][1][id = %d]", e);
  65.             SendClientMessage(playerid, 0x33AA3300, "[1][OK]");
  66.             GetPlayerPos(playerid, PPonto[e][PPOS][0], PPonto[e][PPOS][1], PPonto[e][PPOS][2]);
  67.             format(Local, sizeof(Local), "PPontos/Entradas/%d.txt", e);
  68.             DOF2_CreateFile(Local);
  69.             DOF2_SetString(Local, "TAG", tag);
  70.             DOF2_SetFloat(Local, "POS0", PPonto[e][PPOS][0]);
  71.             DOF2_SetFloat(Local, "POS1", PPonto[e][PPOS][1]);
  72.             DOF2_SetFloat(Local, "POS2", PPonto[e][PPOS][2]);
  73.             DOF2_SaveFile();
  74.             format(Texto, sizeof(Texto), "%s\n[%d]\n<saida>",tag, e);
  75.             PPonto[e][PID] =  CreatePickup(19198, 1, PPonto[e][PPOS][0], PPonto[e][PPOS][1], PPonto[e][PPOS][2]+0.2, 0);
  76.             PPonto[e][PTEXT3D] = Create3DTextLabel(Texto, -1, PPonto[e][PPOS][0], PPonto[e][PPOS][1], PPonto[e][PPOS][2]-0.2, 5.0, 0);
  77.         }
  78.         else
  79.         {
  80.             SendClientMessage(playerid, 0x33AA3300, "Você ja definio o ponto [1] defina o proximo(2).");
  81.         }
  82.     }
  83.     if(opcao == 2)
  84.     {
  85.         if(PPontoPermitir == 2)
  86.         {
  87.             PPontoPermitir = 1;
  88.             for(new a = 0; a < iMAX_PONTOS; a++)
  89.             {
  90.                 if(iPonto[a][PPOS][0] == 0.0)
  91.                 {
  92.                     i = a;
  93.                     break;
  94.                 }
  95.             }
  96.             if(i > MAX_PONTOS) return SendClientMessage(playerid, 0x33AA3300, "Você não pode criar mais.");
  97.             printf("[Porta][2][id = %d]",i);
  98.             SendClientMessage(playerid, 0x33AA3300, "[2][OK]");
  99.             GetPlayerPos(playerid, iPonto[i][PPOS][0], iPonto[i][PPOS][1], iPonto[i][PPOS][2]);
  100.             iPonto[i][IV][0] = GetPlayerInterior(playerid);
  101.             iPonto[i][IV][1] = i;
  102.             format(Local, sizeof(Local), "PPontos/Saidas/%d.txt", i);
  103.             DOF2_CreateFile(Local);
  104.             DOF2_SetString(Local, "TAG", tag);
  105.             DOF2_SetFloat(Local, "POS0", iPonto[i][PPOS][0]);
  106.             DOF2_SetFloat(Local, "POS1", iPonto[i][PPOS][1]);
  107.             DOF2_SetFloat(Local, "POS2", iPonto[i][PPOS][2]);
  108.             DOF2_SetInt(Local, "INTERIOR", iPonto[i][IV][0]);
  109.             DOF2_SetInt(Local, "MUNDO", iPonto[i][IV][1]);
  110.             DOF2_SaveFile();
  111.             format(Texto, sizeof(Texto), "%s\n[%d]\n<saida>", tag, i);
  112.             iPonto[i][PID] =  CreatePickup(19198, 1, iPonto[i][PPOS][0], iPonto[i][PPOS][1], iPonto[i][PPOS][2]+0.2, iPonto[i][IV][1]);
  113.             iPonto[i][PTEXT3D] = Create3DTextLabel(Texto, -1, iPonto[i][PPOS][0], iPonto[i][PPOS][1], iPonto[i][PPOS][2]-0.2, 5.0, iPonto[i][IV][1]);
  114.         }
  115.         else
  116.         {
  117.             SendClientMessage(playerid, 0x33AA3300, "Você aida não definio o ponto [1], defina-o.");
  118.         }
  119.     }
  120.     return 1;
  121. }
  122.  
  123. CMD:apagarponto(playerid)
  124. {
  125.     if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  126.     new f = MAX_PONTOS+1;
  127.     new i = iMAX_PONTOS+1;
  128.     for(new a = 0; a < MAX_PONTOS; a++)
  129.     {
  130.         if(IsPlayerInRangeOfPoint(playerid, 1.0, PPonto[a][PPOS][0], PPonto[a][PPOS][1], PPonto[a][PPOS][2]))
  131.         {
  132.             f = a;
  133.             break;
  134.         }
  135.     }
  136.     for(new a = 0; a < iMAX_PONTOS; a++)
  137.     {
  138.         if(IsPlayerInRangeOfPoint(playerid, 1.0, PPonto[a][PPOS][0], PPonto[a][PPOS][1], PPonto[a][PPOS][2]))
  139.         {
  140.             i = a;
  141.             break;
  142.         }
  143.     }
  144.     if(f > MAX_PONTOS) return SendClientMessage(playerid, 0x33AA3300, "Fique acima da porta principal para apagar.");
  145.     DestroyPickup(PPonto[f][PID]);
  146.     Delete3DTextLabel(PPonto[f][PTEXT3D]);
  147.     DestroyPickup(iPonto[i][PID]);
  148.     Delete3DTextLabel(iPonto[i][PTEXT3D]);
  149.     PPonto[f][PPOS][0] = 0.0;
  150.     PPonto[f][PPOS][1] = 0.0;
  151.     PPonto[f][PPOS][2] = 0.0;
  152.     iPonto[i][PPOS][0] = 0.0;
  153.     iPonto[i][PPOS][1] = 0.0;
  154.     iPonto[i][PPOS][2] = 0.0;
  155.     iPonto[i][IV][0] = 0;
  156.     iPonto[i][IV][1] = 0;
  157.     new Local[100];
  158.     format(Local, sizeof(Local), "PPontos/Entradas/%d.txt", f);
  159.     DOF2_RemoveFile(Local);
  160.     format(Local, sizeof(Local), "PPontos/Saidas/%d.txt", i);
  161.     DOF2_RemoveFile(Local);
  162.     f = -1;
  163.     return 1;
  164. }
  165.  
  166. CMD:entrar(playerid)
  167. {
  168.     new f = MAX_PONTOS+1;
  169.     for(new a = 0; a < MAX_PONTOS; a++)
  170.     {
  171.         if(IsPlayerInRangeOfPoint(playerid, 1.0, PPonto[a][PPOS][0], PPonto[a][PPOS][1], PPonto[a][PPOS][2]))
  172.         {
  173.             f = a;
  174.             break;
  175.         }
  176.     }
  177.     if(f > MAX_PONTOS) return 1;
  178.     SetPlayerInterior(playerid, iPonto[f][IV][0]);
  179.     SetPlayerVirtualWorld(playerid, iPonto[f][IV][1]);
  180.     SetPlayerPos(playerid, iPonto[f][PPOS][0], iPonto[f][PPOS][1], iPonto[f][PPOS][2]);
  181.     return 1;
  182. }
  183.  
  184.  
  185. CMD:sair(playerid)
  186. {
  187.     new i = iMAX_PONTOS+1;
  188.     for(new a = 0; a < iMAX_PONTOS; a++)
  189.     {
  190.         if(IsPlayerInRangeOfPoint(playerid, 1.0, iPonto[a][PPOS][0], iPonto[a][PPOS][1], iPonto[a][PPOS][2]))
  191.         {
  192.             i = a;
  193.             break;
  194.         }
  195.     }
  196.     if(i > MAX_PONTOS) return 1;
  197.     if(GetPlayerVirtualWorld(playerid) == i)
  198.     {
  199.         SetPlayerPos(playerid, PPonto[i][PPOS][0], PPonto[i][PPOS][1], PPonto[i][PPOS][2]);
  200.         SetPlayerInterior(playerid, 0);
  201.         SetPlayerVirtualWorld(playerid, 0);
  202.     }
  203.     return 1;
  204. }
  205.  
  206. stock CarregarPPontos()
  207. {
  208.  
  209.     new Local[100];
  210.     new Texto[100];
  211.     for(new pontoid; pontoid < MAX_PONTOS; pontoid++)
  212.     {
  213.         format(Local, sizeof(Local), "PPontos/Entradas/%d.txt", pontoid);
  214.         if(DOF2_FileExists(Local))
  215.         {
  216.             PPonto[pontoid][PPOS][0] = DOF2_GetFloat(Local, "POS0");
  217.             PPonto[pontoid][PPOS][1] = DOF2_GetFloat(Local, "POS1");
  218.             PPonto[pontoid][PPOS][2] = DOF2_GetFloat(Local, "POS2");
  219.             format(PPonto[pontoid][TAG], 128, DOF2_GetString(Local, "TAG"));
  220.             format(Texto, sizeof(Texto), "%s\n[%d]\n<entrada>", PPonto[pontoid][TAG], pontoid);
  221.             PPonto[pontoid][PID] =  CreatePickup(19198, 1, PPonto[pontoid][PPOS][0], PPonto[pontoid][PPOS][1], PPonto[pontoid][PPOS][2]+0.2, 0);
  222.             PPonto[pontoid][PTEXT3D] = Create3DTextLabel(Texto, -1, PPonto[pontoid][PPOS][0], PPonto[pontoid][PPOS][1], PPonto[pontoid][PPOS][2]-0.2, 5.0, 0);
  223.             printf("[ENTRADA] %s [%d]", PPonto[pontoid][TAG], pontoid);
  224.         }
  225.     }
  226.     for(new pontoid; pontoid < iMAX_PONTOS; pontoid++)
  227.     {
  228.         format(Local, sizeof(Local), "PPontos/Saidas/%d.txt", pontoid);
  229.         if(DOF2_FileExists(Local))
  230.         {
  231.             iPonto[pontoid][PPOS][0] = DOF2_GetFloat(Local, "POS0");
  232.             iPonto[pontoid][PPOS][1] = DOF2_GetFloat(Local, "POS1");
  233.             iPonto[pontoid][PPOS][2] = DOF2_GetFloat(Local, "POS2");
  234.             iPonto[pontoid][IV][0] = DOF2_GetInt(Local, "INTERIOR");
  235.             iPonto[pontoid][IV][1] = DOF2_GetInt(Local, "MUNDO");
  236.             format(iPonto[pontoid][TAG], 128, DOF2_GetString(Local, "TAG"));
  237.             format(Texto, sizeof(Texto), "%s\n[%d]\n<saida>", iPonto[pontoid][TAG], pontoid);
  238.             iPonto[pontoid][PID] =  CreatePickup(19198, 1, iPonto[pontoid][PPOS][0], iPonto[pontoid][PPOS][1], iPonto[pontoid][PPOS][2]+0.2, iPonto[pontoid][IV][1]);
  239.             iPonto[pontoid][PTEXT3D] = Create3DTextLabel(Texto, -1, iPonto[pontoid][PPOS][0], iPonto[pontoid][PPOS][1], iPonto[pontoid][PPOS][2]-0.2, 5.0, iPonto[pontoid][IV][1]);
  240.             printf("[SAIDA] %s [%d]", iPonto[pontoid][TAG], pontoid);
  241.         }
  242.     }
  243. }
  244.  
  245. CMD:teste(playerid)
  246. {
  247.     SetPlayerPos(playerid, 770.8033, -0.7033, 1000.7267);
  248.     SetPlayerInterior(playerid, 5);
  249.     return 1;
  250. }
  251.  
  252. stock sscanf(string[], format[], {Float,_}:...)
  253. {
  254.     #if defined isnull
  255.         if (isnull(string))
  256.     #else
  257.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  258.     #endif
  259.         {
  260.             return format[0];
  261.         }
  262.     #pragma tabsize 4
  263.     new
  264.         formatPos = 0,
  265.         stringPos = 0,
  266.         paramPos = 2,
  267.         paramCount = numargs(),
  268.         delim = ' ';
  269.     while (string[stringPos] && string[stringPos] <= ' ')
  270.     {
  271.         stringPos++;
  272.     }
  273.     while (paramPos < paramCount && string[stringPos])
  274.     {
  275.         switch (format[formatPos++])
  276.         {
  277.             case '\0':
  278.             {
  279.                 return 0;
  280.             }
  281.             case 'i', 'd':
  282.             {
  283.                 new
  284.                     neg = 1,
  285.                     num = 0,
  286.                     ch = string[stringPos];
  287.                 if (ch == '-')
  288.                 {
  289.                     neg = -1;
  290.                     ch = string[++stringPos];
  291.                 }
  292.                 do
  293.                 {
  294.                     stringPos++;
  295.                     if ('0' <= ch <= '9')
  296.                     {
  297.                         num = (num * 10) + (ch - '0');
  298.                     }
  299.                     else
  300.                     {
  301.                         return -1;
  302.                     }
  303.                 }
  304.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  305.                 setarg(paramPos, 0, num * neg);
  306.             }
  307.             case 'h', 'x':
  308.             {
  309.                 new
  310.                     num = 0,
  311.                     ch = string[stringPos];
  312.                 do
  313.                 {
  314.                     stringPos++;
  315.                     switch (ch)
  316.                     {
  317.                         case 'x', 'X':
  318.                         {
  319.                             num = 0;
  320.                             continue;
  321.                         }
  322.                         case '0' .. '9':
  323.                         {
  324.                             num = (num << 4) | (ch - '0');
  325.                         }
  326.                         case 'a' .. 'f':
  327.                         {
  328.                             num = (num << 4) | (ch - ('a' - 10));
  329.                         }
  330.                         case 'A' .. 'F':
  331.                         {
  332.                             num = (num << 4) | (ch - ('A' - 10));
  333.                         }
  334.                         default:
  335.                         {
  336.                             return -1;
  337.                         }
  338.                     }
  339.                 }
  340.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  341.                 setarg(paramPos, 0, num);
  342.             }
  343.             case 'c':
  344.             {
  345.                 setarg(paramPos, 0, string[stringPos++]);
  346.             }
  347.             case 'f':
  348.             {
  349.  
  350.                 new changestr[16], changepos = 0, strpos = stringPos;
  351.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  352.                 {
  353.                     changestr[changepos++] = string[strpos++];
  354.                     }
  355.                 changestr[changepos] = '\0';
  356.                 setarg(paramPos,0,_:floatstr(changestr));
  357.             }
  358.             case 'p':
  359.             {
  360.                 delim = format[formatPos++];
  361.                 continue;
  362.             }
  363.             case '\'':
  364.             {
  365.                 new
  366.                     end = formatPos - 1,
  367.                     ch;
  368.                 while ((ch = format[++end]) && ch != '\'') {}
  369.                 if (!ch)
  370.                 {
  371.                     return -1;
  372.                 }
  373.                 format[end] = '\0';
  374.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  375.                 {
  376.                     if (format[end + 1])
  377.                     {
  378.                         return -1;
  379.                     }
  380.                     return 0;
  381.                 }
  382.                 format[end] = '\'';
  383.                 stringPos = ch + (end - formatPos);
  384.                 formatPos = end + 1;
  385.             }
  386.             case 'u':
  387.             {
  388.                 new
  389.                     end = stringPos - 1,
  390.                     id = 0,
  391.                     bool:num = true,
  392.                     ch;
  393.                 while ((ch = string[++end]) && ch != delim)
  394.                 {
  395.                     if (num)
  396.                     {
  397.                         if ('0' <= ch <= '9')
  398.                         {
  399.                             id = (id * 10) + (ch - '0');
  400.                         }
  401.                         else
  402.                         {
  403.                             num = false;
  404.                         }
  405.                     }
  406.                 }
  407.                 if (num && IsPlayerConnected(id))
  408.                 {
  409.                     setarg(paramPos, 0, id);
  410.                 }
  411.                 else
  412.                 {
  413.                     #if !defined foreach
  414.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  415.                         #define __SSCANF_FOREACH__
  416.                     #endif
  417.                     string[end] = '\0';
  418.                     num = false;
  419.                     new
  420.                         name[MAX_PLAYER_NAME];
  421.                     id = end - stringPos;
  422.                     foreach (Player, playerid)
  423.                     {
  424.                         GetPlayerName(playerid, name, sizeof (name));
  425.                         if (!strcmp(name, string[stringPos], true, id))
  426.                         {
  427.                             setarg(paramPos, 0, playerid);
  428.                             num = true;
  429.                             break;
  430.                         }
  431.                     }
  432.                     if (!num)
  433.                     {
  434.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  435.                     }
  436.                     string[end] = ch;
  437.                     #if defined __SSCANF_FOREACH__
  438.                         #undef foreach
  439.                         #undef __SSCANF_FOREACH__
  440.                     #endif
  441.                 }
  442.                 stringPos = end;
  443.             }
  444.             case 's', 'z':
  445.             {
  446.                 new
  447.                     i = 0,
  448.                     ch;
  449.                 if (format[formatPos])
  450.                 {
  451.                     while ((ch = string[stringPos++]) && ch != delim)
  452.                     {
  453.                         setarg(paramPos, i++, ch);
  454.                     }
  455.                     if (!i)
  456.                     {
  457.                         return -1;
  458.                     }
  459.                 }
  460.                 else
  461.                 {
  462.                     while ((ch = string[stringPos++]))
  463.                     {
  464.                         setarg(paramPos, i++, ch);
  465.                     }
  466.                 }
  467.                 stringPos--;
  468.                 setarg(paramPos, i, '\0');
  469.             }
  470.             default:
  471.             {
  472.                 continue;
  473.             }
  474.         }
  475.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  476.         {
  477.             stringPos++;
  478.         }
  479.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  480.         {
  481.             stringPos++;
  482.         }
  483.         paramPos++;
  484.     }
  485.     do
  486.     {
  487.         if ((delim = format[formatPos++]) > ' ')
  488.         {
  489.             if (delim == '\'')
  490.             {
  491.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  492.             }
  493.             else if (delim != 'z')
  494.             {
  495.                 return delim;
  496.             }
  497.         }
  498.     }
  499.     while (delim > ' ');
  500.     return 0;
  501. }
Advertisement
Add Comment
Please, Sign In to add comment