Announcement

Collapse
No announcement yet.

Timer Delay Problem! Need Coder help! (SOLVED, Free code avail.)

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

    Timer Delay Problem! Need Coder help! (SOLVED, Free code avail.)

    I've been at this thing for the passed week, and it's melted my brain into a bubbly pile of grey crapulence.

    Description: I've used the code from the Skaarjpack folder (Skaarjpupae) Everything is fine for the most part, the monsters walk around, idle, die, run, attack.

    Problem: When the monster makes contact with the player, it deals damage instantly. I need to somehow delay the actual damage that is dealt to occur 'X' amount of seconds after initial contact so that it syncs with my attack animation. (Looks really silly when you get hurt before the monster is done with its claw animation)

    I've tried doing a search, googled, idled in irc, and haven't come to any satisfactory progress. This is eating up so much of my time that I could be using on other things. If anyone has the coding knowhow to help me with this piece of code and tell me how I futzed it up, that would be very appreciated! I'll post the code below:

    class ThisMonster extends MasterMonster;

    var name DeathAnims[2];
    var bool btimeddamage;

    function SetMovementPhysics()
    {
    SetPhysics(PHYS_Falling);
    }

    simulated function PlayDirectionalDeath(Vector HitLoc)
    {
    PlayAnim(DeathAnims[Rand(2)], 1.0, 0.0);
    }

    simulated function PlayDirectionalHit(Vector HitLoc)
    {
    TweenAnim('TakeHit', 0.05);
    }

    function PlayVictory()
    {
    Controller.bPreparingMove = true;
    Acceleration = vect(0,0,0);
    bShotAnim = true;
    PlayAnim('WinAnimation', 1.0, 0);
    Controller.Destination = Location;
    Controller.GotoState('TacticalMove','WaitForAnim') ;
    }

    function RangedAttack(Actor A)
    {
    local float Dist;

    if ( bShotAnim )
    return;

    Dist = VSize(A.Location - Location);
    if ( Dist > 100 )
    return;
    bShotAnim = true;
    PlaySound(ChallengeSound[Rand(4)], SLOT_Interact);
    if ( Dist < MeleeRange + CollisionRadius + A.CollisionRadius )
    if (!btimeddamage)
    {
    btimeddamage=true;
    settimer(2,false);
    }
    if ( FRand() < 0.5 )
    SetAnimAction('Attack1');
    else
    SetAnimAction('Attack2');
    MeleeDamageTarget(25, vect(0,0,0));
    Controller.bPreparingMove = true;
    Acceleration = vect(0,0,0);
    return;
    }

    function Timer()
    {
    if (btimeddamage)
    {
    btimeddamage=false;
    }
    }


    I'm not sure if I put the timer in the right place, or if I'm missing a whole boat load of code but if you are willing to help with this little problem, I would be very grateful! Thanks.

    #2
    tbh, itd be a little bit easier if you used an AnimNotify to trigger the attack. Just place it at the point in the attack animation that damage is most logical, throw in some 'only on the server' checks in the function, and call it good.

    Check out the Brute's RangedAttack and WhipDamageTarget functions for a working example. (RangedAttack tells the brute to run the melee animation and not do anything else, WhipDamageTarget is run halfway through the melee attack animation.)

    Comment


      #3
      I tried adding that part of the Brute code in, but now the monster doesn't move or shoot................gah! Someone hep meh, hep meh pleas!

      Comment


        #4
        You would probably do something like this.

        Code:
        //Plays the Anim
        function RangedAttack(Actor A)
        {
            local float Dist;
        
            if ( bShotAnim )
                return;
        
            Dist = VSize(A.Location - Location);
            
            if ( Dist > 100 )
                return;
            
            bShotAnim = true;
            PlaySound(ChallengeSound[Rand(4)], SLOT_Interact);
             
            if ( FRand() < 0.5 )
                SetAnimAction('Attack1');
            else
                SetAnimAction('Attack2');
                           
            Controller.bPreparingMove = true;
            Acceleration = vect(0,0,0);
            
            return;
        } 
        
        //Does the Damage
        function DoRangedAttack()
        {
            MeleeDamageTarget(25, vect(0,0,0));
        }
        DoRangedAttack would be called by the AnimNotify in the Animations at the point it should make impact with the player.

        Comment


          #5
          Thanks for your help guys! I tried out Dash' method and there were no compile errors, but not damage was being done. I kept on fiddling with it and remembered the 'gotostate' and 'sleep' functions. I always thought that the sleep thing only delayed animations, but I gave it a try anyway (not thinking anything would come out of it) but it worked!!!! Thanks for replying guys and since it's been such a **** pain to get this working for so long, if anyone wants some very basic, workable (though **** sloppy) monster/zombie code, drop me an email and I'll send you the code.

          Comment


            #6
            Well I guess doing it that way works too. I forgot that the function that gets called from the AnimNotify needs to be in the Actor that has the mesh/Anims, the pawn in this case. If you move the function there it should work.

            I would suggest going the AnimNotify route mainly because if you change the animation you have to retime it and keep a bunch of magic numbers for times around. Having the attack be Animation based is lot more flexable; it even allows for some neat effects like if the animation is interrupted by like taking a hit before it actually makes contact the damage never gets done. I am sure you could setup the time dependent code to do something similar it would just be kinda messy though. Anyways, if the sleep/time dependent code works for what you want its all good.

            Comment

            Working...
            X