Announcement

Collapse
No announcement yet.

Cant get condition check right.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cant get condition check right.

    Hello there.
    I have these lines of code in my W_FireWeapon function.
    My purpose is to play one set of frame macros if the player aims at something with 1 and 39 hitpoints and another macro if he aims at something without health.
    My limited brain capacity is not able to wrap around what i have to do. The lines below have the effect that the macros are played at seemingly random patterns.

    else if (self.weapon2 & IT3_CHAINSAW) //if the chainsaw is equipped
    {
    if ((trace_ent.health > 0) && (trace_ent.health < 40))
    //and my trace entity has 1-39 health
    {
    player_Chainsaw1();
    //saw forward through it, as long as the mouse button is pressed (coded in player.qc)
    }
    else //if trace entity is above 39 or below 1 health
    {
    r = random();
    if (r <= 0.5)

    {player_ChainSwing1();} //swing horizontal if r is smaller than 0.5
    else
    {player_ChainSwingB1();}
    //or vertical if not
    self.attack_finished = time + 0.7; //end attack after 0.7 seconds
    }
    }


    I looked at how other functions and mods do similar checks, but somehow their solutions do not work in this case.
    I also tried :

    if ((trace_inopen != 1) || ((trace_ent.health > 1) && (trace_ent.health < 41)))

    if ((trace_ent.solid == SOLID_SLIDEBOX) && ((trace_ent.health > 1) && (trace_ent.health < 41)))


    Doesn't work

    Well, i'm outdumbed by my brain.
    Can any of yours help me?
    That would be really nice.
    I once was a Ranger like you. But then i took a rocket to the knee.
    My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

  • #2

    Hell, this site works charms!
    As usual, right after posting a request for help i found this solution:

    void() W_Attack =
    {
    local float r;
    local vector source;


    [Blablabla]

    else if (self.weapon2 & IT3_CHAINSAW) //if the chainsaw is equipped
    {

    source = self.origin + '0 0 16';
    traceline (source, source + v_forward*64, FALSE, self);


    if ((trace_ent.solid == SOLID_SLIDEBOX) || ((trace_ent.health > 1) && (trace_ent.health < 41)))//and my trace entity has 1-39 health
    {
    player_Chainsaw1();
    //saw forward through it, as long as the mouse button is pressed (coded in player.qc)
    }
    else //if trace entity is above 39 or below 1 health
    {
    r = random();
    if (r <= 0.5)

    {player_ChainSwing1();} //swing horizontal if r is smaller than 0.5
    else
    {player_ChainSwingB1();}
    //or vertical if not
    self.attack_finished = time + 0.7; //end attack after 0.7 seconds
    }
    }
    I once was a Ranger like you. But then i took a rocket to the knee.
    My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

    Comment


    • #3
      There is little to go by here but, I may be able to help due to the 7 gabillion mistakes I have made as a programmer.

      This is some of what I would do:

      Print some of those vars in the conditionals so you can track what is being hit and the value it hit at.

      Slim the whole thing down and add in one condition at a time until it breaks.

      In other words audit your values and rebuild your conditions. I bet you'll find through the auditing that some value is totally wrong. Like maybe .health is always 0 or something.

      Comment


      • #4
        Thanks for the advice! I already found a solution. I can not imagine a way to slim that section down. The Whole thing is:

        void() W_Attack =
        {
        local float r;
        local vector source;

        if (!W_CheckNoAmmo ())
        return;

        makevectors (self.v_angle);
        self.show_hostile = time + 1;

        if (self.weapon == IT_AXE)
        {

        if(self.weapon2 & IT3_AXE)
        {
        sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
        r = random();
        if (r < 0.25)
        player_axe1 ();
        else if (r<0.5)
        player_axeb1 ();
        else if (r<0.75)
        player_axec1 ();
        else
        player_axed1 ();
        self.attack_finished = time + 0.5;
        }
        else if(self.weapon2 & IT3_CHAINSAW)
        {
        source = self.origin + '0 0 16';
        traceline (source, source + v_forward*64, FALSE, self);

        if ((trace_ent.solid == SOLID_SLIDEBOX) && ((trace_ent.health > 1) && (trace_ent.health < 41)))
        {
        player_Chainsaw1();
        }
        else
        {
        r = random();
        if (r <= 0.5)
        {player_ChainSwing1();}
        else
        {player_ChainSwingB1();}
        self.attack_finished = time + 0.7;
        }
        }
        }

        ...[rest of the W_Attack function]

        Originally i just had to make a traceline, before i could let it check for anything.
        I once was a Ranger like you. But then i took a rocket to the knee.
        My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

        Comment


        • #5
          I didn't mean slim it down forever. I meant slim it down and 1 condition at a time build it back up, testing in between. This way you could find the condition that was not working.

          Also, you are checking if solid OR health <> range. Is that really what you want?

          Comment


          • #6
            Also, you are checking if solid OR health <> range. Is that really what you want?
            Do you mean i compare the solid and the health with the range to the entity that is hit by the traceline?
            Uhm... strange, it works nevertheless

            I didn't mean slim it down ...
            Ah, now i understand what you meant. I'm often a little slow in the head.

            Here is a video with how it looks ingame:

            The Solider (less than 40 health at start Edit: in the most cases, this time not) get carved away immediately with the straight away holding animation. The Ogre (300 health at start) needs a little work by swinging the chainsaw from side to side, Edit: then the code starts to play the Straightaway-downsawing animation. Also, the horizontal and vertical animations are played, if the player aims at things without health or the right kind of solid. Well, don't look at the chainsaw animations too closely, they are still very clunky.

            I once was a Ranger like you. But then i took a rocket to the knee.
            My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

            Comment


            • #7
              I think this is actually what you are trying to do. I may be wrong.

              The idea here is that you should be able to use the chainsaw all the time. That being said you do not need a range or to test the SOLID type. What if the ent was a door? You can't open doors with your chainsaw? Of course you can. It does not matter if the trace_ent has any health so only define the upper limits of the first animation. You don't need an 'r' var cause you only use the var 1 time. You do not need a bunch of nested ifs to make a switch decision. Just use a ternary statement.

              ex ternary statement:
              (if this is true)? then do this : (else if this is true) ? then do this : else do this;
              Code:
              else if(self.weapon2 & IT3_CHAINSAW)
              {
                  source = self.origin + '0 0 16';
                  traceline (source, source + v_forward*64, FALSE, self);
              
                  (trace_ent.health <= 39) ? player_Chainsaw1() : (random() <= 0.5) ? player_ChainSwing1() : player_ChainSwingB1();
              
                  self.attack_finished = time + 0.7;
              }
              Last edited by MadGypsy; 10-13-2017, 12:17 AM.

              Comment


              • #8
                Thanks again for your time and effort, Mad_Gypsy.
                Imagine that i spend you a drink :-)
                I once was a Ranger like you. But then i took a rocket to the knee.
                My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

                Comment


                • #9
                  You're welcome. Did it work?

                  Comment


                  • #10
                    Yes, it did!
                    I once was a Ranger like you. But then i took a rocket to the knee.
                    My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

                    Comment


                    • #11
                      Awesome!

                      I'll help you more times if you need help and you don't even have to 'spend' me imaginary drinks. I enjoy helping people with code. Especially if the person is an amateur.
                      Last edited by MadGypsy; 10-13-2017, 11:52 AM.

                      Comment


                      • #12
                        This is excellent! I imagine this is being compile with FTEQCC?

                        EDIT: Just tired this out and it works flawlessly. Never even considered this in QC. Thanks for showing us that gypsy.
                        Last edited by Dutch; 10-14-2017, 02:44 AM.
                        'Replacement Player Models' Project

                        Comment


                        • #13
                          Sometimes i Feel Like i still have a Lot to learn until i can call me an Amateur.
                          I once was a Ranger like you. But then i took a rocket to the knee.
                          My little gore mod : http://quakeone.com/forum/quake-mod-...76473-gore-mod

                          Comment


                          • #14
                            TheKillingJoke
                            You'll do fine. I'll help you and you'll get real good. I'm out of touch with QC but, I can program my ass off so, whatever you got I'll figure it out.


                            Dutch
                            It's only really any good if you just have 2 or 3 singular operations. It can become a pain to read, really fast but, technically you should be able to chain ternaries to infinity. You should also be able to use it after =

                            MyVar = (some condition)? 500 : 1000;

                            Note: my 2 parter above is an actual ternary in full. The 3 parter in my original example is actually 2 ternaries chained together. Look at ternaries as ONLY if and else but the else can hold another ternary which makes it a virtual 'else if'. However if we broke it down this is really what's happening when you chain.

                            Code:
                            if () {
                            } else {
                                if () {
                                } else {
                                }
                            }
                            You can only have 1 value per condition. There is no way to ternary the below nor would you want or ever need to. It would be a mess.

                            Code:
                            If(condition) {
                                myVar1 = 1;
                                myVar2 = 2;
                            } else {
                                myVar1 = myVar2;
                            }
                            Also, you cannot omit any part of a ternary. Let's say you chain a few ternaries and get to the final else but, don't have a final value to use...you better find one... Null, Void, NaN, Empty String, NEGATIVE_INFINITY, something.

                            ​​​​​
                            Last edited by MadGypsy; 10-14-2017, 07:51 AM.

                            Comment

                            Working...
                            X