MiqueiasBarros

Sistema de Propriedades da Sandra

Aug 16th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 23.96 KB | None | 0 0
  1. /*===================================================================================================*\
  2. ||===================================================================================================||
  3. ||                ________    ________    ___    _    ______     ______     ________                 ||
  4. ||          \    |   _____|  |  ____  |  |   \  | |  |   _  \   |  _   \   |  ____  |    /           ||
  5. ||  ======== \   |  |_____   | |____| |  | |\ \ | |  |  | |  |  | |_|  /   | |____| |   / ========   ||
  6. ||            |  | _____  |  |  ____  |  | | \ \| |  |  | |  |  |  _  \    |  ____  |  |             ||
  7. ||  ======== /    ______| |  | |    | |  | |  \ \ |  |  |_|  |  | |  \ \   | |    | |   \ ========   ||
  8. ||          /    |________|  |_|    |_|  |_|   \__|  |______/   |_|   \_|  |_|    |_|    \           ||
  9. ||                                                                                                   ||
  10. ||                                                                                                   ||
  11. ||                                        Property-Filterscript                                      ||
  12. ||                                      Tradução 1.0 Phoenix Encoder´s                               ||
  13. ||===================================================================================================||
  14. ||                           Criado em 5 de junho 2008 by =>Sandra<=                                 ||
  15. ||                                    Não remova os creditos   !!                                    ||
  16. \*===================================================================================================*/
  17. //[email protected] participe de nossa equipe !!!
  18. #include <a_samp>
  19. #include <dini>
  20.  
  21. #define MAX_PROPERTIES 100
  22. #define MAX_PROPERTIES_PER_PLAYER 4
  23. #define UNBUYABLETIME 15  //If a propertie is bought, someone else have to wait this number of minutes before he/she can buy it.
  24.  
  25. #define ENABLE_LOGIN_SYSTEM 0
  26. #define ENABLE_MAP_ICON_STREAMER 1
  27.  
  28. #define REGISTER_COMMAND "/register"
  29. #define LOGIN_COMMAND "/login"
  30.  
  31. new PropertiesAmount;
  32. new MP;
  33. enum propinfo
  34. {
  35.     PropName[64],
  36.     Float:PropX,
  37.     Float:PropY,
  38.     Float:PropZ,
  39.     PropIsBought,
  40.     PropUnbuyableTime,
  41.     PropOwner[MAX_PLAYER_NAME],
  42.     PropValue,
  43.     PropEarning,
  44.     PickupNr,
  45. }
  46. new PropInfo[MAX_PROPERTIES][propinfo]; //CarInfo
  47. new PlayerProps[MAX_PLAYERS];
  48. new EarningsForPlayer[MAX_PLAYERS];
  49. new Logged[MAX_PLAYERS];
  50.  
  51. public OnFilterScriptInit()
  52. {
  53.     LoadProperties();
  54.     MP = GetMaxPlayers();
  55.     for(new i; i<MP; i++)
  56.     {
  57.         if(IsPlayerConnected(i))
  58.         {
  59.             new pName[MAX_PLAYER_NAME];
  60.             GetPlayerName(i, pName, MAX_PLAYER_NAME);
  61.             for(new propid; propid < PropertiesAmount; propid++)
  62.             {
  63.                 if(PropInfo[propid][PropIsBought] == 1)
  64.                 {
  65.                     if(strcmp(PropInfo[propid][PropOwner], pName, true)==0)
  66.                     {
  67.                         EarningsForPlayer[i] += PropInfo[propid][PropEarning];
  68.                         PlayerProps[i]++;
  69.                     }
  70.                 }
  71.             }
  72.         }
  73.     }
  74.     SetTimer("UpdateUnbuyableTime", 60000, 1);
  75.     #if ENABLE_MAP_ICON_STREAMER == 1
  76.     SetTimer("MapIconStreamer", 500, 1);
  77.     #endif
  78.     SetTimer("PropertyPayout", 60000, 1);
  79.     print("-------------------------------------------------");
  80.     print("Property-System by =>Sandra<= Carregado com sucesso!");
  81.     print("-------------------------------------------------");
  82.     return 1;
  83. }
  84.  
  85. public OnFilterScriptExit()
  86. {
  87.     SaveProperties();
  88.     print("Propriedades salvadas!");
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerConnect(playerid)
  93. {
  94.     PlayerProps[playerid] = 0;
  95.     Logged[playerid] = 0;
  96.     EarningsForPlayer[playerid] = 0;
  97.     new pName[MAX_PLAYER_NAME];
  98.     GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  99.     for(new propid; propid < PropertiesAmount; propid++)
  100.     {
  101.         if(PropInfo[propid][PropIsBought] == 1)
  102.         {
  103.             if(strcmp(PropInfo[propid][PropOwner], pName, true)==0)
  104.             {
  105.                 EarningsForPlayer[playerid] += PropInfo[propid][PropEarning];
  106.                 PlayerProps[playerid]++;
  107.             }
  108.         }
  109.     }
  110.     #if ENABLE_LOGIN_SYSTEM == 0
  111.     if(PlayerProps[playerid] > 0)
  112.     {
  113.         new str[128];
  114.         format(str, 128, "Você tem atualmente %d propriedades. use: /minhasprops para saber as info de suas propriedades.", PlayerProps[playerid]);
  115.         SendClientMessage(playerid, 0x99FF66AA, str);
  116.     }
  117.     #endif
  118.     return 1;
  119. }
  120.  
  121. public OnPlayerDisconnect(playerid, reason)
  122. {
  123.     return 1;
  124. }
  125.  
  126. public OnPlayerText(playerid, text[])
  127. {
  128.     return 1;
  129. }
  130.  
  131. public OnPlayerCommandText(playerid, cmdtext[])
  132. {
  133.     new cmd[256], idx;
  134.     //new tmp[256];
  135.     cmd = strtok(cmdtext, idx);
  136.     //================================================================================================================================
  137.     //================================================================================================================================
  138.     //================================================================================================================================
  139.     if(strcmp(cmd, "/ajudaprops", true)==0 || strcmp(cmd, "/prophelp", true)==0)
  140.     {
  141.         SendClientMessage(playerid, 0x6699FFAA, "|=========================================================|");
  142.        // new str[128];
  143.         SendClientMessage(playerid, 0x6699FFAA, "Comandos de Props:");
  144.         #if ENABLE_LOGIN_SYSTEM == 1
  145.         format(str, 128, "%s  ==>> Para registrar", REGISTER_COMMAND);
  146.         SendClientMessage(playerid, 0x66CCFFAA, str);
  147.         format(str, 128, "%s  ==>> Para logar", LOGIN_COMMAND);
  148.         SendClientMessage(playerid, 0x66CCFFAA, str);
  149.         #endif
  150.         SendClientMessage(playerid, 0x66CCFFAA, "/cprop >> para comprar uma propriedade.");
  151.         SendClientMessage(playerid, 0x66CCFFAA, "/vprop >> para vender sua propriedade.");
  152.         SendClientMessage(playerid, 0x66CCFFAA, "/minhasprops >> Para ver as info de suas propriedades.");
  153.         if(IsPlayerAdmin(playerid))
  154.         {
  155.             SendClientMessage(playerid, 0x66CCFFAA, "/vtodasprops [Admin cmd] ==>> para vender todas as props dos jogadores.");
  156.         }
  157.         SendClientMessage(playerid, 0x6699FFAA, "|=========================================================|");
  158.         return 1;
  159.     }
  160.     //================================================================================================================================
  161.     //================================================================================================================================
  162.     //================================================================================================================================
  163.     if(strcmp(cmd, "/cprop", true)==0 || strcmp(cmd, "/buyprop", true)==0)
  164.     {
  165.         new str[128];
  166.         #if ENABLE_LOGIN_SYSTEM == 1
  167.         if(Logged[playerid] == 0)
  168.         {
  169.             format(str, 128, "Você precisa fazer login antes de poder comprar ou vender as props! Use: %s", LOGIN_COMMAND);
  170.             SendClientMessage(playerid, 0xFF0000AA, str);
  171.             return 1;
  172.         }
  173.         #endif
  174.        
  175.         new propid = IsPlayerNearProperty(playerid);
  176.  
  177.         if(propid == -1)
  178.         {
  179.             SendClientMessage(playerid, 0xFF0000AA, "Você tem que estar mais perto da propriedade.");
  180.             return 1;
  181.         }
  182.         if(PlayerProps[playerid] == MAX_PROPERTIES_PER_PLAYER)
  183.         {
  184.             format(str, 128, "Você ja tem %d propriedades, você não pode comprar mais propriedades!", PlayerProps[playerid]);
  185.             SendClientMessage(playerid, 0xFF0000AA, str);
  186.             return 1;
  187.         }
  188.         if(PropInfo[propid][PropIsBought] == 1)
  189.         {
  190.             new ownerid = GetPlayerID(PropInfo[propid][PropOwner]);
  191.             if(ownerid == playerid)
  192.             {
  193.                 SendClientMessage(playerid, 0xFF0000AA, "Você ja é dono desta propriedade.");
  194.                 return 1;
  195.             }
  196.             else
  197.             {
  198.                 if(PropInfo[propid][PropUnbuyableTime] > 0)
  199.                 {
  200.                     format(str, 128, "Esta propriedade ja foi comprada por %s. Você vai ter que esperar %d minutos antes de você pode comprá-lo.", PropInfo[propid][PropOwner], PropInfo[propid][PropUnbuyableTime]);
  201.                     SendClientMessage(playerid, 0xFF0000AA, str);
  202.                     return 1;
  203.                 }
  204.             }
  205.         }
  206.         if(GetPlayerMoney(playerid) < PropInfo[propid][PropValue])
  207.         {
  208.             format(str, 128, "Você não tem dinheiro suficiente para comprar esta propriedade! Você precisa de $%d,-", PropInfo[propid][PropValue]);
  209.             SendClientMessage(playerid, 0xFF0000AA, str);
  210.             return 1;
  211.         }
  212.         new pName[MAX_PLAYER_NAME];
  213.         GetPlayerName(playerid, pName, sizeof(pName));
  214.         if(PropInfo[propid][PropIsBought] && PropInfo[propid][PropUnbuyableTime] == 0)
  215.         {
  216.             new ownerid = GetPlayerID(PropInfo[propid][PropOwner]);
  217.             format(str, 128, "%s Comprou sua propriedade \"%s\". Você ganhou 50% do valor atual ($%d)", pName, PropInfo[propid][PropName], (PropInfo[propid][PropValue]/2));
  218.             GivePlayerMoney(ownerid, (PropInfo[propid][PropValue]/2));
  219.             SendClientMessage(ownerid, 0xFFFF00AA, str);
  220.             PlayerProps[ownerid]--;
  221.         }
  222.         PropInfo[propid][PropOwner] = pName;
  223.         PropInfo[propid][PropIsBought] = 1;
  224.         PropInfo[propid][PropUnbuyableTime] = UNBUYABLETIME;
  225.         EarningsForPlayer[playerid] += PropInfo[propid][PropEarning];
  226.         GivePlayerMoney(playerid, (0-PropInfo[propid][PropValue]));
  227.         format(str, 128, "Você comprou a propriedade de \"%s\" por $%d", PropInfo[propid][PropName], PropInfo[propid][PropValue]);
  228.         SendClientMessage(playerid, 0xFFFF00AA, str);
  229.         format(str, 128, "%s Comprou a propriedade \"%s\".", pName, PropInfo[propid][PropName]);
  230.         SendClientMessageToAllEx(playerid, 0xFFFF00AA, str);
  231.         PlayerProps[playerid]++;
  232.         return 1;
  233.     }
  234.     //================================================================================================================================
  235.     //================================================================================================================================
  236.     //================================================================================================================================
  237.     if(strcmp(cmd, "/vprop", true) == 0 || strcmp(cmd, "/sellprop", true) == 0)
  238.     {
  239.         new str[128];
  240.         #if ENABLE_LOGIN_SYSTEM == 1
  241.         if(Logged[playerid] == 0)
  242.         {
  243.             format(str, 128, "You have to login before you can buy or sell properties! Use: %s", LOGIN_COMMAND);
  244.             SendClientMessage(playerid, 0xFF0000AA, str);
  245.             return 1;
  246.         }
  247.         #endif
  248.         new propid = IsPlayerNearProperty(playerid);
  249.         if(propid == -1)
  250.         {
  251.             SendClientMessage(playerid, 0xFF0000AA, "Você precisa estar mais perto da propriedade.");
  252.             return 1;
  253.         }
  254.         if(PropInfo[propid][PropIsBought] == 1)
  255.         {
  256.             new ownerid = GetPlayerID(PropInfo[propid][PropOwner]);
  257.             if(ownerid != playerid)
  258.             {
  259.                 SendClientMessage(playerid, 0xFF0000AA, "Você não possui esta propriedade!");
  260.                 return 1;
  261.             }
  262.         }
  263.         new pName[MAX_PLAYER_NAME];
  264.         GetPlayerName(playerid, pName, sizeof(pName));
  265.         format(PropInfo[propid][PropOwner], MAX_PLAYER_NAME, "Ninguem");
  266.         PropInfo[propid][PropIsBought] = 0;
  267.         PropInfo[propid][PropUnbuyableTime] = 0;
  268.         GivePlayerMoney(playerid, (PropInfo[propid][PropValue]/2));
  269.         format(str, 128, "Você vendeu sua propriedade \"%s\" por 50% do valor atual: $%d,-", PropInfo[propid][PropName], PropInfo[propid][PropValue]/2);
  270.         SendClientMessage(playerid, 0xFFFF00AA, str);
  271.         format(str, 128, "%s vendeu a propriedade \"%s\".", pName, PropInfo[propid][PropName]);
  272.         SendClientMessageToAllEx(playerid, 0xFFFF00AA, str);
  273.         PlayerProps[playerid]--;
  274.         EarningsForPlayer[playerid] -= PropInfo[propid][PropEarning];
  275.         return 1;
  276.     }
  277.     //================================================================================================================================
  278.     //================================================================================================================================
  279.     //================================================================================================================================
  280.     if(strcmp(cmd, "/minhasprops", true) == 0 || strcmp(cmd, "/myprops", true) == 0)
  281.     {
  282.         new str[128], ownerid;
  283.         #if ENABLE_LOGIN_SYSTEM == 1
  284.         if(Logged[playerid] == 0)
  285.         {
  286.             format(str, 128, "You have to login before you can buy or sell properties! Use: %s", LOGIN_COMMAND);
  287.             SendClientMessage(playerid, 0xFF0000AA, str);
  288.             return 1;
  289.         }
  290.         #endif
  291.         if(PlayerProps[playerid] == 0)
  292.         {
  293.             SendClientMessage(playerid, 0xFF0000AA, "YVocê não possui propriedades!");
  294.             return 1;
  295.         }
  296.         format(str, 128, "|============Suas %d propriedades: =============|", PlayerProps[playerid]);
  297.         SendClientMessage(playerid, 0x99FF66AA, str);
  298.         for(new propid; propid < PropertiesAmount; propid++)
  299.         {
  300.             if(PropInfo[propid][PropIsBought] == 1)
  301.             {
  302.                 ownerid = GetPlayerID(PropInfo[propid][PropOwner]);
  303.                 if(ownerid == playerid)
  304.                 {
  305.                     format(str, 128, ">> \"%s\"   Valor: $%d,-   Recebe: $%d,-", PropInfo[propid][PropName], PropInfo[propid][PropValue], PropInfo[propid][PropEarning]);
  306.                     SendClientMessage(playerid, 0x99FF66AA, str);
  307.                 }
  308.             }
  309.         }
  310.         SendClientMessage(playerid, 0x99FF66AA, "|============================================|");
  311.         return 1;
  312.     }
  313.     //================================================================================================================================
  314.     //================================================================================================================================
  315.     //================================================================================================================================
  316.     #if ENABLE_LOGIN_SYSTEM == 1
  317.     if(strcmp(cmd, REGISTER_COMMAND, true) == 0)
  318.     {
  319.         new str[128];
  320.         if(Logged[playerid] == 1) return SendClientMessage(playerid, 0xFF0000AA, "Você ja esta logado!!!");
  321.         tmp = strtok(cmdtext, idx);
  322.         if(!strlen(tmp))
  323.         {
  324.             format(str, 128, "Use: %s 'Your Password'", REGISTER_COMMAND);
  325.             SendClientMessage(playerid, 0xFF9966AA, str);
  326.             return 1;
  327.         }
  328.         if(strlen(tmp) < 5) return SendClientMessage(playerid, 0xFF9966AA, "Senha pequena limite minimo 5 crt.");
  329.         if(strlen(tmp) > 20) return SendClientMessage(playerid, 0xFF9966AA, "senha grande de mais, limite 20 caracteres.");
  330.         new pName[MAX_PLAYER_NAME], pass;
  331.         GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  332.         pass = dini_Int("PropertySystem/PlayerAccounts.txt", pName);
  333.         if(pass == 0)
  334.         {
  335.             dini_IntSet("PropertySystem/PlayerAccounts.txt", pName, encodepass(tmp));
  336.             Logged[playerid] = 1;
  337.             format(str, 128, "Seu nome goi registrado em nossa data base. \"%s %s\" agora logue se", LOGIN_COMMAND, tmp);
  338.             SendClientMessage(playerid, 0x99FF66AA, str);
  339.         }
  340.         else
  341.         {
  342.             format(str, 128, "Este nome ja esta registrado!! ise  %s !", LOGIN_COMMAND);
  343.             SendClientMessage(playerid, 0xFF9966AA, str);
  344.         }
  345.         return 1;
  346.     }
  347.     //================================================================================================================================
  348.     //================================================================================================================================
  349.     //================================================================================================================================
  350.     if(strcmp(cmd, LOGIN_COMMAND, true) == 0)
  351.     {
  352.         new str[128];
  353.         if(Logged[playerid] == 1) return SendClientMessage(playerid, 0xFF0000AA, "Você ja esta logado!!!");
  354.         tmp = strtok(cmdtext, idx);
  355.         if(!strlen(tmp))
  356.         {
  357.             format(str, 128, "Use: %s 'Sua senha'", LOGIN_COMMAND);
  358.             SendClientMessage(playerid, 0xFF9966AA, str);
  359.             return 1;
  360.         }
  361.         new pName[MAX_PLAYER_NAME], pass;
  362.         GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
  363.         pass = dini_Int("PropertySystem/PlayerAccounts.txt", pName);
  364.         if(pass == 0)
  365.         {
  366.             format(str, 128, "Este nome não esta registrado use %s  para registrar este nome!", REGISTER_COMMAND);
  367.             SendClientMessage(playerid, 0xFF9966AA, str);
  368.         }
  369.         else
  370.         {
  371.             if(pass == encodepass(tmp))
  372.             {
  373.                 Logged[playerid] = 1;
  374.                 SendClientMessage(playerid, 0x99FF66AA, "Você esta logado agora você pode vender e compra propriedades!");
  375.             }
  376.             else
  377.             {
  378.                 SendClientMessage(playerid, 0xFF0000AA, "Errou a senha");
  379.             }
  380.         }
  381.         #if ENABLE_LOGIN_SYSTEM == 1
  382.         if(PlayerProps[playerid] > 0)
  383.         {
  384.             format(str, 128, "YVocê é dono de %d propriedades. use /minhasprops para mais informações.", PlayerProps[playerid]);
  385.             SendClientMessage(playerid, 0x99FF66AA, str);
  386.         }
  387.         #endif
  388.         return 1;
  389.     }
  390.     #endif
  391.     //================================================================================================================================
  392.     //================================================================================================================================
  393.     //================================================================================================================================
  394.     if(strcmp(cmd, "/vtodasprops", true)==0)
  395.     {
  396.         if(IsPlayerAdmin(playerid))
  397.         {
  398.             for(new propid; propid<PropertiesAmount; propid++)
  399.             {
  400.                 format(PropInfo[propid][PropOwner], MAX_PLAYER_NAME, "Ninguem");
  401.                 PropInfo[propid][PropIsBought] = 0;
  402.                 PropInfo[propid][PropUnbuyableTime] = 0;
  403.             }
  404.             for(new i; i<MAX_PLAYERS; i++)
  405.             {
  406.                 if(IsPlayerConnected(i))
  407.                 {
  408.                     PlayerProps[i] = 0;
  409.                 }
  410.             }
  411.             new str[128], pName[24];
  412.             GetPlayerName(playerid, pName, 24);
  413.             format(str, 128, "Admin %s vendeu todas as propriedades!", pName);
  414.             SendClientMessageToAll(0xFFCC66AA, str);
  415.         }
  416.         return 1;
  417.     }
  418.     //================================================================================================================================
  419.     //================================================================================================================================
  420.     //================================================================================================================================
  421.     return 0;
  422. }
  423.  
  424.  
  425. public OnPlayerPickUpPickup(playerid, pickupid)
  426. {
  427.     new propid = -1;
  428.     for(new id; id<MAX_PROPERTIES; id++)
  429.     {
  430.         if(PropInfo[id][PickupNr] == pickupid)
  431.         {
  432.             propid = id;
  433.             break;
  434.         }
  435.     }
  436.     if(propid != -1)
  437.     {
  438.         new str[128];
  439.         format(str, 128, "~y~\"%s\"~n~~r~Valor: ~y~$%d~n~~r~Ganhos: ~y~$%d~n~~r~Dono: ~y~%s", PropInfo[propid][PropName], PropInfo[propid][PropValue], PropInfo[propid][PropEarning], PropInfo[propid][PropOwner]);
  440.         GameTextForPlayer(playerid, str, 6000, 3);
  441.     }
  442.     return 1;
  443. }
  444.  
  445. stock LoadProperties()
  446. {
  447.     if(fexist("PropertySystem/PropertyInfo.txt"))
  448.     {
  449.         CountProperties();
  450.         new Argument[9][70];
  451.         new entry[256], BoughtProps;
  452.         new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_read);
  453.         if (propfile)
  454.         {
  455.             for(new id; id<PropertiesAmount; id++)
  456.             {
  457.                 fread(propfile, entry);
  458.                 split(entry, Argument, ',');
  459.                 format(PropInfo[id][PropName], 64, "%s", Argument[0]);
  460.                 PropInfo[id][PropX] = floatstr(Argument[1]);
  461.                 PropInfo[id][PropY] = floatstr(Argument[2]);
  462.                 PropInfo[id][PropZ] = floatstr(Argument[3]);
  463.                 PropInfo[id][PropValue] = strval(Argument[4]);
  464.                 PropInfo[id][PropEarning] = strval(Argument[5]);
  465.                 format(PropInfo[id][PropOwner], MAX_PLAYER_NAME, "%s", Argument[6]);
  466.                 PropInfo[id][PropIsBought] = strval(Argument[7]);
  467.                 PropInfo[id][PropUnbuyableTime] = strval(Argument[8]);
  468.                 PropInfo[id][PickupNr] = CreatePickup(1273, 1, PropInfo[id][PropX], PropInfo[id][PropY], PropInfo[id][PropZ]);
  469.                 if(PropInfo[id][PropIsBought] == 1)
  470.                 {
  471.                     BoughtProps++;
  472.                 }
  473.             }
  474.             fclose(propfile);
  475.             printf("===================================");
  476.             printf("||    Foi localizado %d propriedades||", PropertiesAmount);
  477.             printf("||%d das propriedades sao compradas ||", BoughtProps);
  478.             printf("===================================");
  479.         }
  480.     }
  481. }
  482.  
  483. stock SaveProperties()
  484. {
  485.     new entry[256];
  486.     new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_write);
  487.     for(new id; id<PropertiesAmount; id++)
  488.     {
  489.         format(entry, 128, "%s,%.2f,%.2f,%.2f,%d,%d,%s,%d,%d \r\n",PropInfo[id][PropName], PropInfo[id][PropX], PropInfo[id][PropY], PropInfo[id][PropZ], PropInfo[id][PropValue], PropInfo[id][PropEarning], PropInfo[id][PropOwner], PropInfo[id][PropIsBought], PropInfo[id][PropUnbuyableTime]);
  490.         fwrite(propfile, entry);
  491.     }
  492.     printf("Salva %d Propiedades!", PropertiesAmount);
  493.     fclose(propfile);
  494. }
  495.  
  496. forward split(const strsrc[], strdest[][], delimiter);
  497. public split(const strsrc[], strdest[][], delimiter)
  498. {
  499.     new i, li;
  500.     new aNum;
  501.     new len;
  502.     while(i <= strlen(strsrc)){
  503.         if(strsrc[i]==delimiter || i==strlen(strsrc)){
  504.             len = strmid(strdest[aNum], strsrc, li, i, 128);
  505.             strdest[aNum][len] = 0;
  506.             li = i+1;
  507.             aNum++;
  508.         }
  509.         i++;
  510.     }
  511.     return 1;
  512. }
  513.  
  514. stock CountProperties()
  515. {
  516.     new entry[256];
  517.     new File: propfile = fopen("PropertySystem/PropertyInfo.txt", io_read);
  518.     while(fread(propfile, entry, 256))
  519.     {
  520.         PropertiesAmount++;
  521.     }
  522.     fclose(propfile);
  523. }
  524.  
  525. forward IsPlayerNearProperty(playerid);
  526. public IsPlayerNearProperty(playerid)
  527. {
  528.     new Float:Distance;
  529.     for(new prop; prop<PropertiesAmount; prop++)
  530.     {
  531.         Distance = GetDistanceToProperty(playerid, prop);
  532.         if(Distance < 1.0)
  533.         {
  534.             return prop;
  535.         }
  536.     }
  537.     return -1;
  538. }
  539.  
  540. forward Float:GetDistanceToProperty(playerid, Property);
  541. public Float:GetDistanceToProperty(playerid, Property)
  542. {
  543.     new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  544.     GetPlayerPos(playerid,x1,y1,z1);
  545.     x2 = PropInfo[Property][PropX];
  546.     y2 = PropInfo[Property][PropY];
  547.     z2 = PropInfo[Property][PropZ];
  548.     return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  549. }
  550.  
  551. stock GetPlayerID(const Name[])
  552. {
  553.     for(new i; i<MAX_PLAYERS; i++)
  554.     {
  555.         if(IsPlayerConnected(i))
  556.         {
  557.             new pName[MAX_PLAYER_NAME];
  558.             GetPlayerName(i, pName, sizeof(pName));
  559.             if(strcmp(Name, pName, true)==0)
  560.             {
  561.                 return i;
  562.             }
  563.         }
  564.     }
  565.     return -1;
  566. }
  567.  
  568. stock SendClientMessageToAllEx(exeption, color, const message[])
  569. {
  570.     for(new i; i<MAX_PLAYERS; i++)
  571.     {
  572.         if(IsPlayerConnected(i))
  573.         {
  574.             if(i != exeption)
  575.             {
  576.                 SendClientMessage(i, color, message);
  577.             }
  578.         }
  579.     }
  580. }
  581.  
  582. forward UpdateUnbuyableTime();
  583. public UpdateUnbuyableTime()
  584. {
  585.     for(new propid; propid<PropertiesAmount; propid++)
  586.     {
  587.         if(PropInfo[propid][PropIsBought] == 1)
  588.         {
  589.             if(PropInfo[propid][PropUnbuyableTime] > 0)
  590.             {
  591.                 PropInfo[propid][PropUnbuyableTime]--;
  592.             }
  593.         }
  594.     }
  595. }
  596.  
  597. stock encodepass(buf[]) {
  598.     new length=strlen(buf);
  599.     new s1 = 1;
  600.     new s2 = 0;
  601.     new n;
  602.     for (n=0; n<length; n++)
  603.     {
  604.        s1 = (s1 + buf[n]) % 65521;
  605.        s2 = (s2 + s1)     % 65521;
  606.     }
  607.     return (s2 << 16) + s1;
  608. }
  609.  
  610. forward MapIconStreamer();
  611. public MapIconStreamer()
  612. {
  613.     for(new i; i<MP; i++)
  614.     {
  615.         if(IsPlayerConnected(i))
  616.         {
  617.             new Float:SmallestDistance = 99999.9;
  618.             new CP, Float:OldDistance;
  619.             for(new propid; propid<PropertiesAmount; propid++)
  620.             {
  621.                 OldDistance = GetDistanceToProperty(i, propid);
  622.                 if(OldDistance < SmallestDistance)
  623.                 {
  624.                     SmallestDistance = OldDistance;
  625.                     CP = propid;
  626.                 }
  627.             }
  628.             RemovePlayerMapIcon(i, 31);
  629.             if(PropInfo[CP][PropIsBought] == 1)
  630.             {
  631.                 SetPlayerMapIcon(i, 31, PropInfo[CP][PropX], PropInfo[CP][PropY], PropInfo[CP][PropZ], 32, 0);
  632.             }
  633.             else
  634.             {
  635.                 SetPlayerMapIcon(i, 31, PropInfo[CP][PropX], PropInfo[CP][PropY], PropInfo[CP][PropZ], 31, 0);
  636.             }
  637.         }
  638.     }
  639. }
  640.  
  641. forward PropertyPayout();
  642. public PropertyPayout()
  643. {
  644.     new str[64];
  645.     for(new i; i<MAX_PLAYERS; i++)
  646.     {
  647.         if(IsPlayerConnected(i))
  648.         {
  649.             if(PlayerProps[i] > 0)
  650.             {
  651.                 GivePlayerMoney(i, EarningsForPlayer[i]);
  652.                 format(str, 64, "Você ganhou $%d,- De suas propriedades!", EarningsForPlayer[i]);
  653.                 SendClientMessage(i, 0xFFFF00AA, str);
  654.             }
  655.         }
  656.     }
  657. }
  658.  
  659. strtok(const string[], &index)
  660. {
  661. new length = strlen(string);
  662. while ((index < length) && (string[index] <= ' '))
  663. {
  664. index++;
  665. }
  666.  
  667. new offset = index;
  668. new result[20];
  669. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  670. {
  671. result[index - offset] = string[index];
  672. index++;
  673. }
  674. result[index - offset] = EOS;
  675. return result;
  676. }
Advertisement
Add Comment
Please, Sign In to add comment