UGX-Mods

Call of Duty 5: World at War => Downloadable Items for Mappers => Custom Maps, Mods & Tools => Scripts => Topic started by: alaurenc9 on July 27, 2015, 12:47:10 am

Title: Scrolling Fullscreen Overlay Hud
Post by: alaurenc9 on July 27, 2015, 12:47:10 am
Hey guys, today I have something I guess is cool
and worth posting. This is something I needed for my
mod so I spent like 3 hours scripting and testing it,
and since it's not a big deal I might as well show
people because I find it to have benefits, even though
alot of people are probably not gonna give two shits
about this post. Anyway here it is,

Fullscreen Overlay HUD

Basically this allows you to have an overlay on your screen,
scrolling up or down it at a speed you choose. I needed this
especially for Vulture Aid, and I thought I could release it
and see what other people could use it for.

Copy this code and call it _xS78_overlay.gsc:

Code Snippet
Plaintext
#include maps\_utility;
#include common_scripts\utility;
#include maps\_zombiemode_utility;

apply_scrolling_overlay( shader, priority, scroll_time, alpha, direction )
{
self endon( "disconnect" );
if( !IsDefined( self.scrolling_overlay_list ) )
{
self.scrolling_overlay_list = [];
}
already_in_array = false;
for( i = 0; i < self.scrolling_overlay_list.size; i++ )
{
if( self.scrolling_overlay_list[i].shader == shader )
{
already_in_array = true;
self.scrolling_overlay_list[i].priority = priority;
self.scrolling_overlay_list[i].scroll_time = scroll_time;
self.scrolling_overlay_list[i].alpha = alpha;
self.scrolling_overlay_list[i].direction = direction;
break;
}
}
if( !already_in_array )
{
temp_struct = spawnStruct();
temp_struct.shader = shader;
temp_struct.priority = priority;
temp_struct.scroll_time = scroll_time;
temp_struct.alpha = alpha;
temp_struct.direction = direction;
self.scrolling_overlay_list = array_add( self.scrolling_overlay_list, temp_struct );
}
self set_highest_overlay();
}

remove_scrolling_overlay( shader )
{
self endon( "disconnect" );
if( !IsDefined( self.scrolling_overlay_list ) )
{
self.scrolling_overlay_list = [];
}
temp_struct = undefined;
for( i = 0; i < self.scrolling_overlay_list.size; i ++ )
{
if( self.scrolling_overlay_list[i].shader == shader )
{
temp_struct = self.scrolling_overlay_list[i];
}
}
if( IsDefined( temp_struct ) )
{
self.scrolling_overlay_list = array_remove( self.scrolling_overlay_list, temp_struct );
}
self set_highest_overlay();
}

set_highest_overlay()
{
overlay = self get_highest_overlay();
if( IsDefined( self.current_overlay ) && ( !IsDefined( overlay ) || self.current_overlay.overlay != overlay ) )
{
self overlay_destroy();
}
if( !IsDefined( self.current_overlay ) && IsDefined( overlay ) )
{
self thread overlay_create( overlay );
}
}

get_highest_overlay()
{
if( !IsDefined( self.scrolling_overlay_list ) )
{
return undefined;
}
if( self.scrolling_overlay_list.size <= 0 )
{
return undefined;
}
highest_score_overlay = self.scrolling_overlay_list[0];
for( i = 1; i < self.scrolling_overlay_list.size; i ++ )
{
if( self.scrolling_overlay_list[i].priority > highest_score_overlay.priority )
{
highest_score_overlay = self.scrolling_overlay_list[i];
}
}
return highest_score_overlay;
}

overlay_create( overlay )
{
struct = spawnStruct();
struct endon( "overlay_over" );
self endon( "disconnect" );
self.current_overlay = struct;
struct.overlay = overlay;
scroll_percent = 0;
last_direction = overlay.direction;
while( true )
{
struct.hud = self create_overlay_hud( overlay.shader, overlay.alpha, scroll_percent, overlay.direction, last_direction );
struct.hud thread scroll_hud( overlay.scroll_time, self, struct, scroll_percent, overlay.direction, last_direction );
struct.hud thread set_hud_alpha( self, overlay );
current_scroll_time = overlay.scroll_time;
current_direction = overlay.direction;
while( true )
{
if( overlay.scroll_time != current_scroll_time )
{
break;
}
if( overlay.direction != current_direction )
{
break;
}
wait 0.01;
}
scroll_percent = 0;
if( IsDefined( struct.last_scroll_start_time ) )
{
elapsed_time = ( GetTime() - struct.last_scroll_start_time ) * 0.001;
scroll_percent = elapsed_time / current_scroll_time;
}
last_direction = current_direction;
struct.hud notify( "hud_destroy" );
struct.hud.second_hud Destroy();
struct.hud Destroy();
struct.hud = undefined;
}
}

