Page 1 of 1
Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 5:07 pm
by metal_head
I know I can make this using a flipbook entity or something,but it doesn't really look well in the game.I'm talking abaout when the player gets hit by a projectile or something (when the player's health attribute decreases) the screen to go red.OK,this can be done with a flipbook and a script,but I want it to be a little more complicated.this thing exists in nirhis demo,but I couldn't figure out how it works and what is it.When the player's health decreases with for example 5,the screen goes red,but just a little red (I'm talking about the transparency of the red) and then the red screen smoothly dissapears,but if the player''s health decreases by 30,the transparency of the red will get smaller and the screen will go totally red...I don't really know how to explain this,I just hope that you've all played the nirhis demo and know what I'm talking about.
I don't know about a command for transparency and couldn't find nothing in the manual (if there is,I've missed it) can someone please help,that's important for the demo release.

Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 5:41 pm
by Juutis
In Nirhis it's done with the FillScreenArea command:
FillScreenArea(int Area#, bool KeepVisible, float Alpha);
FillScreenArea(int Area#, bool KeepVisible, float Alpha, float R, float G, float B);
FillScreenArea(int Area#, bool KeepVisible, float Alpha, float R, float G, float B, int Left, int Top, int Right, int Bottom);
Fills a rectangle on the screen with a color and an alpha
Area# is a number between 0 and 19 that is used to distinguish between different FillScreenArea commands within one order.
KeepVisible keeps the rectangle processed and visible independent of the selected ThinkTime
Alpha defines the transparency of the filled rectangle (0 is fully transparent, 255 is fully solid)
R, G, B define the color to be used to fill the rectangle. Default color is black (0, 0, 0).
Left, Top, Right, Bottom define the rectangle in screen coordinates to be filled. If not specified, the full screen will be filled
It's basically a red transparent rectangle which covers the whole screen.
If you take a look at the player script (player.s) you'll find this in the damage() method.
Code: Select all
if(screenred > 0)
{
FillScreenArea(1,true,screenred,255,0,0);
if(redtime < self.time)
{
screenred = screenred - 5;
redtime = self.time + 0.05;
}
}
else
{
RemoveScreenArea(1);
}
Where 'screenred' is a variable holding the amount of "red" drawn on the screen. In other words, the transparency. The variable itself is calculated with the line
Code: Select all
screenred = screenred + lastdamage*4;
Where 'lastdamage' is the amount of damage the player last received.
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 6:14 pm
by metal_head
thanks,but as alway I got some questions

. What's that "redtime" ?
it should be a variable,right,but for what?
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 6:31 pm
by Juutis
It's a variable for the timer that reduces the transparency. Every 0.05 seconds it reduces the transparency of the red by 5.
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 6:38 pm
by metal_head
OK,so this is what I made,and as always it doesn't work

...man I can't wait for the day when I'll make something MYSELF with no help and it will work.
Code: Select all
{
screenred [0]
redtime [0]
lasthealth [0]
Spawn[ ()
{
Console(true);
LowLevel("execute");
} ]
execute[ ()
{
if(GetAttribute("health","Player") < lasthealth)
{
FillScreenArea(1,true,screenred,255,0,0);
if(redtime < self.time)
{
screenred = screenred - 10;
redtime = self.time + 0.05;
}
}
else
{
RemoveScreenArea(1);
}
} ]
}
I don't see any missed "{ }"..so maybe it's a whole missed command or more,but shouldn't that be working?
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 7:15 pm
by bernie
A script must start with { and end with }
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 7:40 pm
by metal_head
oh,that's just a copy/paste mistake,sorry I'll fix the post above. So it's not because of a { or }.
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 8:04 pm
by Juutis
Note that what I posted above is not the full script. That just draws the red rectangle on the screen. You still have to check if the player is damaged. Try something like:
Code: Select all
execute[ ()
{
if(GetAttribute("health","Player") != lasthealth)
{
if(GetAttribute("health","Player") < lasthealth)
{
screenred = screenred + (lasthealth - GetAttribute("health","Player"))*4;
}
lasthealth = GetAttribute("health","Player");
}
if(screenred > 0)
{
FillScreenArea(1,true,screenred,255,0,0);
if(redtime < self.time)
{
screenred = screenred - 10;
redtime = self.time + 0.05;
}
}
else
{
RemoveScreenArea(1);
}
} ]
***EDIT***
Oh, you're a moderator bernie? I never realized. When did you become one?
Congrats, no matter how late I am.

Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 8:12 pm
by metal_head
I though I've done this with:
Code: Select all
if(GetAttribute("health","Player") < lasthealth)
Oh,I still got a lot to learn.
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 8:19 pm
by Juutis
All that does is it checks if the player's attribute 'health' is smaller than the script's variable 'lasthealth'. In the beginning of the script you set 'lasthealth' to 0 and never change it. This leads to player's health being always larger than the 'lasthealth' variable (unless the player is dead). And so your if-statement is always false. In other words the stuff inside the if-block is never executed.
Re: Bleeding Player (Help Needed Fast,if possible)
Posted: Wed Oct 15, 2008 8:30 pm
by metal_head
I see...well,it's going to take time till I understand and remember all theese

But I won't give up,in school were are starting to learn the structure of programming and I think all theese things we'll get a lot much clearer for me,just a matter of time and hard work!