Bleeding Player (Help Needed Fast,if possible)

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 5:07 pm

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.

Image

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Bleeding Player (Help Needed Fast,if possible)

Post by Juutis » Wed Oct 15, 2008 5:41 pm

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.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 6:14 pm

thanks,but as alway I got some questions :D . What's that "redtime" ?

Code: Select all

if(redtime < self.time)
it should be a variable,right,but for what?

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Bleeding Player (Help Needed Fast,if possible)

Post by Juutis » Wed Oct 15, 2008 6:31 pm

It's a variable for the timer that reduces the transparency. Every 0.05 seconds it reduces the transparency of the red by 5.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 6:38 pm

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?
Last edited by metal_head on Wed Oct 15, 2008 7:41 pm, edited 1 time in total.

User avatar
bernie
RF Moderator
Posts: 1249
Joined: Tue Nov 15, 2005 10:07 am
Location: Ireland

Re: Bleeding Player (Help Needed Fast,if possible)

Post by bernie » Wed Oct 15, 2008 7:15 pm

A script must start with { and end with }

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 7:40 pm

oh,that's just a copy/paste mistake,sorry I'll fix the post above. So it's not because of a { or }.

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Bleeding Player (Help Needed Fast,if possible)

Post by Juutis » Wed Oct 15, 2008 8:04 pm

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. :D
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 8:12 pm

I though I've done this with:

Code: Select all

if(GetAttribute("health","Player") < lasthealth)
Oh,I still got a lot to learn.

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Bleeding Player (Help Needed Fast,if possible)

Post by Juutis » Wed Oct 15, 2008 8:19 pm

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.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Bleeding Player (Help Needed Fast,if possible)

Post by metal_head » Wed Oct 15, 2008 8:30 pm

I see...well,it's going to take time till I understand and remember all theese :D 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!

Post Reply