CaptainManiac Posted November 7, 2016 I got a cool idea of screen fading when the health of the player goes below 50%,40%,30% and 10% and when it reaches 0%.I made a script.The problem is:It does not work,but seem to work.Can you help me please?Or just thrash this shit,only saving the code to use it on your stuff.#include "zcommon.acs" script 1 open { if(GetActorProperty(0,APROP_HEALTH) <= 50 && GetActorProperty(0,APROP_HEALTH) > 40) { delay(10); FadeTo(128,128,128,50,0.0); delay(10); } else if(GetActorProperty(0,APROP_HEALTH) <= 40 && GetActorProperty(0,APROP_HEALTH) >30) { 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 && GetActorProperty(0,APROP_HEALTH) > 10) { FadeTo(255,0,0,70,0.0); } else if(GetActorProperty(0,APROP_HEALTH) <= 10 && GetActorProperty(0,APROP_HEALTH) > 1) { 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; } If anyone can help me..thank you so much,otherwise just thrash that to Moronland. :( 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 ACS scripts have a thing called an "Activator". This is basically the person who turned on the script. The activator basically tells the game "Hey, this guy activated the script, but not the other guys", and as a result, it will activate a specific thing JUST for a player, such as Hud messages. (This doesn't apply to everything however. Map related stuff (such as moving the floor and ceiling and such) does not care who activated the script, because it will do it will be changing the map, and as a result it must do it for everyone at the same time). Scripts that are OPEN do not care who the activator is. Try replacing OPEN with ENTER. ENTER scripts are activated when a player joins the game, and because FadeTo NEED to know who activated the script, OPEN will not work. Little trick for knowing when stuff needs an activator is by paying attention to the wiki. For example, GetActorProperty, says:tid: TID of the actor. Use 0 to refer to the activator. https://zdoom.org/wiki/GetActorProperty Also, next time when you make a thread, please try to make a descriptive title. First because an all caps title with no description of the problem makes people not care to come see the thread. Another reason to make a descriptive title is because when people are searching for a problem similar to yours on google, they will find this thread with a solution. But they won't find it if the title of the thread doesn't match what they're looking for. 0 Quote Share this post Link to post
Dragonfly Posted November 7, 2016 I think the issue is your intensity value. I believe it's supposed to have a decimal and vary between 0 and 1. Here's a version of the code I haven't tested, because I'm at work. #include "zcommon.acs" var playerHealth = 100; // Set up playerhealth variable. Used 100 as default. var fadeDecimal == 0.0; // Used to store the expected fade value. Used 0.0 as default. Script 1 OPEN { playerHealth = GetActorProperty(0,APROP_HEALTH); if (playerHealth >= 50) { fadeDecimal = 0.0; } else if(playerHealth >= 40) { fadeDecimal = 0.2; } else if(playerHealth <= 30) { fadeDecimal = 0.4; } else if(playerHealth <= 20) { fadeDecimal = 0.6; } else if(playerHealth <= 10) { fadeDecimal = 0.8; } else { fadeDecimal = 1.0; } FadeTo(128,128,128,fadeDecimal,0.1); delay(1); restart; } 0 Quote Share this post Link to post
CaptainManiac Posted November 7, 2016 Uhm,i need the fade to be red when the health fall below 40,thnaks for the help,i will try to use your suggestions Dragonfly said:I think the issue is your intensity value. I believe it's supposed to have a decimal and vary between 0 and 1. Here's a version of the code I haven't tested, because I'm at work. #include "zcommon.acs" var playerHealth = 100; // Set up playerhealth variable. Used 100 as default. var fadeDecimal == 0.0; // Used to store the expected fade value. Used 0.0 as default. Script 1 OPEN { playerHealth = GetActorProperty(0,APROP_HEALTH); if (playerHealth >= 50) { fadeDecimal = 0.0; } else if(playerHealth >= 40) { fadeDecimal = 0.2; } else if(playerHealth <= 30) { fadeDecimal = 0.4; } else if(playerHealth <= 20) { fadeDecimal = 0.6; } else if(playerHealth <= 10) { fadeDecimal = 0.8; } else { fadeDecimal = 1.0; } FadeTo(128,128,128,fadeDecimal,0.1); delay(1); restart; } when i add those vars before the script it gives a error on line 2 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 CaptainManiac said:when i add those vars before the script it gives a error on line 2 Can you post the error next time? It helps us figure stuff out. The issue is Dragonfly is initializing variables without stating what they are. So a fix would be:var int playerHealth = 100; // Set up playerhealth variable. Used 100 as default. var int fadeDecimal == 0.0; // Used to store the expected fade value. Used 0.0 as default. I MIGHT BE WRONG IN THIS NEXT PART, BECAUSE THE WIKI IS CONFUSING, SO PLEASE CORRECT ME IF SO However, the code DragonFly whipped up wont work as fadeDecimal has decimals, and AFAIK ZDoom's ACS does not support floats inside of variables defined as an integer. You'll need to use: https://zdoom.org/wiki/FixedDiv Regardless, he is correct about the decimals. FadeTo needs the intensity to be a number between 1 and 0. Also, did you try my suggestion of using your original code but changing the word OPEN to ENTER? The script DragonFly posted has the exact same problem. 0 Quote Share this post Link to post
Arctangent Posted November 7, 2016 y'just have to use int and such "var" doesn't actually exist in ACS I don't think 0 Quote Share this post Link to post
CaptainManiac Posted November 7, 2016 Under any of those circumstances it shows me invalid declarator error 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 CaptainManiac said:Under any of those circumstances it shows me invalid declarator error Line? 0 Quote Share this post Link to post
scifista42 Posted November 7, 2016 There should be a = instead of == in the declaration. 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 scifista42 said:There should be a = instead of == in the declaration. Good eye, didn't notice it (happens a lot actually) 0 Quote Share this post Link to post
MaxED Posted November 7, 2016 else if(playerHealth <= 30) { fadeDecimal = 0.4; } else if(playerHealth <= 20) { fadeDecimal = 0.6; } else if(playerHealth <= 10) { fadeDecimal = 0.8; }This won't do what you want it to do, (because playerHealth <= 30 is true when health is, say, 8). 0 Quote Share this post Link to post
CaptainManiac Posted November 7, 2016 int playerhealth = 100; float fadeDecimal = 0.0; that now gives me the invalid declarator errors.Line 3 and 4 on original code 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 Float doesn't exist as a variable declarator as I explained in my post above. Also you still need the word var. I actually figured a way to get around the fact that we need decimals. We simply multiply the numbers by 10 when storing them and divide by 10 when using them. #include "zcommon.acs" var int playerHealth = 100; // Set up playerhealth variable. Used 100 as default. var int fadeDecimal = 0.0; // Used to store the expected fade value. Used 0.0 as default. Script 1 ENTER { playerHealth = GetActorProperty(0,APROP_HEALTH); if (playerHealth > 50) { fadeDecimal = 0.0; } else if(playerHealth < 50 && playerHealth >= 40) { fadeDecimal = 1.0; } else if(playerHealth < 40 && playerHealth >= 30) { fadeDecimal = 2.0; } else if(playerHealth < 30 && playerHealth >= 20) { fadeDecimal = 4.0; } else if(playerHealth < 20 && playerHealth >= 10) { fadeDecimal = 6.0; } else if(playerHealth < 10 && playerHealth >= 0) { fadeDecimal = 8.0; } else { fadeDecimal = 10.0; } FadeTo(128,128,128,fadeDecimal/10,0.1); delay(1); restart; } This should work. 0 Quote Share this post Link to post
MaxED Posted November 7, 2016 And here's the version, which: 1. Doesn't require global variables. 2. Doesn't do unneeded health checks. 3. Doesn't require unneeded division by 10. #include "zcommon.acs" script 1 ENTER { int health, fade; while (true) { health = GetActorProperty(0, APROP_HEALTH); if (health > 50) { fade = 0.0; } else if(health >= 40) { fade = 0.1; } else if(health >= 30) { fade = 0.2; } else if(health >= 20) { fade = 0.4; } else if(health >= 10) { fade = 0.5; } else if(health > 0) { fade = 0.8; } else { fade = 1.0; } FadeTo(255, 0, 0, fade, 0.1); delay(1); } } 0 Quote Share this post Link to post
Buu342 Posted November 7, 2016 MaxED said:And here's the version, which: 1. Doesn't require global variables. 2. Doesn't do unneeded health checks. 3. Doesn't require unneeded division by 10. -snip- Ahh, only now did I realize those variables weren't needed. That does make it much better. Out of curiosity, doesn't that end up by changing the fade constantly without the extra health checks? 0 Quote Share this post Link to post
Empyre Posted November 7, 2016 I don't know acs, but if you declare fade to be an int, how can you assign 0.1 to it? 0 Quote Share this post Link to post
MaxED Posted November 8, 2016 Buu342 said:Out of curiosity, doesn't that end up by changing the fade constantly without the extra health checks?It doesn't, because only a single branch of "if... else if..." chain is executed. Empyre said:I don't know acs, but if you declare fade to be an int, how can you assign 0.1 to it?Because acs supports several primitive data types (int, fixed and string), but doesn't support data type declarations / type conversion operators for them.#include "zcommon.acs" script 1 ENTER { int hello = "OW HELLO!"; PrintBold(s:hello); } 0 Quote Share this post Link to post
Dragonfly Posted November 8, 2016 Sorry for the errors, was at work and couldn't test, heh. Mixing up javascript with ACS a little, hence the use of "var". The other errors aren't excusable aside from the lack of test-ability. Looking at the posts quickly, MaxEd has done what I meant to do, that should work just fine. 0 Quote Share this post Link to post
Edward850 Posted November 8, 2016 MaxED said:Because acs supports several primitive data types (int, fixed and string), but doesn't support data type declarations / type conversion operators for them. Actually not even that. ACS only understands a single primitive type, 32bit signed integers, and has no other data type. Hence why int hello = "OW HELLO!"; works, because "OW HELLO!" is also a 32bit integer (the index of that string). Meanwhile fixed types work as fixed is already a 32bit int anyway. ACC will convert 0.1 to its real fixed equivalent on compile time (0.1 == 0.1*65536 == 6554 == 6554/65536 == 0.100006103515625). Hence why you have to remember to bitshift or fixedmul where necessary. In short, str and bool aren't real types to ACC, only aliases of int. 0 Quote Share this post Link to post
scifista42 Posted November 8, 2016 Empyre said:I don't know acs, but if you declare fade to be an int, how can you assign 0.1 to it? http://zdoom.org/wiki/Data_types#Fixed_point 0 Quote Share this post Link to post
CaptainManiac Posted November 8, 2016 Thank you very much for the help. 0 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.