SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <a_samp> | |
| 2 | ||
| 3 | forward Fader_PlayerProcess(playerid); | |
| 4 | stock fadeIn(playerid, ms, color = 0x000000FF); | |
| 5 | stock fadeOut(playerid, ms, color = 0x000000FF); | |
| 6 | ||
| 7 | static const | |
| 8 | MAX_TRANSPARENCY = 0xFF, | |
| 9 | TIMER_FRAME = 50; | |
| 10 | ||
| 11 | enum {
| |
| 12 | FADE_IN = 1, | |
| 13 | FADE_OUT | |
| 14 | } | |
| 15 | ||
| 16 | enum E_PLAYER_FADE_INFO {
| |
| 17 | PlayerText:fadeText, | |
| 18 | fadeCurrentAlpha, | |
| 19 | ||
| 20 | fadeTotalFrames, | |
| 21 | fadeTransparencyPerFrame, | |
| 22 | fadeColor, | |
| 23 | ||
| 24 | fadeTimer, | |
| 25 | fadeType | |
| 26 | } | |
| 27 | static gPlayerFadeInfo[MAX_PLAYERS][E_PLAYER_FADE_INFO]; | |
| 28 | ||
| 29 | #define CAP_MAX(%0) ((%0 > MAX_TRANSPARENCY) ? (MAX_TRANSPARENCY) : %0) | |
| 30 | #define CAP_MIN(%0) ((%0 < 0) ? (0) : %0) | |
| 31 | ||
| 32 | /* Natives: | |
| 33 | * native fadeIn(playerid, ms, color = 0x000000FF); | |
| 34 | * native fadeOut(playerid, ms, color = 0x000000FF); | |
| 35 | * | |
| 36 | * por Stewie` | |
| 37 | */ | |
| 38 | ||
| 39 | stock fadeIn(playerid, ms, color = 0x000000FF) {
| |
| 40 | if(!IsPlayerConnected(playerid)) | |
| 41 | return 0; | |
| 42 | ||
| 43 | // pegar a transparência atual da textdraw | |
| 44 | new alpha = gPlayerFadeInfo[playerid][fadeCurrentAlpha]; | |
| 45 | // no caso da textdraw tiver a transparência cheia, ou mais do que o permitido, o nosso trabalho está feito | |
| 46 | if((MAX_TRANSPARENCY - alpha) <= 0) {
| |
| 47 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] = MAX_TRANSPARENCY; | |
| 48 | gPlayerFadeInfo[playerid][fadeType] = 0; | |
| 49 | ||
| 50 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | alpha); | |
| 51 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 52 | return 1; | |
| 53 | } | |
| 54 | // configurar o tipo de fade que estamos aplicando | |
| 55 | gPlayerFadeInfo[playerid][fadeType] = FADE_IN; | |
| 56 | ||
| 57 | // mover um byte para a direita para 'apagar' a transparência | |
| 58 | // e '>>' para não voltar para o começo os primeiros bits | |
| 59 | gPlayerFadeInfo[playerid][fadeColor] = color >> 8; | |
| 60 | ||
| 61 | // a quantidade de frames que o PlayerProcess irá processar | |
| 62 | // você pode perceber que a duração é dividida pelos frames por processamento e, se existe restante, é adicinado mais um processamento | |
| 63 | gPlayerFadeInfo[playerid][fadeTotalFrames] = ((ms / TIMER_FRAME) + _:((ms % TIMER_FRAME) > 0)); | |
| 64 | // o tanto de transparência que será adicionado por cada processamento | |
| 65 | // no fim, deve ser checado a quantidade de transarência que a textdraw possui | |
| 66 | // a transparência que será adicionada até o final é dividida pela quantidade de frames que serão rodados | |
| 67 | gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] = (MAX_TRANSPARENCY - alpha) / gPlayerFadeInfo[playerid][fadeTotalFrames]; | |
| 68 | ||
| 69 | if(gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] <= 0) {
| |
| 70 | gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] = 10; | |
| 71 | } | |
| 72 | ||
| 73 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | alpha); | |
| 74 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 75 | // se não existir o timer, criá-lo! | |
| 76 | if(!gPlayerFadeInfo[playerid][fadeTimer]) {
| |
| 77 | gPlayerFadeInfo[playerid][fadeTimer] = SetTimerEx("Fader_PlayerProcess", TIMER_FRAME, 1, "i", playerid);
| |
| 78 | } | |
| 79 | return 1; | |
| 80 | } | |
| 81 | ||
| 82 | stock fadeOut(playerid, ms, color = 0x000000FF) {
| |
| 83 | if(!IsPlayerConnected(playerid)) | |
| 84 | return 0; | |
| 85 | ||
| 86 | // pegar a transparência atual da textdraw | |
| 87 | new alpha = gPlayerFadeInfo[playerid][fadeCurrentAlpha]; | |
| 88 | // no caso da textdraw não tiver nenhuma transparênca, sair | |
| 89 | if(alpha <= 0) {
| |
| 90 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] = MAX_TRANSPARENCY; | |
| 91 | gPlayerFadeInfo[playerid][fadeType] = 0; | |
| 92 | ||
| 93 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | alpha); | |
| 94 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 95 | return 1; | |
| 96 | } | |
| 97 | // configurar o tipo de fade que estamos aplicando | |
| 98 | gPlayerFadeInfo[playerid][fadeType] = FADE_OUT; | |
| 99 | ||
| 100 | // mover um byte para a direita para 'apagar' a transparência | |
| 101 | // e '>>' para não voltar para o começo os primeiros bits | |
| 102 | gPlayerFadeInfo[playerid][fadeColor] = color >> 8; | |
| 103 | ||
| 104 | // a quantidade de frames que o PlayerProcess irá processar | |
| 105 | // você pode perceber que a duração é dividida pelos frames por processamento e, se existe restante, é adicinado mais um processamento | |
| 106 | gPlayerFadeInfo[playerid][fadeTotalFrames] = ((ms / TIMER_FRAME) + _:((ms % TIMER_FRAME) > 0)); | |
| 107 | // o tanto de transparência que será subtraída por cada processamento | |
| 108 | // no fim, deve ser checado a quantidade de transarência que a textdraw possui | |
| 109 | // a transparência que será subtraída até o final é dividida pela quantidade de frames que serão rodados | |
| 110 | gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] = (alpha) / gPlayerFadeInfo[playerid][fadeTotalFrames]; | |
| 111 | ||
| 112 | if(gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] <= 0) {
| |
| 113 | gPlayerFadeInfo[playerid][fadeTransparencyPerFrame] = 10; | |
| 114 | } | |
| 115 | ||
| 116 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | alpha); | |
| 117 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 118 | // se não existir o timer, criá-lo! | |
| 119 | if(!gPlayerFadeInfo[playerid][fadeTimer]) {
| |
| 120 | gPlayerFadeInfo[playerid][fadeTimer] = SetTimerEx("Fader_PlayerProcess", TIMER_FRAME, 1, "i", playerid);
| |
| 121 | } | |
| 122 | return 1; | |
| 123 | } | |
| 124 | ||
| 125 | public Fader_PlayerProcess(playerid) {
| |
| 126 | // se o fade foi desligado para o player, mas o timer ainda está ativo | |
| 127 | if(gPlayerFadeInfo[playerid][fadeType] == 0) {
| |
| 128 | // se o timer existe | |
| 129 | if(gPlayerFadeInfo[playerid][fadeTimer] > 0) {
| |
| 130 | KillTimer(gPlayerFadeInfo[playerid][fadeTimer]); | |
| 131 | gPlayerFadeInfo[playerid][fadeTimer] = 0; | |
| 132 | ||
| 133 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | gPlayerFadeInfo[playerid][fadeCurrentAlpha]); | |
| 134 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 135 | } | |
| 136 | } | |
| 137 | ||
| 138 | switch(gPlayerFadeInfo[playerid][fadeType]) {
| |
| 139 | case FADE_IN: {
| |
| 140 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] += gPlayerFadeInfo[playerid][fadeTransparencyPerFrame]; | |
| 141 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] = CAP_MAX(gPlayerFadeInfo[playerid][fadeCurrentAlpha]); | |
| 142 | ||
| 143 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | gPlayerFadeInfo[playerid][fadeCurrentAlpha]); | |
| 144 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 145 | ||
| 146 | if(gPlayerFadeInfo[playerid][fadeCurrentAlpha] == MAX_TRANSPARENCY) {
| |
| 147 | gPlayerFadeInfo[playerid][fadeType] = 0; | |
| 148 | KillTimer(gPlayerFadeInfo[playerid][fadeTimer]); | |
| 149 | gPlayerFadeInfo[playerid][fadeTimer] = 0; | |
| 150 | } | |
| 151 | } | |
| 152 | case FADE_OUT: {
| |
| 153 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] -= gPlayerFadeInfo[playerid][fadeTransparencyPerFrame]; | |
| 154 | gPlayerFadeInfo[playerid][fadeCurrentAlpha] = CAP_MIN(gPlayerFadeInfo[playerid][fadeCurrentAlpha]); | |
| 155 | ||
| 156 | PlayerTextDrawBoxColor(playerid, gPlayerFadeInfo[playerid][fadeText], (gPlayerFadeInfo[playerid][fadeColor] << 8) | gPlayerFadeInfo[playerid][fadeCurrentAlpha]); | |
| 157 | PlayerTextDrawShow(playerid, gPlayerFadeInfo[playerid][fadeText]); | |
| 158 | ||
| 159 | if(gPlayerFadeInfo[playerid][fadeCurrentAlpha] == 0) {
| |
| 160 | gPlayerFadeInfo[playerid][fadeType] = 0; | |
| 161 | KillTimer(gPlayerFadeInfo[playerid][fadeTimer]); | |
| 162 | gPlayerFadeInfo[playerid][fadeTimer] = 0; | |
| 163 | } | |
| 164 | } | |
| 165 | } | |
| 166 | return 1; | |
| 167 | } | |
| 168 | ||
| 169 | public OnPlayerConnect(playerid) {
| |
| 170 | new tmp[E_PLAYER_FADE_INFO]; | |
| 171 | gPlayerFadeInfo[playerid] = tmp; | |
| 172 | ||
| 173 | new PlayerText:text = CreatePlayerTextDraw(playerid, -20.0, -20.0, "_"); | |
| 174 | gPlayerFadeInfo[playerid][fadeText] = text; | |
| 175 | // detalhes | |
| 176 | PlayerTextDrawUseBox(playerid, text, 1); | |
| 177 | PlayerTextDrawBoxColor(playerid, text, 0xFFFFFF00); | |
| 178 | PlayerTextDrawLetterSize(playerid, text, 680.0, 500.0); | |
| 179 | PlayerTextDrawTextSize(playerid, text, 680.0, 500.0); | |
| 180 | return 1; | |
| 181 | } | |
| 182 | ||
| 183 | public OnPlayerDisconnect(playerid,reason) {
| |
| 184 | gPlayerFadeInfo[playerid][fadeTimer] = 0; | |
| 185 | return 1; | |
| 186 | } | |
| 187 | ||
| 188 | #if defined _ALS_OnPlayerConnect | |
| 189 | #undef OnPlayerConnect | |
| 190 | #else | |
| 191 | #define _ALS_OnPlayerConnect | |
| 192 | #endif | |
| 193 | #define OnPlayerConnect FD_OnPlayerConnect | |
| 194 | forward FD_OnPlayerConnect(playerid); | |
| 195 | ||
| 196 | #if defined _ALS_OnPlayerDisconnect | |
| 197 | #undef OnPlayerDisconnect | |
| 198 | #else | |
| 199 | #define _ALS_OnPlayerDisconnect | |
| 200 | #endif | |
| 201 | #define OnPlayerDisconnect FD_OnPlayerDisconnect | |
| 202 | forward FD_OnPlayerDisconnect(playerid,reason); |