[INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 28.01.2010
I saw _Seif's "Seifader"
HERE and how it was limited in a few aspects.
- This screen fader uses a relatively simple formula to convert one color into the other.
- It has my rendition of 'foreach' installed so lag is at a minimum.
- Unlike Seifader, mine doesn't use hex colors, not necessarily a downfall or an upgrade, it's just done differently.
- Only uses ONE textdraw! Total! Even if you have 501 players!
Added Functions and Callbacks:
ConvertToColor(RR,GG,BB,AA):
It's only used once in this script but you might find it helpful for other occasions, it turns RR(red), GG(green), BB(blue), AA(alpha) into a single number which can be read as a hex or an integer.
FadeColorForPlayer(playerid,RR1,GG1,BB1,AA1,RR2,GG 2,BB2,AA2,steps,hold):
It's definitely a lot longer of a function and can lead to confusion, but it's relatively simple.
the first set of RR,GG,BB,AA is where the fade is going to start (best used when starting at an AA of 0), the second RR,GG,BB,AA is where the fade is going to end.
steps is relatively how many steps it's going to go through to reach the end color, please note however, this is changed to meat programming needs, so this is only relative.
hold is how many frames it's going to hold the end color before turning off (frames is UPDATERATE in-script, currently set to 100 milliseconds)
StopPlayerFade(playerid)
This stops the fade occurances and finishes it (runs OnFadeComplete twice, once for 'beforehold', and once for after hold)
SetPlayerPosFade(playerid,steps,interiorid,Float ,Float:y,Float:z) //Version 2 only
This is basically a MIC function. It will fade the player's screen to black, teleport and set interior, then fade from black to clear again for a smooth teleporting transition.
OnFadeComplete(playerid,beforehold)
A public call back called via 'CallLocalFunction' in the include.
This is called once a fade has finished.
'beforehold' will be 1 if it's running before the set amount of wait time (hold) is finished, it will be 0 when hold is comeplete.
So in all, OnFadeComplete runs twice.
Required Functions:
FadeInit():
this goes into OnGameModeInit or OnFilterScriptInit
FadeExit():
this goes into OnGameModeExit or OnFilterScriptExit
FadePlayerConnect(playerid):
this goes into OnPlayerConnect
FadePlayerDisconnect(playerid):
this goes into OnPlayerDisconnect, don't forget the playerid parameter
Video
TestFade
Visible Damage
Fading Teleport Transition
Download
J_Fader.INC <--Direct Link
J_Fader_v2.INC <--Direct Link
Example Script
TestFade Command
Type /testfade to see 3 colors fade in and fade out (featured invideo)
pawn Code:
#include <a_samp>
#include <j_fader>
new pFadePlace[MAX_PLAYERS];
public OnFilterScriptInit()
{
FadeInit();
return 1;
}
public OnFilterScriptExit()
{
FadeExit();
return 1;
}
public OnPlayerConnect(playerid)
{
FadePlayerConnect(playerid);
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
FadePlayerDisconnect(playerid);
return 1;
}
public OnPlayerCommandText(playerid,cmdtext[])
{
if(!strcmp(cmdtext[1],"testfade",true))
{
pFadePlace[playerid]=1;
FadeColorForPlayer(playerid,255,0,0,0,255,0,0,255,100,10);//starting at nothing, fading to red
return 1;
}
return 0;
}
public OnFadeComplete(playerid,beforehold)
{
switch(pFadePlace[playerid])
{
case 1:
{
FadeColorForPlayer(playerid,255,0,0,255,0,0,255,255,100,10);//notice how RR,GG,BB,AA 1 is now what 2 was at the start
pFadePlace[playerid]=2;//fading from red to blue
}
case 2:
{
FadeColorForPlayer(playerid,0,0,255,255,0,255,0,255,100,10);//fading from blue to green
pFadePlace[playerid]=3;
}
case 3:
{
FadeColorForPlayer(playerid,0,255,0,255,0,255,0,0,100,10);//Fading back to nothing FROM green
pFadePlace[playerid]=0;//reset the steps
}
}
return 1;
}
Visible damage
This will cause the screen to fade from red to clear based on the amount of damage the player takes. The more damage, the longer it takes to fade out.
--Now it also flashes red when a player's vehicle crashes. Also fades to red when a player dies, and fades back when the player spawns.
pawn Code:
#include <a_samp>
#include <j_fader_v2>
new Float:gTmp;
new Float:pOldHealth[MAX_PLAYERS];
new Float:vSpeed[MAX_PLAYERS];
new Float:gtemp[4]; //global temporary variables
new JustDied[MAX_PLAYERS];
public OnFilterScriptInit()
{
FadeInit();
return 1;
}
public OnFilterScriptExit()
{
FadeExit();
return 1;
}
public OnPlayerConnect(playerid)
{
FadePlayerConnect(playerid);
JustDied[playerid]=0;
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
FadePlayerDisconnect(playerid);
return 1;
}
public OnPlayerDeath(playerid,killerid,reason)
{
FadeColorForPlayer(playerid,255,0,0,0,255,0,0,255,25,1000);
JustDied[playerid]=1;
return 1;
}
public OnPlayerSpawn(playerid)
{
if(JustDied[playerid])
{
FadeColorForPlayer(playerid,255,0,0,255,255,0,0,0,25,0);
JustDied[playerid]=0;
}
return 1;
}
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(newstate==PLAYER_STATE_ONFOOT)vSpeed[playerid]=0;
return 1;
}
public OnPlayerUpdate(playerid)
{
GetPlayerHealth(playerid,gTmp);
if(pOldHealth[playerid]>gTmp)
{
FadeColorForPlayer(playerid,255,0,0,floatround(pOldHealth[playerid]-gTmp)*10,255,0,0,0,floatround(pOldHealth[playerid]-gTmp),0);
}
pOldHealth[playerid]=gTmp;
if(IsPlayerInAnyVehicle(playerid))
{
GetVehicleVelocity(GetPlayerVehicleID(playerid),gtemp[0],gtemp[1],gtemp[2]);
gtemp[3]=floatsqroot( floatmul(gtemp[0],gtemp[0])+floatmul(gtemp[1],gtemp[1])+floatmul(gtemp[2],gtemp[2]) )*100;
if(vSpeed[playerid]-gtemp[3]>20)FadeColorForPlayer(playerid,255,0,0,(floatround(vSpeed[playerid]-gtemp[3])-20)*3,255,0,0,0,floatround(vSpeed[playerid]-gtemp[3])-20,0);
vSpeed[playerid]=gtemp[3];
}
return 1;
}
Fading Teleport Transition
Made this to show off 'beforehold' and because I really wanted to =p
pawn Code:
#include <a_samp>
#include <j_fader>
#define INVALID_DESTINATION 0
#define LOC_LV_CASINO_INT 1
#define LOC_LV_CASINO_EXT 2
new Text3D:gDoors[2];
new pTeleporting[MAX_PLAYERS]; //X,Y,Z,A
public OnFilterScriptInit()
{
FadeInit();
gDoors[0]=Create3DTextLabel("Press F/Return to enter",0xAAAAFFFF,1951.7018,1342.9615,15.3746,25.0,0);
gDoors[1]=Create3DTextLabel("Press F/Return to exit",0xAAAAFFFF,2251.85,-1138.16,1050.63,25.0,0);
return 1;
}
public OnFilterScriptExit()
{
for(new doors;doors<sizeof(gDoors);doors++)Delete3DTextLabel(gDoors[doors]);
FadeExit();
return 1;
}
public OnPlayerConnect(playerid)
{
FadePlayerConnect(playerid);
pTeleporting[playerid]=INVALID_DESTINATION; //Keeps him from teleporting for no reason ;p
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
FadePlayerDisconnect(playerid);
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if( (newkeys & KEY_SECONDARY_ATTACK) && !(oldkeys & KEY_SECONDARY_ATTACK) )
{
if(IsPlayerInRangeOfPoint(playerid,2.0,1951.7018,1342.9615,15.3746)) //LV Casino Suite
{
pTeleporting[playerid]=LOC_LV_CASINO_INT;
FadeColorForPlayer(playerid,0,0,0,0,0,0,0,255,15,0);
return 1;
}
if(IsPlayerInRangeOfPoint(playerid,2.0,2251.85,-1138.16,1050.63))
{
pTeleporting[playerid]=LOC_LV_CASINO_EXT;
FadeColorForPlayer(playerid,0,0,0,0,0,0,0,255,15,0);
return 1;
}
}
return 1;
}
public OnFadeComplete(playerid,beforehold)
{
if(beforehold)
{
switch(pTeleporting[playerid])
{
case LOC_LV_CASINO_INT:
{
FadeColorForPlayer(playerid,0,0,0,255,0,0,0,0,15,0);
SetPlayerPos(playerid,2251.85,-1138.16,1050.63);
SetPlayerInterior(playerid,9);
pTeleporting[playerid]=INVALID_DESTINATION;
}
case LOC_LV_CASINO_EXT:
{
FadeColorForPlayer(playerid,0,0,0,255,0,0,0,0,15,0);
SetPlayerPos(playerid,1951.7018,1342.9615,15.3746);
SetPlayerInterior(playerid,0);
pTeleporting[playerid]=INVALID_DESTINATION;
}
}
}
return 1;
}
Re: [INC]Screen Fader -- Supports color-to-color fades! -
NeRoSiS - 28.01.2010
Amazing! Nice work, i thought Seifs was awesome, and this is just, well, woah xD
Re: [INC]Screen Fader -- Supports color-to-color fades! -
RoamPT - 28.01.2010
It is a good work indeed, but this becomes kinda unnecessary once u press TAB, but as i said good work indeed.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 28.01.2010
Quote:
Originally Posted by RoamPT
It is a good work indeed, but this becomes kinda unnecessary once u press TAB, but as i said good work indeed.
|
True, but it's no different than when a player is blind folded in an RP server. Player's are expecting to go through the ordeal of limited vision, it's what makes the game fun.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
John Rockie - 28.01.2010
Nice INC
Re: [INC]Screen Fader -- Supports color-to-color fades! -
RoamPT - 28.01.2010
Quote:
Originally Posted by Joe Staff
Quote:
Originally Posted by RoamPT
It is a good work indeed, but this becomes kinda unnecessary once u press TAB, but as i said good work indeed.
|
True, but it's no different than when a player is blind folded in an RP server. Player's are expecting to go through the ordeal of limited vision, it's what makes the game fun.
|
What u mention it was what i thought if i would use this, but then we got the other side, the player press TAB and he is no longer blindfolded. We can't prevent it, or can we?
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 28.01.2010
Quote:
Originally Posted by RoamPT
Quote:
Originally Posted by Joe Staff
Quote:
Originally Posted by RoamPT
It is a good work indeed, but this becomes kinda unnecessary once u press TAB, but as i said good work indeed.
|
True, but it's no different than when a player is blind folded in an RP server. Player's are expecting to go through the ordeal of limited vision, it's what makes the game fun.
|
What u mention it was what i thought if i would use this, but then we got the other side, the player press TAB and he is no longer blindfolded. We can't prevent it, or can we?
|
Well in the case of blindfolding, we could just set the player's camera into the sky someplace, but for this there's no work around.
EDIT* I forgot to add the function: StopPlayerFade(playerid). It's not in the pawno list but it still works.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Pinehole - 28.01.2010
Good work.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
robert4049 - 29.01.2010
could you do this when somone dies
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 29.01.2010
Important Note:
Everybody re-download it (assuming you already downloaded it
), I ran into a bug which caused the callback "OnFadeComplete" to be ran continously, this bug is now fixed and a small update has been added.
OnFadeComplete(playerid,beforehold)
beforehold was added. OnFadeComplete will run twice every time now, once for when the fade itself is complete, and once for when the hold time is finished.
beforehold will be '1' for the fade transition completion
it will be '0' for the hold time completion.
StopPlayerFade(playerid) was added into the pawno functions list
FadePlayerConnect(playerid) now has the 'playerid' parameter to adjust for changes forementioned
I added 2 new videos and another script example: Fading Teleport Transitions using the beforehold feature
Quote:
Originally Posted by robert4049
could you do this when somone dies
|
What do you mean? Fade in for when he dies and fade out for when he spawns?
Re: [INC]Screen Fader -- Supports color-to-color fades! -
SPFoxy - 29.01.2010
Looks sexy
Re: [INC]Screen Fader -- Supports color-to-color fades! -
cyber_punk - 29.01.2010
Hmm, I'll give it a shot, Thanks. Maybe I can finally get rid of the odd flashing purple screen bug, that tends to happen with _Seif's.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 29.01.2010
Quote:
Originally Posted by cyber_punk
Hmm, I'll give it a shot, Thanks. Maybe I can finally get rid of the odd flashing purple screen bug, that tends to happen with _Seif's.
|
I did a quite a bit of work to keep colors from freaking out.
Colors can't reach outside of the usual spectrum (o-255)
When the math of 'step' doesn't match out it fixes it, for example:
You want the AA to go from 255 to 0 in 100 steps (roughly 10 seconds)
You would take the initial color and subtract the ending color, so 255-0 = 255
then divide by the steps (255/100)
but in programming this doesn't give 2.55, it gives 2 (always rounds down unless specified otherwise)
This means we'll change the color 100 times and subtract 2 from 255 each time, but this comes up with a remainder (255 -(100*2) = 55)
so what I do is add to the steps how much is left using the same subtractee (2)
Remainder (55) divide by our subtractee (2) is how many steps we're gonna need to add (55/2=27,rounded down)
So now there are 127 steps, not 100
Re: [INC]Screen Fader -- Supports color-to-color fades! -
RyDeR` - 29.01.2010
Nice release, but Seif's I'll keep using Seif's though.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
RenisiL - 29.01.2010
It's very nice
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 08.02.2010
Updated it with version 2.
Only a small change:
SetPlayerPosFade(playerid,steps,interiorid,Float ,Float:y,Float:z); //Version 2 only
This is basically a MIC function. It will fade the player's screen to black, teleport and set interior, then fade from black to clear again for a smooth teleporting transition.
Originally made for ML-RP, but unfortunately was incompatible.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Fedee! - 08.02.2010
Nice INC man!!
Great work
Gotta question, how can I make this:
pawn Code:
#include <a_samp>
#include <j_fader>
new Float:gTmp;
new Float:pOldHealth[MAX_PLAYERS];
public OnFilterScriptInit()
{
FadeInit();
return 1;
}
public OnFilterScriptExit()
{
FadeExit();
return 1;
}
public OnPlayerConnect(playerid)
{
FadePlayerConnect(playerid);
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
FadePlayerDisconnect(playerid);
return 1;
}
public OnPlayerUpdate(playerid)
{
GetPlayerHealth(playerid,gTmp);
if(pOldHealth[playerid]>gTmp)
{
FadeColorForPlayer(playerid,255,0,0,floatround(pOldHealth[playerid]-gTmp)*10,255,0,0,0,floatround(pOldHealth[playerid]-gTmp),0);
}
pOldHealth[playerid]=gTmp;
return 1;
}
to work by crashing the car and when you get killed?
EDIT: Also, how can I make this
pawn Code:
FadeColorForPlayer(playerid,0,0,0,255,0,0,0,0,15,0);
to be first white(clear) and then to fade to black?
Thanks!
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Joe Staff - 09.02.2010
@Fedee:
pawn Code:
#include <a_samp>
#include <j_fader_v2>
new Float:gTmp;
new Float:pOldHealth[MAX_PLAYERS];
new Float:vSpeed[MAX_PLAYERS];
new Float:gtemp[4]; //global temporary variables
new JustDied[MAX_PLAYERS];
public OnFilterScriptInit()
{
FadeInit();
return 1;
}
public OnFilterScriptExit()
{
FadeExit();
return 1;
}
public OnPlayerConnect(playerid)
{
FadePlayerConnect(playerid);
JustDied[playerid]=0;
return 1;
}
public OnPlayerDisconnect(playerid,reason)
{
FadePlayerDisconnect(playerid);
return 1;
}
public OnPlayerDeath(playerid,killerid,reason)
{
FadeColorForPlayer(playerid,255,0,0,0,255,0,0,255,25,1000);
JustDied[playerid]=1;
return 1;
}
public OnPlayerSpawn(playerid)
{
if(JustDied[playerid])
{
FadeColorForPlayer(playerid,255,0,0,255,255,0,0,0,25,0);
JustDied[playerid]=0;
}
return 1;
}
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(newstate==PLAYER_STATE_ONFOOT)vSpeed[playerid]=0;
return 1;
}
public OnPlayerUpdate(playerid)
{
GetPlayerHealth(playerid,gTmp);
if(pOldHealth[playerid]>gTmp)
{
FadeColorForPlayer(playerid,255,0,0,floatround(pOldHealth[playerid]-gTmp)*10,255,0,0,0,floatround(pOldHealth[playerid]-gTmp),0);
}
pOldHealth[playerid]=gTmp;
if(IsPlayerInAnyVehicle(playerid))
{
GetVehicleVelocity(GetPlayerVehicleID(playerid),gtemp[0],gtemp[1],gtemp[2]);
gtemp[3]=floatsqroot( floatmul(gtemp[0],gtemp[0])+floatmul(gtemp[1],gtemp[1])+floatmul(gtemp[2],gtemp[2]) )*100;
if(vSpeed[playerid]-gtemp[3]>20)FadeColorForPlayer(playerid,255,0,0,(floatround(vSpeed[playerid]-gtemp[3])-20)*3,255,0,0,0,floatround(vSpeed[playerid]-gtemp[3])-20,0);
vSpeed[playerid]=gtemp[3];
}
return 1;
}
I haven't tested that, but I will later on. If it works I'll add it to the front page.
Tested and it works great
I even guessed the vehicle speeds correctly, lol.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Fedee! - 09.02.2010
Quote:
Originally Posted by Joe Staff
@Fedee:
pawn Code:
#include <a_samp> #include <j_fader_v2> new Float:gTmp; new Float:pOldHealth[MAX_PLAYERS]; new Float:vSpeed[MAX_PLAYERS]; new Float:gtemp[4]; //global temporary variables new JustDied[MAX_PLAYERS]; public OnFilterScriptInit() { FadeInit(); return 1; } public OnFilterScriptExit() { FadeExit(); return 1; } public OnPlayerConnect(playerid) { FadePlayerConnect(playerid); JustDied[playerid]=0; return 1; } public OnPlayerDisconnect(playerid,reason) { FadePlayerDisconnect(playerid); return 1; } public OnPlayerDeath(playerid,killerid,reason) { FadeColorForPlayer(playerid,255,0,0,0,255,0,0,255,25,1000); JustDied[playerid]=1; return 1; } public OnPlayerSpawn(playerid) { if(JustDied[playerid]) { FadeColorForPlayer(playerid,255,0,0,255,255,0,0,0,25,0); JustDied[playerid]=0; } return 1; } public OnPlayerStateChange(playerid,newstate,oldstate) { if(newstate==PLAYER_STATE_ONFOOT)vSpeed[playerid]=0; return 1; } public OnPlayerUpdate(playerid) { GetPlayerHealth(playerid,gTmp); if(pOldHealth[playerid]>gTmp) { FadeColorForPlayer(playerid,255,0,0,floatround(pOldHealth[playerid]-gTmp)*10,255,0,0,0,floatround(pOldHealth[playerid]-gTmp),0); } pOldHealth[playerid]=gTmp; if(IsPlayerInAnyVehicle(playerid)) { GetVehicleVelocity(GetPlayerVehicleID(playerid),gtemp[0],gtemp[1],gtemp[2]); gtemp[3]=floatsqroot( floatmul(gtemp[0],gtemp[0])+floatmul(gtemp[1],gtemp[1])+floatmul(gtemp[2],gtemp[2]) )*100; if(vSpeed[playerid]-gtemp[3]>20)FadeColorForPlayer(playerid,255,0,0,(floatround(vSpeed[playerid]-gtemp[3])-20)*3,255,0,0,0,floatround(vSpeed[playerid]-gtemp[3])-20,0); vSpeed[playerid]=gtemp[3]; } return 1; }
I haven't tested that, but I will later on. If it works I'll add it to the front page.
Tested and it works great
I even guessed the vehicle speeds correctly, lol.
|
Thanks dude !!
EDIT: Another thing, how can I make if someone puts /home the screens fades to black, and then it clears again fading out?
Thanks !
EDIT2: Nevermind..
SetPlayerPosFade(playerid,steps,interiorid,Float ,Float:y,Float:z) is the same.
Re: [INC]Screen Fader -- Supports color-to-color fades! -
Chaprnks - 09.02.2010
You should use ALS so you don't have to add those functions (ex: FadeInit under OnFilterScript/GameModeInit).