Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: [Tutorial][Work in progress] Hud elements

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    [Tutorial][Work in progress] Hud elements

    You can create 2 kinds of hud elements: a global one, or a client-based one.

    Global:
    Code:
    hud = newHudElem();
    Client:
    Code:
    hud = newClientHudElem(client_entity);
    Above code might look trivial, but remember to store your hud elems in some proper variable so you can destroy() them when you dont need them anymore. However, if you think you might reuse a hud elem, just make it insivible instead of destroying (iirc there is a max on creation of hud elements)

    Now, if you have a hud element, you want to place it somewhere. You can mainly do this using .vertAlign and .horzAlign:

    Code:
    hud.vertAlign = "some_string";
    hud.horzAlign = "some_string";
    In which the "some_string" is one of these, for vertAlign:
    Code:
    top
    bottom
    middle
    center_safearea
    fullscreen
    subtop
    noscale
    alignto480
    The easiest of this bunch is probably the fullscreen one. This makes your hud element stretch from top to bottom, having its zero-origin-point in the middle (as a horizontal line, as it still depends on the .horzAlign) of your screen. This means .y can range from +240 to -240 for the hud to be visible. The downside here is that the hud will be scaled (from 480 pixels to whatever you are using) and will probably look ugly on new, non-4:3 screens. Plus side is that it will cover the entire screen.

    The top alignment is so the engine knows it can use the top 480 pixels (? or does it scale according to your aspec ratio?) of your screen, with the zero-origin-point at the top of your screen. This means that, in order for the hud to become visible, you have to give it a negative .y coordinate. Plus side is that it will not be scaled, downside is that you can probably not reach the bottom of the screen (?).

    Bottom alignment is exactly the opposite of top-alignment: the hud will start at the bottom, having its zer-origin-point exactly there and requiring a positive .y to be visible.

    center_safearea uses the middle 640x480 pixels of your screen (might scale according to aspect ratio also, unsure) and will have your hud visible (at least partially) if you have a .y between 240 and -240

    If the middle alignment exists (unsure) it will not give much advantages over center_safearea, although it might be that middle scales according to aspect ratio while center_safearea does not (citation needed)


    For the .horzalign:
    Code:
    right
    left
    center
    center_safearea
    fullscreen
    subleft
    noscale
    alignto640
    Most of above alignments are comparable to their vertAlign counterparts: left will start at the left of your screen, requiring a positive .x, while right starts at the right, requiring a negative .x.

    It is advisable to use either fullscreen/fullscreen for both, or use any other for both (so dont use fullscreen/left or bottom/fullscreen) unless you know what you are doing and know its intended effect. It is also advisable to not use fullscreen for any text, unless you want it to look goddamn ugly, and the same goes for any image you want to have placed somewhere while not being scaled unevenly.

    [part about setvalue/settext/.label/setshader goes here]

    [part about .sort and .foreground goes here]

    [part about scaleovertime/fadeovertime+alpha goes here]

    [part about destroying goes here]

    [part with some practical examples with example images of usage of vertalign/horzalign goes here]
    Last edited by IzNoGoD; 15th September 2014 at 11:33.

  2. The Following 6 Users Say Thank You to IzNoGoD For This Useful Post:

    guiismiti (15th September 2014),Jeplaa (19th October 2013),kung foo man (19th October 2013),Lonsofore (25th March 2017),Loveboy (19th October 2013),Rocky (19th October 2013)

  3. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Feel free to write parts of this tutorial, i will then add them to the first post (or link them if you prefer) giving the proper credits.

    Also, there are a few things in the tutorial i'm not entirely certain of. If you know any of these things, feel free to reply, will edit them and credit you.

  4. #3
    Private pollo's Avatar
    Join Date
    Jul 2012
    Location
    Spain
    Posts
    116
    Thanks
    93
    Thanked 69 Times in 35 Posts
    Hey all, I know this is an old topic but I dont wan't to create a new topic for this question

    Can you tell me guys what are these variables used for?

    sort
    archived


    Eg.

    PHP Code:
    level.hud.sort 9999;
    level.hud.archived=false
    There's no info about this on the inet!

    Thanks in advance!

    Pollo
    Last edited by pollo; 12th September 2014 at 19:23.

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    sort is to indicate in what order the huds should be drawn (aka put before or behind other huds) (i dont know if higher number = foreground or lower number = foreground, try this yourself)

    archived = visible on killcam yes/no. Also applies to spectator (if you set archived to false, spectators cant see that particular hud). Im uncertain what happens with a non-archived hud as a personal hud for a spec, archived only applies when you are speccing a player
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  6. The Following 2 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (13th September 2014),pollo (12th September 2014)

  7. #5
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    So, I just made this today, it is a very basic hud based on eXtreme+ (only thing is, this is much more simple).
    This is for displaying kill streak messages as images instead of strings with iprintlnBold.
    I'm not sure if there are any errors, since it's the first hud I ever wrote, but it works fine.

    I hope it helps anybody who's looking for help.

    Do not forget to precache your shaders. Do it in Callback_StartGameType():
    Code:
    precacheShader("your_shader");
    PHP Code:
    displayShader(shadersizedurationattacker)
    {
        
    shaderhud newClientHudElem(attacker);
        
    shaderhud.vertAlign "subtop";
        
    shaderhud.horzAlign "center";
        
    shaderhud.size*(-0.5);
        
    shaderhud.size*(0.5);

        
    shaderhud.alpha 0;
        
    shaderhud setShader(shadersizesize);
        
    shaderhud.alpha 1;

        
    wait(duration);

        
    shaderhud fadeOverTime(1);
        
    shaderhud.alpha 0;
        
    wait(1);

        
    shaderhud destroy();

    Where, naturally, shader is the name of your shader (string), size is the size, duration is the duration before it starts to fade and attacker is the player receiving the new hud.



    added info that was here to first post - izno
    Last edited by IzNoGoD; 15th September 2014 at 11:34.

  8. The Following User Says Thank You to guiismiti For This Useful Post:

    pollo (15th September 2014)

  9. #6
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    A couple useful information and another HUD example:

    - These hud attributes will align your object to its origin position. I could have used it in the hud from my previous post, but I didn't know about it:
    self.your_hud.alignx
    which can be: "left", "center", "right"

    self.your_hud.aligny
    which can be: "top", "middle", "bottom"


    And here's an example of a stopwatch. It gradually changes color from green (full time) to red (end time). Made by me, based on game type sd. Use thread to call this function, since there's a <duration> total wait time before it is finished.

    PHP Code:
    gunshipStopwatch()
    {
        
    self endon("disconnect");
        
    self endon("killed_player");

        if(
    isdefined(self.hud_gunshipstopwatch))
            
    self.hud_gunshipstopwatch destroy();

        
    duration 60;
        
    increment 0.5;

        
    self.hud_gunshipstopwatch newClientHudElem(self);
        
    self.hud_gunshipstopwatch.6;
        
    self.hud_gunshipstopwatch.= -24;
        
    self.hud_gunshipstopwatch.horzAlign "left";
        
    self.hud_gunshipstopwatch.vertAlign "middle";
        
    self.hud_gunshipstopwatch setClock(durationduration"hudStopwatch"4848);
        
    self.hud_gunshipstopwatch.sort 9999;

        for(
    1duration 1.01+= increment)
        {
            
    gradientlevel duration;
            
    self.hud_gunshipstopwatch.color = (gradientlevel,(gradientlevel),0);
            
    wait(increment);
        }

        
    self.hud_gunshipstopwatch destroy();


  10. The Following 2 Users Say Thank You to guiismiti For This Useful Post:

    Ni3ls (22nd September 2014),pollo (22nd September 2014)

  11. #7
    Private pollo's Avatar
    Join Date
    Jul 2012
    Location
    Spain
    Posts
    116
    Thanks
    93
    Thanked 69 Times in 35 Posts
    Hey

    I had some trouble while setting the alpha value of some huds by using the "fadeovertime()" function (sometimes when 2 funcs change the alpha value of a same hud, it kinda "flashes", or become transparent/opaque in a short time), so I made this little one which seems to work fine.

    PHP Code:
    //call the function like this:

    //thread _alphahud(level.hud,true);

    //hud = your hud
    //show = boolean (true, hud fades to opaque; false, it fades to transparent)
    //you can also add a time variable in the function to edit it at your own

    _alphahud(hud,show)
    {
    self endon("disconnect");
        for(
    i=0;i<20;i++)
        {
            if(
    show == true)
            {
            
    hud.alpha += 0.05;
                if(
    hud.alpha == 1)
                    break;
            }
            else
            {
            
    hud.alpha -= 0.05;
                if(
    hud.alpha == 0)
                    break;
            }
        
    wait .05;
        }
    return;

    Last edited by pollo; 22nd September 2014 at 21:56.

  12. The Following User Says Thank You to pollo For This Useful Post:

    guiismiti (22nd September 2014)

  13. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by pollo View Post
    Hey

    I had some trouble while setting the alpha value of some huds by using the "fadeovertime()" function (sometimes when 2 funcs change the alpha value of a same hud, it kinda "flashes", or become transparent/opaque in a short time), so I made this little one which seems to work fine.

    PHP Code:
    //call the function like this:

    //thread _alphahud(level.hud,true);

    //hud = your hud
    //show = boolean (true, hud fades to opaque; false, it fades to transparent)
    //you can also add a time variable in the function to edit it at your own

    _alphahud(hud,show)
    {
    self endon("disconnect");
        for(
    i=0;i<20;i++)
        {
            if(
    show == true)
            {
            
    hud.alpha += 0.05;
                if(
    hud.alpha == 1)
                    break;
            }
            else
            {
            
    hud.alpha -= 0.05;
                if(
    hud.alpha == 0)
                    break;
            }
        
    wait .05;
        }
    return;

    As there is no loop function running continuously, do not use an endon(). This will add to the max number of script variables allowed, and is completely unnecessary unless you have a loop function which does more than count (as in the current method). Endon() is designed to kill continuous loops only. It will not end any other function such as a count.

    Max script variables will crash a server, and is reached when the game counts ever single instance of endon(), waittill(), or wait(). Conserve your script variables at all costs. It is very easy to reach the ceiling with them.

  14. The Following 2 Users Say Thank You to Tally For This Useful Post:

    guiismiti (23rd September 2014),pollo (23rd September 2014)

  15. #9
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by Tally View Post
    As there is no loop function running continuiously, do not use an endon(). This will add to the max number of script variables allowed, and is completely unnecessary unless you have a loop function which does more than count (as in the current method).

    Max script variables will crash a server, and is reached when the game counts ever single instance of endon(), waittill(), or wait(). Conserve your script variables at all costs. It is very easy to reach the ceiling with them.
    You either have to use endon or you have to check if self is defined, else you are trying to write to a client hud elem whilst the client is not defined anymore. The endon will be freed at the end of this loop, which only takes a second. I'd say, keep the endon.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  16. #10
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by IzNoGoD View Post
    You either have to use endon or you have to check if self is defined, else you are trying to write to a client hud elem whilst the client is not defined anymore. The endon will be freed at the end of this loop, which only takes a second. I'd say, keep the endon.
    In my opinion it is better to use a check for defined entity. An endon() will kill a for() count after the first loop through but if the player leaves the server before the 1st count is complete it is likely to throw an "undefined is not an entity" error anyway. I've had that happen to me many times. It would have been helpful if the endon() function killed for() counts during the loop, and not after it has run its course. But that is not the case.

    I warn people about the mis-use of endon() functions as a matter of course because if you have a big mod it is very easy to hit the max number. The COD2 stock files already use a lot anyway. It doesn't give the modder much to play with.
    Last edited by Tally; 23rd September 2014 at 09:41.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •