SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 28/01/2010, 08:47 PM   #1
Joe Staff
High-roller
 
Joe Staff's Avatar
 
Join Date: Aug 2007
Posts: 2,567
Reputation: 377
Default [INC]Screen Fader -- Supports color-to-color fades!

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;
}
__________________
Big bottom girls make this rockin' world go 'round.

Last edited by Joe Staff; 04/04/2013 at 07:14 PM.
Joe Staff is offline   Reply With Quote
Old 28/01/2010, 08:53 PM   #2
NeRoSiS
Gangsta
 
Join Date: Feb 2008
Posts: 555
Reputation: 3
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

Amazing! Nice work, i thought Seifs was awesome, and this is just, well, woah xD
NeRoSiS is offline   Reply With Quote
Old 28/01/2010, 09:10 PM   #3
RoamPT
High-roller
 
RoamPT's Avatar
 
Join Date: Nov 2007
Location: Toronto, Canada
Posts: 1,110
Reputation: 26
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

It is a good work indeed, but this becomes kinda unnecessary once u press TAB, but as i said good work indeed.
__________________
RoamPT is offline   Reply With Quote
Old 28/01/2010, 10:00 PM   #4
Joe Staff
High-roller
 
Joe Staff's Avatar
 
Join Date: Aug 2007
Posts: 2,567
Reputation: 377
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

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.
__________________
Big bottom girls make this rockin' world go 'round.
Joe Staff is offline   Reply With Quote
Old 28/01/2010, 10:04 PM   #5
John Rockie
Huge Clucker
 
Join Date: Dec 2009
Posts: 319
Reputation: 20
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

Nice INC
John Rockie is offline   Reply With Quote
Old 28/01/2010, 10:17 PM   #6
RoamPT
High-roller
 
RoamPT's Avatar
 
Join Date: Nov 2007
Location: Toronto, Canada
Posts: 1,110
Reputation: 26
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

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?
__________________
RoamPT is offline   Reply With Quote
Old 28/01/2010, 10:24 PM   #7
Joe Staff
High-roller
 
Joe Staff's Avatar
 
Join Date: Aug 2007
Posts: 2,567
Reputation: 377
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

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.
__________________
Big bottom girls make this rockin' world go 'round.
Joe Staff is offline   Reply With Quote
Old 28/01/2010, 10:32 PM   #8
Pinehole
Big Clucker
 
Pinehole's Avatar
 
Join Date: Sep 2009
Posts: 116
Reputation: 3
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

Good work.
Pinehole is offline   Reply With Quote
Old 29/01/2010, 04:09 AM   #9
robert4049
Huge Clucker
 
Join Date: Apr 2008
Posts: 265
Reputation: -3
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

could you do this when somone dies
__________________
robert4049 is offline   Reply With Quote
Old 29/01/2010, 06:13 AM   #10
Joe Staff
High-roller
 
Joe Staff's Avatar
 
Join Date: Aug 2007
Posts: 2,567
Reputation: 377
Default Re: [INC]Screen Fader -- Supports color-to-color fades!

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?
__________________
Big bottom girls make this rockin' world go 'round.
Joe Staff is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] [INC] Color Inlcude (Most used color defines in one include!) (New Link) Oxside Includes 19 14/05/2014 06:42 PM
[FilterScript] [FS] Color screen v1+2 (could be used for a drug effect on RP servers) Correlli Filterscripts 32 16/10/2010 11:39 PM
color/car-color/weapon Defines BurningSWA Help Archive 1 13/02/2010 01:39 PM


All times are GMT. The time now is 01:34 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.