Results 1 to 10 of 20

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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 20:56.

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

    guiismiti (22nd September 2014)

  3. #2
    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.

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

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

  5. #3
    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

  6. #4
    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 08:41.

  7. #5
    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
    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.
    This might be the case in many other pieces of code, but as the wait is at the end of the loop, this will not happen, as cod2 runs on a frame-by-frame basis, and you cannot disconnect mid-frame.

    Edit: above is true for checking for defined(), but not true for endon. Endon will work properly.

    But like tally is saying, max variables might be an issue, especially on servers filled with players.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    pollo (23rd September 2014)

Posting Permissions

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