enum _:RGBA {
R,
G,
B,
A
};
enum _:MessageDataStruct {
RECIPIENT_ID,
Float:DURATION,
Float:HOLD_TIME,
COLOR1[RGBA],
COLOR2[RGBA],
bool:IS_BLIND
};
enum _:TaskDataStruct {
ARRAY_HANDLE,
BLINKS_NUM,
BLINKS_ITER
};
stock PlayerScreenBlinking(
const blinksNum = 10,
const playerId,
const Float:duration = 1.0,
const Float:holdTime = 1.0,
const color1[RGBA] = {255, 255, 255, 255},
const color2[RGBA] = {255, 255, 255, 255},
const bool:isBlind = true
) {
const TASK_ID_BASE = 13131313;
new messageData[MessageDataStruct];
messageData[RECIPIENT_ID] = playerId;
messageData[DURATION] = duration;
messageData[HOLD_TIME] = holdTime;
messageData[COLOR1][R] = color1[R];
messageData[COLOR1][G] = color1[G];
messageData[COLOR1][B] = color1[B];
messageData[COLOR1][A] = color1[A];
messageData[COLOR2][R] = color2[R];
messageData[COLOR2][G] = color2[G];
messageData[COLOR2][B] = color2[B];
messageData[COLOR2][A] = color2[A];
messageData[IS_BLIND] = isBlind;
new Array:messageDataArray = ArrayCreate(MessageDataStruct);
ArrayPushArray(messageDataArray, messageData);
new taskData[TaskDataStruct];
taskData[ARRAY_HANDLE] = any:messageDataArray;
taskData[BLINKS_NUM] = blinksNum;
for(new i = 1; i <= blinksNum; i++) {
taskData[BLINKS_ITER] = i;
set_task(duration * i, "ScreenBlinkingTask", TASK_ID_BASE, taskData, sizeof(taskData));
}
}
public ScreenBlinkingTask(taskData[TaskDataStruct]) {
new messageData[MessageDataStruct];
new Array:messageDataArray = any:taskData[ARRAY_HANDLE];
ArrayGetArray(messageDataArray, 0, messageData);
if(taskData[BLINKS_NUM] == taskData[BLINKS_ITER])
ArrayDestroy(messageDataArray);
new color[RGBA];
if(taskData[BLINKS_ITER] % 2) {
color[R] = messageData[COLOR1][R];
color[G] = messageData[COLOR1][G];
color[B] = messageData[COLOR1][B];
color[A] = messageData[COLOR1][A];
} else {
color[R] = messageData[COLOR2][R];
color[G] = messageData[COLOR2][G];
color[B] = messageData[COLOR2][B];
color[A] = messageData[COLOR2][A];
}
SendScreenFadeMessage(
messageData[RECIPIENT_ID],
messageData[DURATION],
messageData[HOLD_TIME],
color,
messageData[IS_BLIND]
);
}
stock SendScreenFadeMessage(
const playerId,
const Float:duration = 1.0,
const Float:holdTime = 1.0,
const color[RGBA] = {255, 255, 255, 255},
const bool:isBlind = true
) {
const FFADE_OUT = 0x0001;
static msgId;
if(msgId == 0 && (msgId = get_user_msgid("ScreenFade")) == 0)
return;
for(new i = (playerId == 0) ? 1 : playerId; i <= MaxClients; i++) {
if(!is_user_connected(i))
continue;
if(isBlind && PlayerIsBlind(i))
continue;
message_begin(MSG_ONE_UNRELIABLE, msgId, {0, 0, 0}, i);
write_short(FixedUnsigned16(duration));
write_short(FixedUnsigned16(holdTime));
write_short(FFADE_OUT);
write_byte(color[R]);
write_byte(color[G]);
write_byte(color[B]);
write_byte(color[A]);
message_end();
}
}
stock bool:PlayerIsBlind(const playerId) {
return bool:(Float:get_member(playerId, m_blindUntilTime) > get_gametime());
}
stock FixedUnsigned16(Float:value) {
return clamp(floatround(value * 4096.0), 0, 0xFFFF);
}