28.01.2010, 19:47
(
Last edited by Joe Staff; 04/04/2013 at 06:14 PM.
)
I saw _Seif's "Seifader" HERE and how it was limited in a few aspects.
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)
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.
Fading Teleport Transition
Made this to show off 'beforehold' and because I really wanted to =p
- 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!
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;
}
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;
}
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;
}