overlay_destroy()
{
if( IsDefined( self.current_overlay ) )
{
if( IsDefined( self.current_overlay.hud ) )
{
self.current_overlay.hud notify( "hud_destroy" );
self.current_overlay.hud.second_hud Destroy();
self.current_overlay.hud Destroy();
}
self.current_overlay notify( "overlay_over" );
self.current_overlay = undefined;
}
}

create_overlay_hud( shader, alpha, scroll_percent, cur_direction, prev_direction )
{
hud_elem = NewClientHudElem( self );
hud_elem.x = 0;
hud_elem.y = 0;
hud_elem.hidewheninmenu = false;
hud_elem.horzAlign = "fullscreen";
hud_elem.vertAlign = "fullscreen";
hud_elem.foreground = false;
hud_elem SetShader( shader, 640, 480 );
hud_elem.alpha = alpha;
hud_elem.second_hud = NewClientHudElem( self );
hud_elem.second_hud.x = 0;
hud_elem.second_hud.y = -480;
hud_elem.second_hud.hidewheninmenu = false;
hud_elem.second_hud.horzAlign = "fullscreen";
hud_elem.second_hud.vertAlign = "fullscreen";
hud_elem.second_hud.foreground = false;
hud_elem.second_hud SetShader( shader, 640, 480 );
hud_elem.second_hud.alpha = alpha;
if( cur_direction == "down" )
{
hud_elem.y = 0;
hud_elem.second_hud.y = -480;
}
else
{
hud_elem.y = 480;
hud_elem.second_hud.y = 0;
}
if( scroll_percent > 0 )
{
if( cur_direction == "down" )
{
if( prev_direction == "down" )
{
scroll_percent_offset = scroll_percent * 480;
}
else
{
scroll_percent_offset = ( 1 - scroll_percent ) * 480;
}
hud_elem.y += scroll_percent_offset;
hud_elem.second_hud.y += scroll_percent_offset;
}
else
{
if( prev_direction != "down" )
{
scroll_percent_offset = scroll_percent * 480;
}
else
{
scroll_percent_offset = ( 1 - scroll_percent ) * 480;
}
hud_elem.y -= scroll_percent_offset;
hud_elem.second_hud.y -= scroll_percent_offset;
}
}
return hud_elem;
}

set_hud_alpha( player, overlay )
{
self endon( "hud_destroy" );
player endon( "disconnect" );
while( true )
{
self.alpha = overlay.alpha;
self.second_hud.alpha = overlay.alpha;
wait 0.01;
}
}

scroll_hud( scroll_time, player, struct, scroll_percent, cur_direction, prev_direction )
{
self endon( "hud_destroy" );
player endon( "disconnect" );
if( scroll_percent > 0 )
{
if( cur_direction == "down" )
{
if( prev_direction == "down" )
{
finish_scroll = ( 1 - scroll_percent ) * scroll_time;
}
else
{
finish_scroll = scroll_percent * scroll_time;
}
}
else
{
if( prev_direction != "down" )
{
finish_scroll = ( 1 - scroll_percent ) * scroll_time;
}
else
{
finish_scroll = scroll_percent * scroll_time;
}
}
self MoveOverTime( finish_scroll );
self.second_hud MoveOverTime( finish_scroll );
if( cur_direction == "down" )
{
self.y = 480;
self.second_hud.y = 0;
}
else
{
self.y = 0;
self.second_hud.y = -480;
}
struct.last_scroll_start_time = GetTime() - ( ( scroll_time - finish_scroll ) * 1000 );
wait( finish_scroll + 0.001 );
}
while( true )
{
if( cur_direction == "down" )
{
self.y = 0;
self.second_hud.y = -480;
}
else
{
self.y = 480;
self.second_hud.y = 0;
}
self MoveOverTime( scroll_time );
self.second_hud MoveOverTime( scroll_time );
if( cur_direction == "down" )
{
self.y = 480;
self.second_hud.y = 0;
}
else
{
self.y = 0;
self.second_hud.y = -480;
}
struct.last_scroll_start_time = GetTime();
wait( scroll_time + 0.001 );
}
}


There is no init or anything to call, this script can just remain
idle until you are ready to use it.

How To Use This:

Setting Up The Shader - First you need to get your overlay shader, any
shader works, but obviously use one that is meant for being displayed fullscreen,
with a pattern and nothing specific ( thats what this whole thing is for,
fullscreen overlays ). The material settings need to be the same as a normal
on screen shader ( like perk hud or something ), and they are not precached
in this script, you need to precace it seperately in the script yourself.

Using This In Script - Using this in script has been made really simple,
all you do is say weather to apply or remove the overlay shader.
To apply a shader, call this in your script where ever:
Code Snippet
Plaintext
self maps\_xS78_overlay::apply_scrolling_overlay( shader, priority, scroll_time, alpha, direction );

