Y_Less

y_zonepulse.inc

Feb 19th, 2012
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.89 KB | None | 0 0
  1. /*----------------------------------------------------------------------------*\
  2.                     ===========================
  3.                      Gang Zone colour pulsing.
  4.                     ===========================
  5. Description:
  6.     Gradually fades a zone's colour between one colour and another, then back.
  7. Legal:
  8.     Version: MPL 1.1
  9.    
  10.     The contents of this file are subject to the Mozilla Public License Version
  11.     1.1 (the "License"); you may not use this file except in compliance with
  12.     the License. You may obtain a copy of the License at
  13.     http://www.mozilla.org/MPL/
  14.    
  15.     Software distributed under the License is distributed on an "AS IS" basis,
  16.     WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  17.     for the specific language governing rights and limitations under the
  18.     License.
  19.    
  20.     The Original Code is the YSI foreach include.
  21.    
  22.     The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  23.     Portions created by the Initial Developer are Copyright (C) 2011
  24.     the Initial Developer. All Rights Reserved.
  25.    
  26.     Contributors:
  27.         ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  28.    
  29.     Thanks:
  30.         JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  31.         ZeeX - Very productive conversations.
  32.         koolk - IsPlayerinAreaEx code.
  33.         TheAlpha - Danish translation.
  34.         breadfish - German translation.
  35.         Fireburn - Dutch translation.
  36.         yom - French translation.
  37.         50p - Polish translation.
  38.         Zamaroht - Spanish translation.
  39.         Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  40.             for me to strive to better.
  41.         Pixels^ - Running XScripters where the idea was born.
  42.         Matite - Pestering me to release it and using it.
  43.    
  44.     Very special thanks to:
  45.         Thiadmer - PAWN, whose limits continue to amaze me!
  46.         Kye/Kalcor - SA:MP.
  47.         SA:MP Team past, present and future - SA:MP.
  48.    
  49. Version:
  50.     0.2
  51. Changelog:
  52.     19/02/12:
  53.         Added "time2" and "delay2" parameters.
  54.         First version.
  55. Functions:
  56.     Public:
  57.         __GangZonePulse - The timer that does the hard work.
  58.     Core:
  59.         -
  60.     Stock:
  61.         GangZonePulse - Pulse a zone for player or collection of players.
  62.         GangZonePulseForPlayer - Pulse a zone for a player.
  63.         GangZonePulseForAll - Pulse a zone for everyone.
  64.         GangZoneStopPulse - Stop a zone pulsing for a set of players.
  65.         GangZoneStopPulseForPlayer - Stop a zone pulsing for a single player.
  66.         GangZoneStopPulseForAll - Stop a zone pulsing for everyone.
  67.     Static:
  68.         -
  69.     Inline:
  70.         -
  71.     API:
  72.         -
  73. Callbacks:
  74.     -
  75. Hooks:
  76.     -
  77. Definitions:
  78.     -
  79. Enums:
  80.     -
  81. Macros:
  82.     -
  83. Keywords:
  84.     -
  85. Tags:
  86.     -
  87. Variables:
  88.     Global:
  89.         -
  90.     Static:
  91.         -
  92. Commands:
  93.     -
  94. Compile options:
  95.     ZONE_PULSE_STAGE_TIME - ms between each pulse frame.
  96. Operators:
  97.     -
  98. Iterators:
  99.     -
  100. \*----------------------------------------------------------------------------*/
  101.  
  102. /*
  103. native GangZonePulse(@PlayerSet:ps, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1);
  104. native GangZonePulseForPlayer(playerid, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1);
  105. native GangZonePulseForAll(zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1);
  106. native GangZoneStopPulse(@PlayerSet:ps, zone);
  107. native GangZoneStopPulseForPlayer(playerid, zone);
  108. native GangZoneStopPulseForAll(zone);
  109. */
  110.  
  111. #include <a_samp>
  112. #include <YSI\internal\y_version>
  113. #include <YSI\y_playerset>
  114. #include <YSI\y_iterate>
  115. #include <YSI\y_debug>
  116.  
  117. #if !defined ZONE_PULSE_STAGE_TIME
  118.     #define ZONE_PULSE_STAGE_TIME (50)
  119. #endif
  120.  
  121. forward __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2);
  122.  
  123. public __GangZonePulse(playerid, zone, from, to, time, stage, delay, time2, delay2)
  124. {
  125.     if (!IsPlayerConnected(playerid))
  126.     {
  127.         return;
  128.     }
  129.     static
  130.         sTimer[32];
  131.     format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  132.     stage = (stage + 1) % (time + time2);
  133.     if (stage == time)
  134.     {
  135.         GangZoneShowForPlayer(playerid, zone, to);
  136.         SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", delay, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  137.         return;
  138.     }
  139.     else if (stage == 0)
  140.     {
  141.         GangZoneShowForPlayer(playerid, zone, from);
  142.         SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", delay2, 0, "iiiiiiiii", playerid, zone, from, to, time, 0, delay, time2, delay2));
  143.         return;
  144.     }
  145.     if (stage > time)
  146.     {
  147.         // Fade back
  148.         new
  149.             multiplier = (time2 - (stage - time2)),
  150.             r = ((to >>> 24) - (from >>> 24)) * multiplier / time2 + (from >>> 24),
  151.             g = ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) * multiplier / time2 + (from >>> 16 & 0xFF),
  152.             b = ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) * multiplier / time2 + (from >>> 8 & 0xFF),
  153.             a = ((to  & 0xFF) - (from  & 0xFF)) * multiplier / time2 + (from  & 0xFF);
  154.         P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  155.         GangZoneShowForPlayer(playerid, zone, (r << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
  156.         SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  157.     }
  158.     else
  159.     {
  160.         // Fade there.
  161.         new
  162.             r = ((to >>> 24) - (from >>> 24)) * stage / time + (from >>> 24),
  163.             g = ((to >>> 16 & 0xFF) - (from >>> 16 & 0xFF)) * stage / time + (from >>> 16 & 0xFF),
  164.             b = ((to >>> 8 & 0xFF) - (from >>> 8 & 0xFF)) * stage / time + (from >>> 8 & 0xFF),
  165.             a = ((to  & 0xFF) - (from  & 0xFF)) * stage / time + (from  & 0xFF);
  166.         P:7("__GangZonePulse: %d %d %x %x %x %x", playerid, zone, r & 0xFF, g & 0xFF, b & 0xFF, a & 0xFF);
  167.         GangZoneShowForPlayer(playerid, zone, (r << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
  168.         SetPVarInt(playerid, sTimer, SetTimerEx("__GangZonePulse", ZONE_PULSE_STAGE_TIME, 0, "iiiiiiiii", playerid, zone, from, to, time, stage, delay, time2, delay2));
  169.     }
  170.     return;
  171. }
  172.  
  173. stock _GangZonePulse(@PlayerSet:ps, zone, from, to, time, delay = ZONE_PULSE_STAGE_TIME, time2 = -1, delay2 = -1)
  174. {
  175.     static
  176.         sTimer[32];
  177.     format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  178.     if (time2 == -1)
  179.     {
  180.         time2 = time;
  181.     }
  182.     if (delay2 == -1)
  183.     {
  184.         delay2 = delay;
  185.     }
  186.     foreach (new p : PS(ps))
  187.     {
  188.         KillTimer(GetPVarInt(p, sTimer));
  189.         GangZoneShowForPlayer(p, zone, from);
  190.         SetPVarInt(p, sTimer, SetTimerEx("__GangZonePulse", delay, 0, "iiiiiiiii", p, zone, from, to, time / ZONE_PULSE_STAGE_TIME, 0, delay, time2 / ZONE_PULSE_STAGE_TIME, delay2));
  191.     }
  192. }
  193.  
  194. #define GangZonePulse(%0) PSF:_GangZonePulse(%0)
  195. #define GangZonePulseForPlayer(%0) PSF:_GangZonePulse(%0)
  196. #define GangZonePulseForAll(%0) PSF:_GangZonePulse(ALL_PLAYERS,%0)
  197.  
  198. stock _GangZoneStopPulse(@PlayerSet:ps, zone)
  199. {
  200.     static
  201.         sTimer[32];
  202.     format(sTimer, sizeof (sTimer), "y_zonepulse_%d", zone);
  203.     foreach (new p : PS(ps))
  204.     {
  205.         KillTimer(GetPVarInt(p, sTimer));
  206.     }
  207. }
  208.  
  209. #define GangZoneStopPulse(%0) PSF:_GangZoneStopPulse(%0)
  210. #define GangZoneStopPulseForPlayer(%0) PSF:_GangZoneStopPulse(%0)
  211. #define GangZoneStopPulseForAll(%0) PSF:_GangZoneStopPulse(ALL_PLAYERS,%0)
Advertisement
Add Comment
Please, Sign In to add comment