Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

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

  1. #11
    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

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

    pollo (23rd September 2014)

  3. #12
    Private pollo's Avatar
    Join Date
    Jul 2012
    Location
    Spain
    Posts
    116
    Thanks
    93
    Thanked 69 Times in 35 Posts
    Well I need to put an endon() because I have a func somewhere in my script which is continuously fading the hud (if players touch a trigger the hud starts to flash), so while I was testing I noticed that if a player disconnects when the hud func was running, the server crashed with the "undefined is not an entity" error.

    But thank you for this advice, didn't know there was a max on that func. Atm there are like 10 endon in my script argh
    Last edited by pollo; 23rd September 2014 at 15:38.

  4. #13
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    Does anybody know if it is possible to change the position of the .label, from left to right?
    set logfile 2

  5. #14
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Put a &&1 in your label.

    hud.label = &"&&1 is on a killing spree";
    hud setplayernamestring(player);
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    guiismiti (24th March 2017)

  7. #15
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    Looks like it works for player names only, not custom strings.
    It will be useful for another purpose, though.

    Anyway, I'm just gonna add a lot of spaces to the "Headshot:" string and add the "m" in the end, instead of adding "m" as a label of the distance value.

    Click image for larger version. 

Name:	Untitled.png 
Views:	54 
Size:	97.0 KB 
ID:	1303
    set logfile 2

  8. #16
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    You could also .value or setstring() it, but that didnt make sense given the stuff I typed in the example.

    For your thing:

    hud.label = &"Headshot: ^1&&1 ^7m";
    hud.value = 36;

    Might need to add that label as a localized string file, not sure if &&1 works without it. Try it i'd say.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    guiismiti (24th March 2017)

  10. #17
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    I will try it later.

    The other purpose I had with it was to print variable messages to everyone (iprintln):
    Code:
    iprintln(&"BATTLEFIELD_MONSTERKILL", player);
    Localized string:
    Code:
    REFERENCE           MONSTERKILL
    LANG_ENGLISH        "&&1 ^7- ^1MONSTER KILL !!!"
    LANG_GERMAN         "#same"
    LANG_RUSSIAN        "#same"
    Edit #1: I posted because it worked without the need of setplayernamestring(player). I copied the way it is on meatbot.
    Edit #2: I tried izno's suggestion and it seems to be the best thing to do because (1) I only need 1 hud and (2) it is now perfectly centered. Thank you very much one again.
    Just one small corretion, change
    Code:
    hud.value = x;
    for
    Code:
    hud setValue(x);
    And here is the code for a simple hud for headshots.
    1. You must create the localized string for the label:
    Code:
    REFERENCE           HEADSHOT
    LANG_ENGLISH        "^7Headshot: ^1&&1 ^7m"
    2. On player connect, set self.headshothudid to 0;
    3. Call this function with the killer
    PHP Code:
    displayHeadshot(distanceduration)
    {
        
    self.headshothudid += 1;
        
    hudid self.headshothudid;

        if(
    isdefined(self.headshothud))
        {
            
    self.headshothud destroy();
        }

        
    self.headshothud newClientHudElem(self);
        
    self.headshothud.vertAlign "top";
        
    self.headshothud.horzAlign "center";
        
    self.headshothud.alignx "center";
        
    self.headshothud.120;
        
    self.headshothud setValue(distance);
        
    self.headshothud.label = &"FILENAME_HEADSHOT";
        
    self.headshothud.fontScale 1.4;
        
    self.headshothud.alpha 1;
        
    self.headshothud.sort 5000;
        
    self.headshothud.color = (111);

        
    wait(duration);

        
    // if the player performed another headshot, there will be a new hud, which should not be affected/deleted by the old hud function
        
    if(self.headshothudid == hudid)
        {
            
    self.headshothud fadeOverTime(1);
            
    self.headshothud.alpha 0;

            
    wait(1);

            if(
    self.headshothudid == hudid)
            {
                if(
    isdefined(self.headshothud))
                {
                    
    self.headshothud destroy();
                }

                
    self.headshothudid 0;
            }
        }

    Where FILENAME is the name of your localized strings file; duration is the duration of the hud (not counting the 1 second for fading); and distance(in meters) can be given as
    Code:
    distance = int(((distance(attacker.origin , self.origin)) * 0.0254) + 0.5);
    (the +0.5 is because int will round, for example, 3.7 to 3, and I'd rather have it rounding it to the nearest int)
    Last edited by guiismiti; 25th March 2017 at 14:59.
    set logfile 2

  11. #18
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    If you have libcod, you can also use Izno's unprecached setText() patch

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

    guiismiti (25th March 2017)

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

    PHP Code:
    headshot(meters)
    {
        
    self notify("headshot");
        
    self endon("headshot");
        
    self endon("disconnect");
        if(
    isdefined(self.headshothud))
            
    self.headshothud destroy();

        
    self.headshothud newclienthudelem(self);
        
    //set other stuff like .x etc here

        
    self.headshothud.label = &"yourshitgoeshere";
        
    self.headshothud setvalue(meters);
        
    self.headshothud.alpha 1;
        
    wait 3;
        
    self.headshothud.fadeovertime(3);
        
    self.headshothud.alpha 0;
        
    wait 3;
        
    self.headshothud destroy();

    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

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

    guiismiti (26th March 2017),kung foo man (26th March 2017)

  15. #20
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    Change hud.fadeovertime for hud fadeovertime and it works fine.
    set logfile 2

Posting Permissions

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