Now lets look at the arguments passed in:

   Shader - the name of the material you want to use as the overlay, also
   what is used to sort the overlays seperately, like a way to specify a single
   overlay

   Priority - The priority of this overlay showing up over the others. Basically
   you are able to apply multiple overlay's at once, and basically it only shows
   the overlay with the highest priority.

   Scroll Time - The time it takes for the hud to completely move down or up
   your screen in one cycle, basically increases\decreases the speed of the overlay.

   Alpha - The alpha ( visibility ) of the overlay ( i think we all know what this means ).

   Direction - The direction the overlay scrolls ( you can only put one of two things:
   "up" or "down", and the overlay will move in that direction.

You can re-apply the settings, basically meaning you can call that function again with
the same shader, and you can add new settings to the overlay. Each setting has been scripted
to update properly while its scrolling ( which was the hardest thing to do honestly ).

When it's time do be done with the overlay, you can easily remove it.
basically just call this:
Code Snippet
Plaintext
self maps\_xS78_overlay::remove_scrolling_overlay( shader );

Just call this with the shader you want to be removed, and it will remove. Once removed,
it will apply the overlay with the next highest priority number ( if the one you removed
had the highest priority number ). If you don't have any overlay's applied, no overlays
will show up ( duh ).

And thats pretty much it, I hope this becomes useful to some people :P

One note that people should know: this does use two HUD elems to properly
display the scrolling overlay, keep that in mind if you have a setup that
is on the verge of hitting the HUD limit.
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: DidUknowiPwn on July 27, 2015, 12:59:45 am
This would be so much easier in menu file ._.
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: ibounce on July 27, 2015, 01:26:15 am
Any chance you could post some images or a video?
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: Harry Bo21 on July 27, 2015, 01:48:29 am
Any chance you could post some images or a video?
its literally a full screen size hud elem moving of the screen in a certain direction if im reading this right

Imagine the lightning you get on your screen when you teleport in Der Reise, but imagine it moving upwards or sideways or something, I think thats what this is basically. Not sure though, havent read it fully
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: ibounce on July 27, 2015, 01:55:14 am
its literally a full screen size hud elem moving of the screen in a certain direction if im reading this right

Imagine the lightning you get on your screen when you teleport in Der Reise, but imagine it moving upwards or sideways or something, I think thats what this is basically. Not sure though, havent read it fully

Ahhh, gotcha. It's credits.  :troll:
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: Harry Bo21 on July 27, 2015, 02:06:16 am
Ahhh, gotcha. It's credits.  :troll:
lol well, I guess you could use it for credits ;)
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: alaurenc9 on July 27, 2015, 03:23:10 am
its literally a full screen size hud elem moving of the screen in a certain direction if im reading this right

Imagine the lightning you get on your screen when you teleport in Der Reise, but imagine it moving upwards or sideways or something, I think thats what this is basically. Not sure though, havent read it fully

it looks like the vulture aid green overlay thing that scrolls up your screen basically, except this comes with more: u can add different speeds, different directions, differenct alpha, especially how you can change those settings while its active and it updates without notice. And also you can apply multiple ones at one time, and use the highest priority thing. Its really good for if you don't want to end up with two overlays at once and you want one that dominates the others.

Ahhh, gotcha. It's credits.  :troll:

I mean I guess but the thing is it keeps like scrolling the same pic so you would see the same text over and over and over, so no don't do that.

This would be so much easier in menu file ._.

menu files don't offer this much without any script, so yea
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: DidUknowiPwn on July 27, 2015, 03:45:04 am
it looks like the vulture aid green overlay thing that scrolls up your screen basically, except this comes with more: u can add different speeds, different directions, differenct alpha, especially how you can change those settings while its active and it updates without notice. And also you can apply multiple ones at one time, and use the highest priority thing. Its really good for if you don't want to end up with two overlays at once and you want one that dominates the others.
 
I mean I guess but the thing is it keeps like scrolling the same pic so you would see the same text over and over and over, so no don't do that.

menu files don't offer this much without any script, so yea
Code Snippet
Plaintext
exp				rect X((-107) - ((float(milliseconds() % FOG_SCROLL_TIME) / FOG_SCROLL_TIME) * (854)))
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: Harry Bo21 on July 27, 2015, 04:09:29 am
Code Snippet
Plaintext
exp				rect X((-107) - ((float(milliseconds() % FOG_SCROLL_TIME) / FOG_SCROLL_TIME) * (854)))
lets be fair man, you are astonishingly good with menu files, but the rest of us hardly understand them, so just go around them lol
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: HitmanVere on July 27, 2015, 12:31:09 pm
lets be fair man, you are astonishingly good with menu files, but the rest of us hardly understand them, so just go around them lol

If you take time reading stock menufiles, you can understand very easily ;)
Title: Re: Scrolling Fullscreen Overlay Hud
Post by: alaurenc9 on July 27, 2015, 01:24:20 pm
Code Snippet
Plaintext
exp				rect X((-107) - ((float(milliseconds() % FOG_SCROLL_TIME) / FOG_SCROLL_TIME) * (854)))

No I understand you can make a fullscreen scrolling overlay, but this does more, im talking about how this script is able to handle the entire overlay system, all the settings and all the things it does. Menufile just creates the hud, and then you have to manage showing it and setting it up which would be harder than this is.