Advertisement
Kon_BR

FS kLanterna v1.0 - by Kon_BR

Nov 7th, 2012
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.18 KB | None | 0 0
  1.                                                                                                                                                       /*
  2.    __________________________________________________
  3.   |                                                  |
  4.   |          | /                                     |
  5.   |          |/                    ____________      |
  6.   | [ FS ]   | \ - Lanterna       |v1.0 | 0.3e |     |
  7.   |                                ¯¯¯¯¯¯¯¯¯¯¯¯      |    
  8.    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  9.    
  10.    Criado e desenvolvido by Kon_BR || Twist (http://forum.sa-mp.com/member.php?u=158736)
  11.    
  12.    -
  13.    
  14.    # Links úteis #
  15.    Tópico Progress Bar - http://forum.sa-mp.com/showthread.php?t=113443  
  16.  
  17.    -                                                                                                                                                    */
  18.    
  19.    
  20.    
  21. #include <a_samp>
  22.  
  23.  
  24. // ========== ## Ajustes (Como bem queira.) ## ==========
  25.  
  26.  
  27. // ~~> Nivel da escuridão, altere como bem achar melhor. ("kBaixa", "kMedia"(Default) ou "kAlta")
  28. #define NivelEscuridao kMedia
  29.  
  30.  
  31. // ~~> Defina o tempo em segundo em segundo em que gasta a lanterna (Default : 3000(de 3 em 3s))
  32. #define TempoGastarLanterna 3000
  33.  
  34. // ~~> Defina o tempo em segundo em segundo para recarregar a lanterna (Default : 7000(de 7 em 7s))
  35. #define TempoRecarregarLanterna 7000
  36.  
  37.  
  38.  
  39.  
  40. // ========== Includes ==========
  41.  
  42. #include ProgressBar
  43.  
  44. // ========== Variavéis ==========
  45.  
  46. // ~~> Textdraws
  47. new Text: TextdrawVisao[MAX_PLAYERS];
  48.  
  49. // ~~> Geral
  50. new bool:LanternaAtivada[MAX_PLAYERS];
  51. new bool:LanternaPifada[MAX_PLAYERS];
  52. new PlayerBar:BarraBateriaLanterna[MAX_PLAYERS]; // Barra de carga da lanterna. (Progress Bar)
  53. new VezesQueLigouOuDesligouLanterna[MAX_PLAYERS];
  54.  
  55. // ~~> Timers
  56. new TimerRecarregarLanterna[MAX_PLAYERS];
  57. new TimerGastarLanterna[MAX_PLAYERS];
  58. new TimerDelayLanterna[MAX_PLAYERS];
  59.  
  60. // ========== Defines ==========
  61.  
  62. // ~~> Definimos os niveis da escuridão (Hex Colours) da Textdraw, aconselho a não mexer.
  63. #define kBaixa 0x00000067
  64. #define kMedia 0x0000009A
  65. #define kAlta 0x000000CD
  66.  
  67. /* ~~> Definimos as claridades da lanterna quando está com muita carga e com pouca carga.
  68. - Aconselho a não mexer, mas caso queira aumentar/diminuir é só usar os dois ultimos numeros da Hex Colour (11 e 05 no caso) */
  69. #define LuzLanternaMaxima 0xffffff18
  70. #define LuzLanternaMinima 0xffffff08
  71.  
  72. // ========== Forwards ==========
  73.  
  74. forward GastarLanterna(playerid);
  75. forward RecarregarLanterna(playerid);
  76. forward DelayLigarEDesligarLanterna(playerid);
  77.  
  78.  
  79.  
  80.  
  81. // # Inicio #
  82.  
  83. public OnFilterScriptInit()
  84. {
  85.     print("\n--------------------------------------");
  86.     print("                                        ");
  87.     print(" FS - kLanterna  v1.0 - by Kon_BR       ");
  88.     print("                               Loaded ! ");
  89.     print("--------------------------------------\n");
  90.     return 1;
  91. }
  92.  
  93. public OnFilterScriptExit()
  94. {
  95.     return 1;
  96. }
  97.  
  98. public OnPlayerRequestClass(playerid, classid)
  99. {
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerConnect(playerid)
  104. {
  105.  
  106.     // ~~> Criar a Progress Bar da bateria da lanterna.
  107.     BarraBateriaLanterna[playerid] = CreatePlayerProgressBar(playerid,550.0, 425.0, _, _, 0xFFFF00FF, 100.0);
  108.  
  109.     // ========== Textdraws ==========
  110.  
  111.     // ~~> Textdraw lanterna (Luz ambiente (Escuro ou claro(lanterna))
  112.     TextdrawVisao[playerid] = TextDrawCreate(-20.000000,2.000000,"X");
  113.     TextDrawLetterSize(TextdrawVisao[playerid],1.000000,52.200000);
  114.     TextDrawTextSize(TextdrawVisao[playerid],660.000000,22.000000);
  115.     TextDrawUseBox(TextdrawVisao[playerid],1);
  116.     TextDrawBoxColor(TextdrawVisao[playerid],NivelEscuridao);
  117.    
  118.     // ========== Valores de variaveis ==========
  119.    
  120.     LanternaAtivada[playerid] = false;
  121.     LanternaAtivada[playerid] = false;
  122.     VezesQueLigouOuDesligouLanterna[playerid] = 0;
  123.    
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerDisconnect(playerid, reason)
  128. {
  129.     return 1;
  130. }
  131.  
  132. public OnPlayerSpawn(playerid)
  133. {
  134.    
  135.     // ~~> Mostrar a visão escura (Textdraw)
  136.     TextDrawShowForPlayer(playerid,TextdrawVisao[playerid]);
  137.  
  138.     // ~~> Mostrar e setar o valor da Progress bar
  139.     SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], 100.0);
  140.     ShowPlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  141.    
  142.     // ~~> Esconder o nick em cima da skin dos outros players (Lanterna desativada)
  143.     kEsconderNickDeTodos(playerid);
  144.    
  145.     return 1;
  146. }
  147.  
  148. public OnPlayerDeath(playerid, killerid, reason)
  149. {
  150.     // ~~> Ao player morrer, esconder a barra da bateria da lanterna. (Ela é restaurada após spawn)
  151.     HidePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  152.    
  153.     // ~~> Caso a lanterna esteja ativada, desativá-lá. E também destruir timers para não carregar ou gastar quando morre.
  154.     KillTimer(TimerRecarregarLanterna[playerid]);
  155.     KillTimer(TimerGastarLanterna[playerid]);
  156.    
  157.     if(LanternaAtivada[playerid] == true)
  158.     {
  159.     LanternaAtivada[playerid] = false;
  160.     PlayerPlaySound(playerid,1058,0,0,0);
  161.     kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],NivelEscuridao);
  162.     kEsconderNickDeTodos(playerid);
  163.     }
  164.  
  165.     return 1;
  166. }
  167.  
  168. public OnPlayerStateChange(playerid, newstate, oldstate)
  169. {
  170.     return 1;
  171. }
  172.  
  173. public OnPlayerRequestSpawn(playerid)
  174. {
  175.     return 1;
  176. }
  177.  
  178. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  179. {
  180.  
  181.     // ~~> Ligar/Desligar lanterna (Tecla N(Default)) | Caso queira alterar, à vontade. (http://wiki.sa-mp.com/wiki/GetPlayerKeys)
  182.     if(newkeys & KEY_NO)
  183.     {
  184.    
  185.         // ~~> Caso o player fique ligando e desligando a lanterna feito um bobão, ela irá pifar :b
  186.     if(VezesQueLigouOuDesligouLanterna[playerid] == 0)
  187.     {
  188.     TimerDelayLanterna[playerid] = SetTimerEx("DelayLigarEDesligarLanterna",3000,false,"d",playerid);
  189.     }
  190.     VezesQueLigouOuDesligouLanterna[playerid]++;
  191.    
  192.    
  193.     if(VezesQueLigouOuDesligouLanterna[playerid] == 5)
  194.     {
  195.     KillTimer(TimerRecarregarLanterna[playerid]);
  196.     KillTimer(TimerGastarLanterna[playerid]);
  197.     KillTimer(TimerDelayLanterna[playerid]);
  198.     LanternaAtivada[playerid] = false;
  199.     LanternaPifada[playerid] = true;
  200.    
  201.     PlayerPlaySound(playerid,1085,0,0,0);
  202.    
  203.    
  204.     kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],NivelEscuridao);
  205.     kEsconderNickDeTodos(playerid);
  206.    
  207.     SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], 0.0);
  208.     SetPlayerProgressBarColor(playerid, PlayerBar:BarraBateriaLanterna[playerid], 0x808080FF);
  209.     UpdatePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  210.     return 1;
  211.     }
  212.    
  213.     if(LanternaAtivada[playerid] == false && LanternaPifada[playerid] == false && GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) > 0.0)
  214.     {
  215.         TimerGastarLanterna[playerid] = SetTimerEx("GastarLanterna",TempoGastarLanterna,true,"d",playerid);
  216.         KillTimer(TimerRecarregarLanterna[playerid]);
  217.         LanternaAtivada[playerid] = true;
  218.        
  219.         PlayerPlaySound(playerid,1056,0,0,0);
  220.        
  221.         kMostrarNickDeTodos(playerid); // Função (stock) para mostrar o nick em cima da skin das pessoas ao seu redor
  222.        
  223.         if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) > 10.0)
  224.         {
  225.             kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],LuzLanternaMaxima);
  226.         }
  227.        
  228.         if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) <= 10.0)
  229.         {
  230.             kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],LuzLanternaMaxima);
  231.         }
  232.         return 1;
  233.     }
  234.     if(LanternaAtivada[playerid] == true && LanternaPifada[playerid] == false)
  235.     {
  236.         LanternaAtivada[playerid] = false;
  237.        
  238.         PlayerPlaySound(playerid,1058,0,0,0);
  239.        
  240.         KillTimer(TimerGastarLanterna[playerid]);
  241.         TimerRecarregarLanterna[playerid] = SetTimerEx("RecarregarLanterna",TempoRecarregarLanterna,true,"d",playerid);
  242.         kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],NivelEscuridao);
  243.        
  244.         kEsconderNickDeTodos(playerid); // Função (stock) para esconder o nick em cima da skin das pessoas ao seu redor
  245.        
  246.         return 1;
  247.     }
  248.     }
  249.  
  250.     return 1;
  251. }
  252.  
  253. public OnPlayerUpdate(playerid)
  254. {
  255.     return 1;
  256. }
  257.  
  258. public OnPlayerStreamIn(playerid, forplayerid)
  259. {
  260.     return 1;
  261. }
  262.  
  263. public OnPlayerStreamOut(playerid, forplayerid)
  264. {
  265.     return 1;
  266. }
  267.  
  268. // ========== Outras publics (Chamadas por timers) ==========
  269.  
  270. // ~~> Gastar lanterna (caso esteja ativada)
  271. public GastarLanterna(playerid)
  272. {
  273.     if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) <= 0.0)
  274.     {
  275.     KillTimer(TimerGastarLanterna[playerid]);
  276.     SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], 0.0);
  277.     TimerRecarregarLanterna[playerid] = SetTimerEx("RecarregarLanterna",TempoRecarregarLanterna,true,"d",playerid);
  278.     kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],NivelEscuridao);
  279.     LanternaAtivada[playerid] = false;
  280.    
  281.     kEsconderNickDeTodos(playerid); // Função (stock) para esconder o nick em cima da skin das pessoas ao seu redor
  282.    
  283.     return 1;
  284.     }
  285.  
  286.     if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) <= 10.0)
  287.     {
  288.     kTextDrawSetBoxColor(playerid,TextdrawVisao[playerid],LuzLanternaMinima);
  289.     SetPlayerProgressBarColor(playerid, PlayerBar:BarraBateriaLanterna[playerid], 0xFF0000FF);
  290.     UpdatePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  291.     }
  292.    
  293.     SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) - 3.0);
  294.     UpdatePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  295.     return 1;
  296. }
  297.  
  298. // ~~> Recarregar lanterna (caso esteja desativada)
  299. public RecarregarLanterna(playerid)
  300. {
  301.     if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) >= 100.0) return KillTimer(TimerRecarregarLanterna[playerid]), SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], 100.0);
  302.  
  303.     if(GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) > 10.0)
  304.     {
  305.     SetPlayerProgressBarColor(playerid, PlayerBar:BarraBateriaLanterna[playerid], 0xFFFF00FF);
  306.     UpdatePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  307.     }
  308.    
  309.     SetPlayerProgressBarValue(playerid, PlayerBar:BarraBateriaLanterna[playerid], GetPlayerProgressBarValue(playerid,PlayerBar:BarraBateriaLanterna[playerid]) + 4.0);
  310.     UpdatePlayerProgressBar(playerid, PlayerBar:BarraBateriaLanterna[playerid]);
  311.     return 1;
  312. }
  313.  
  314. // ~~> Tempo delay para ligar e desligar a lanterna (caso contrario ela pifa :D)
  315. public DelayLigarEDesligarLanterna(playerid)
  316. {
  317.  
  318.     VezesQueLigouOuDesligouLanterna[playerid] = 0;
  319.     return 1;
  320. }
  321.  
  322.  
  323.  
  324. // ========== Stocks ==========
  325.  
  326. // ~~> Esconder o nick em cima da skin de todos caso o player em questão esteja com a lanterna desativada.
  327. stock kEsconderNickDeTodos(playerid)
  328. {
  329. for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
  330. return 1;
  331. }
  332.  
  333. // ~~> Mostrar o nick em cima da skin de todos caso o player em questão esteja com a lanterna ativada.
  334. stock kMostrarNickDeTodos(playerid)
  335. {
  336. for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, true);
  337. return 1;
  338. }
  339.  
  340. // ~~> Modo "minimizado" de mudar a cor e atualizar a textdraw da visão.
  341. stock kTextDrawSetBoxColor(playerid,Text:text, color)
  342. {
  343. TextDrawBoxColor(Text:text,color);
  344. TextDrawShowForPlayer(playerid,Text:text);
  345. return 1;
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement