[Help] Low health fade/blood splatter effect
- CaptainManiac
- Topic Author
- Cacodemon
Less
More
- Posts: 103
8 years 1 month ago - 8 years 1 month ago #1
by CaptainManiac
[Help] Low health fade/blood splatter effect was created by CaptainManiac
Hi.Sorry for my childish questioning.To be honest,i tried to make a script that fades screen when player's health lowers.I tried the script in game and it does not work.I do not make it for a project i am working on.Sorry about asking for help here.
Here is my shame:
Now prepare to laugh on this,because it does not work
Here is my shame:
Code:
#include "zcommon.acs"
script 1 open
{
if(GetActorProperty(0,APROP_HEALTH) <= 50)
{
delay(10);
FadeTo(128,128,128,50,0.0);
delay(10);
}
else if(GetActorProperty(0,APROP_HEALTH) <= 40)
{
SetHudSize(1024,768,0);
Setfont("bldscrnt");
delay(10);
FadeTo(128,128,128,50,0.0);
delay(10);
HudMessageBold(s:"A";HUDMSG_FADEINOUT,0,CR_WHITE,512.0,384.0,0.0);
delay(10);
}
else if(GetActorProperty(0,APROP_HEALTH) <= 30)
{
FadeTo(255,0,0,70,0.0);
}
else if(GetActorProperty(0,APROP_HEALTH) <= 10)
{
delay(10);
FadeTo(255,0,0,80,0.0);
delay(10);
}
else if(GetActorProperty(0,APROP_HEALTH) <= 1|GetActorProperty(0,APROP_HEALTH) == 0)
{
delay(10);
FadeTo(255,0,0,90,0.0);
delay(10);
}
delay(10);
restart;
}
Last edit: 8 years 1 month ago by Blue Shadow. Reason: Changed title to be more descriptive.
Please Log in or Create an account to join the conversation.
- CaptainManiac
- Topic Author
- Cacodemon
Less
More
- Posts: 103
8 years 1 month ago #2
by CaptainManiac
Replied by CaptainManiac on topic My childish questioning again....
Huh,if you do not care about that please thrash it to the edge of chaos and copy only the code.I hope that this code will make some use for one of your projects.
Please Log in or Create an account to join the conversation.
- MagicWazard
- Moderator
Less
More
- Posts: 808
8 years 1 month ago #3
by MagicWazard
Replied by MagicWazard on topic My childish questioning again....
Well, for starters, you don't need to be so hard on yourself or your efforts. Every one of us gets stuck on something from time to time.
As far as the code, I won't have a chance to look at it right away, but someone might. Don't write it off as a waste of time just yet.
As far as the code, I won't have a chance to look at it right away, but someone might. Don't write it off as a waste of time just yet.
Please Log in or Create an account to join the conversation.
- BadMojo
- Wicked
Less
More
- Posts: 224
8 years 1 month ago - 8 years 1 month ago #4
by BadMojo
Replied by BadMojo on topic My childish questioning again....
We all make mistakes, its how we learn
But anyway, Ive messed around with your script and noticed a few things.
Here is what Ive done:
I kind of just rewritten the whole thing, theres a few things missing from the one you posted but you can add them in later.
Firstly, for the intensity value in FadeTo, it should be a float otherwise it wont work, that was the main issue.
The second thing that wasnt working was the TID for GetActorProperty. Basically you just need to assign the player thing to a TID, so Ive set it so that player 1's TID is 1000, player 2'2 TID is 1001 etc...
Then to simplify the whole thing, I just created an int called P_Health to contain the value of APROP_Health... It just makes everything neat and tidy.
I removed all of the delays and just set a 1 tick delay right at the end before the loop.
Oh and lastly, I started the script with ENTER not OPEN, so that it start when the player enters the map rather than when the map starts.
But anyway, Ive messed around with your script and noticed a few things.
Here is what Ive done:
Code:
#include "zcommon.acs"
script 1 ENTER
{
Thing_ChangeTID(0, 1000 + PlayerNumber()); //Assign the player a TID
int P_Health = GetActorProperty(1000, APROP_HEALTH); /*A variable containing the value of APROP_HEALTH
(it just simplifies the code and makes it easier to read))*/
if(P_Health >= 51) /* This is so the game knows what to do at more than 50 health,
without this, it will fade as if its 50 health the moment the script runs.. its also good to have a default point for over 50 hp*/
{
FadeTo(0,0,0,0.0,1.0); //Changed the intensity value to a floating point, and gave it a 1 second fade time
}
else if(P_Health <= 50)
{
FadeTo(128,128,128,0.5,1.0);
}
else if(P_Health <= 40)
{
FadeTo(128,128,128,0.6,0.0);
}
else if(P_Health <= 30)
{
FadeTo(255,0,0,0.7,0.0);
}
else if(P_Health <= 10)
{
FadeTo(255,0,0,0.8,0.0);
}
else if(P_Health <= 1)
{
FadeTo(255,0,0,0.9,0.0);
}
delay(1);
restart;
}
I kind of just rewritten the whole thing, theres a few things missing from the one you posted but you can add them in later.
Firstly, for the intensity value in FadeTo, it should be a float otherwise it wont work, that was the main issue.
The second thing that wasnt working was the TID for GetActorProperty. Basically you just need to assign the player thing to a TID, so Ive set it so that player 1's TID is 1000, player 2'2 TID is 1001 etc...
Then to simplify the whole thing, I just created an int called P_Health to contain the value of APROP_Health... It just makes everything neat and tidy.
I removed all of the delays and just set a 1 tick delay right at the end before the loop.
Oh and lastly, I started the script with ENTER not OPEN, so that it start when the player enters the map rather than when the map starts.
Last edit: 8 years 1 month ago by BadMojo.
Please Log in or Create an account to join the conversation.
- CaptainManiac
- Topic Author
- Cacodemon
Less
More
- Posts: 103
8 years 1 month ago #5
by CaptainManiac
Replied by CaptainManiac on topic My childish questioning again....
Thank you,BadMojo.I have changed the script but something is still nto achieved:on health below 40 an image was supposed to be drawn on the screen(used the HudMessageBold and set the font to the name of my picture lump,but it does not show(the image's size is 1024:1024 and the hudsize was set to 1024:768 and the image was meant to be displayed on the centre of the screen.It does not show up.I will try to repair that alone,but any help will be appreciated
Please Log in or Create an account to join the conversation.
- CaptainManiac
- Topic Author
- Cacodemon
Less
More
- Posts: 103
8 years 1 month ago #6
by CaptainManiac
Replied by CaptainManiac on topic My childish questioning again....
Unfortunately,i have no idea why the image is not printed on the screen using the hudmessage command
Please Log in or Create an account to join the conversation.
- BadMojo
- Wicked
Less
More
- Posts: 224
8 years 1 month ago - 8 years 1 month ago #7
by BadMojo
Replied by BadMojo on topic My childish questioning again....
Can you provide me a sample of the code you wrote?
Ill see what I can do from what I sent you already in terms of displaying an image on the screen... Whilst playing with the code you sent earlier though, I noticed there was the letter 'a' in the middle of the crosshair, so that worked at least.. But Ill mess around with it anyway and see what I can do to help
Ill see what I can do from what I sent you already in terms of displaying an image on the screen... Whilst playing with the code you sent earlier though, I noticed there was the letter 'a' in the middle of the crosshair, so that worked at least.. But Ill mess around with it anyway and see what I can do to help
Last edit: 8 years 1 month ago by BadMojo.
Please Log in or Create an account to join the conversation.
- CaptainManiac
- Topic Author
- Cacodemon
Less
More
- Posts: 103
8 years 1 month ago #8
by CaptainManiac
Replied by CaptainManiac on topic My childish questioning again....
Ok,i will send you the code,this time the picture shows,but on the top of the screen,not on the centre.Here is the code:
The Image is called M_BLUD and is 512:512(the 1024:1024 resolution was problem what prevents it from viewing) and i resized it to 512:512.Offsets are Graphic and HUd/Weapon(Doom)
Code:
#include "zcommon.acs"
script 1 enter
{
int fadeDecimal = 0.0; //The decimal of the fade
int phealth = GetActorProperty(0,APROP_HEALTH); //the health point goes here
if(phealth <= 50 && phealth > 40)
{
fadeDecimal = 0.2;
delay(10);
FadeTo(128,128,128,fadeDecimal,1.0); //below 50:fades to 20% grey
delay(10);
}
else if(phealth <= 40 && phealth >30)
{
fadeDecimal = 0.3;
FadeTo(128,128,128,fadeDecimal,1.0); //below 40:fades to 30% grey and...
SetHudSize(1024,768,0);
Setfont("M_BLUD");
delay(10);
HudMessage(s:"A";HUDMSG_PLAIN,0,CR_UNTRANSLATED,512.0,420.0,1.0);//..draws an blood on screen image
delay(10);
}
else if(phealth <=20 && phealth >10)
{
fadeDecimal = 0.6;
FadeTo(255,0,0,fadeDecimal,1.0); //below 20:60% red fading
}
else if(phealth <= 30 && phealth > 20)
{
fadeDecimal = 0.4;
FadeTo(255,0,0,fadeDecimal,1.0); //below 30:40% red fading
}
else if(phealth <= 10 && phealth > 1)
{
fadeDecimal = 0.8;
delay(10);
FadeTo(255,0,0,fadeDecimal,1.0); //below 10%:a 80% fading(you see hard)
delay(10);
}
else if(phealth <= 1|phealth == 0)
{
fadeDecimal = 0.9;
delay(10);
FadeTo(255,0,0,fadeDecimal,1.0); //90% fade on death
delay(10);
}
else
{
fadeDecimal = 0.0;
FadeTo(255,255,255,fadeDecimal,1.0); //resets everything when the above condtions are not met
}
delay(10);
restart;
}
Please Log in or Create an account to join the conversation.
- BadMojo
- Wicked
Less
More
- Posts: 224
8 years 1 month ago #9
by BadMojo
Replied by BadMojo on topic My childish questioning again....
After looking at your old code, theres a problem with the way your setting the fixed X and Y positions of the in conjunction with the SetHudSize. Try this line instead of the one you have already:
It should place the 1024x1024 image you have in the center of the screen... if you cant see the image still, its probably because the way you have that image nested in, what I'm assuming is your WAD?.. It doesnt work if its between the F_START and END lumps, I can only assume it wont work between the sprite and the other lumps that tell the game what type of image it is.. so just have it outside of any of those and you should be right. If your using a pk3, then the graphics folder should be fine.
The other problem that I noticed, is that so long as your health is 40 or below, it will keep the image on screen until health goes above 40 again.. rather than fade it out after the 3.7 seconds, like the way you have it set to in your first post.. Im not sure if this is intentional or not but to remedy that, it might be a good idea to set a couple of int's or bool's, to check in an if statement, when health has gone below 40 and when it goes back up again, so that it doesnt constantly loop the HudMessage image, and just does it once and fades it out... If that makes any sense at all
Edit: Heh, I was in the process of typing all of that above in an edited post.... but you replied in the process so I didnt see it until now... but anyway it should still apply to the code you have now
Code:
HudMessageBold(s:"A"; HUDMSG_FADEINOUT, 0, CR_WHITE, 0.5, -0.5, 3.7);
It should place the 1024x1024 image you have in the center of the screen... if you cant see the image still, its probably because the way you have that image nested in, what I'm assuming is your WAD?.. It doesnt work if its between the F_START and END lumps, I can only assume it wont work between the sprite and the other lumps that tell the game what type of image it is.. so just have it outside of any of those and you should be right. If your using a pk3, then the graphics folder should be fine.
The other problem that I noticed, is that so long as your health is 40 or below, it will keep the image on screen until health goes above 40 again.. rather than fade it out after the 3.7 seconds, like the way you have it set to in your first post.. Im not sure if this is intentional or not but to remedy that, it might be a good idea to set a couple of int's or bool's, to check in an if statement, when health has gone below 40 and when it goes back up again, so that it doesnt constantly loop the HudMessage image, and just does it once and fades it out... If that makes any sense at all
Edit: Heh, I was in the process of typing all of that above in an edited post.... but you replied in the process so I didnt see it until now... but anyway it should still apply to the code you have now
Please Log in or Create an account to join the conversation.
- BadMojo
- Wicked
Less
More
- Posts: 224
8 years 1 month ago - 8 years 1 month ago #10
by BadMojo
Replied by BadMojo on topic My childish questioning again....
Paste this in, Ive commented what I done but essentially its what I ment about the bool that checks if health goes back above a set point... and also, your new fadeDecimal int seems to just be a waste of characters, especially if you have to type it out to equal something new everytime.. just seems like unnecessary clutter to me... phealth is ok because it shortens what you need to type significantly considering it needs to be typed a few times.
UPDATE:
Code:
#include "zcommon.acs"
script 1 enter
{
int fadeDecimal = 0.0; //The decimal of the fade.... This probably isnt going to help at all, it just makes more lines of code to write :)
int phealth = GetActorProperty(0,APROP_HEALTH); //the health point goes here
bool foo; //this is to check if health has already reached 40
if(phealth <= 50 && phealth > 40)
{
foo = FALSE; //set foo to FALSE, always runs when health is above 40
fadeDecimal = 0.2;
delay(10);
FadeTo(128,128,128,fadeDecimal,1.0); //below 50:fades to 20% grey
delay(10);
}
else if(phealth <= 40 && phealth >30)
{
if(!foo) // if foo is FALSE
{
foo=TRUE; // Then set foo to TRUE, run all of this code and dont run again until hp goes above 40
fadeDecimal = 0.3;
FadeTo(128,128,128,fadeDecimal,1.0); //below 40:fades to 30% grey and...
SetHudSize(1024,768,0);
Setfont("UNTITLED");
delay(10);
HudMessage(s:"A";HUDMSG_PLAIN,0,CR_WHITE, 0.5,-0.5,1.0);//..draws an blood on screen image
delay(10);
}
}
else if(phealth <=20 && phealth >10)
{
fadeDecimal = 0.6;
FadeTo(255,0,0,fadeDecimal,1.0); //below 20:60% red fading
}
else if(phealth <= 30 && phealth > 20)
{
fadeDecimal = 0.4;
FadeTo(255,0,0,fadeDecimal,1.0); //below 30:40% red fading
}
else if(phealth <= 10 && phealth > 1)
{
fadeDecimal = 0.8;
delay(10);
FadeTo(255,0,0,fadeDecimal,1.0); //below 10%:a 80% fading(you see hard)
delay(10);
}
else if(phealth <= 1|phealth == 0)
{
fadeDecimal = 0.9;
delay(10);
FadeTo(255,0,0,fadeDecimal,1.0); //90% fade on death
delay(10);
}
else
{
fadeDecimal = 0.0;
FadeTo(255,255,255,fadeDecimal,1.0); //resets everything when the above condtions are not met
}
delay(10);
restart;
}
UPDATE:
Warning: Spoiler!
Heres a simplified, more responsive version of what I did... those 10 tick delays you had are a bit much, were not doing any cpu or gpu intensive stuff here, so a simple 1 tick delay at the end before restart should be fine
Code:
#include "zcommon.acs"
script 1 enter
{
int phealth = GetActorProperty(0,APROP_HEALTH); //the health point goes here
bool foo; //this is to check if health has already reached 40
if(phealth > 49) //always make sure foo is FALSE if 50 or more hp
foo=FALSE;
if(phealth >= 41 && phealth < 51)
{
FadeTo(128,128,128,0.2,1.0); //below 50:fades to 20% grey
}
else if(phealth <= 40)
{
if(!foo) // if foo is FALSE
{
SetHudSize(1024,768,0);
Setfont("UNTITLED");
HudMessage(s:"A";HUDMSG_FADEINOUT,0,CR_RED, 0.5,-0.5,1.0, 1.0, 5.0);//..draws an blood on screen image
foo=TRUE; // Then set foo to TRUE, run all of this code and dont run again until hp goes above 40
}
FadeTo(128,128,128,0.3,1.0); //below 40:fades to 30% grey and...
}
else if(phealth <=20)
{
FadeTo(255,0,0,0.6,1.0); //below 20:60% red fading
}
else if(phealth <= 30)
{
FadeTo(255,0,0,0.4,1.0); //below 30:40% red fading
}
else if(phealth <= 10)
{
FadeTo(255,0,0,0.8,1.0); //below 10%:a 80% fading(you see hard)
}
else if(phealth <= 1|phealth == 0)
{
FadeTo(255,0,0,0.9,1.0); //90% fade on death
}
else
{
FadeTo(255,255,255,0.0,1.0); //resets everything when the above condtions are not met
}
delay(1);
restart;
}
Last edit: 8 years 1 month ago by BadMojo.
Please Log in or Create an account to join the conversation.