Damage

Topics regarding Scripting with Reality Factory
Post Reply
Masta_J
Posts: 37
Joined: Tue Apr 17, 2007 1:35 pm
Location: Johannesburg South Africa

Damage

Post by Masta_J »

Got my player pawn up and running from last post (RFmanual). Thanks alot guys, couldn hav don it otherwise! I hav two questions for this post:

1) How do I program melee attacks into my player's script. I have tried to insert the animations by defining extra shooting animations (eg. shoot1, shoot2 etc) and then assigning them to a specific key (eg. K_PUNCH [27], K_KICK [28] etc) but so far all it does is stall my player for a couple seconds and then set him back to idle.

2) How do I set the collision detection and damage done to my opponent. I know this has to do with damageattribute, I just don know how to do it.

Much appreciated, thanks guys
A good warrior knows his limits, but a great warrior finds his way around them.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Post by Juutis »

Sorry for being so slow, I've started to write a reply several times already, but then got distracted and decided to put it off.

I assume you know the basics of scripting. Orders and stuff...

genericplayer.s handles the attack action with this piece of script:

Code: Select all

    if(IsKeyDown(K_FIRE))
    {
        //fire
        if(ANC < 1)
        {
            //only go to shoot anim if at idle
            ANIM=StringCopy(SHOOTANIM);
            ANC=1;
        }
        // Check fire rate
        if(self.time > TM+FIRERATE)
        {
            TM=self.time;
            FireProjectileBlind(FIREAMMO,WEAPONHAND,0,0,0,DAMAGEATTRIB);
            AddExplosion(FIREEFFECT,WEAPONHAND,0,0,0);
            TM=self.time;
        }
    }
Basically, you could just copy-paste it and change the variables ('K_FIRE', 'SHOOTANIM' etc...) to match those of your new attack. I think that even if the attack is a melee attack you should still use a projectile. You could define a projectile with very short lifetime and then shoot that with the command 'FireProjectileBlind()' while playing the melee animation. That way you don't have to worry about the collisions and stuff.

One thing, though. Piling all your actions into one order ('RunPlayer') will cause problems eventually, so here's another approach. Let's give, say, the 'kick' action a whole order of its own. Also, a delay before the projectile is launched is easier to do this way. Here's an example order for the kicking:

Code: Select all

Kick[()
{
    if(attackdelay < self.time)  // see if enough time has passed since the animation started
    {
	FireProjectileBlind(KICKPROJECTILE,BONE,0,0,0,DAMAGEATTRIB);  // shoot the projectile (= do the damage)
	attackdelay = self.time + 10000;   // make sure the damage is done only once
    }

    if(self.animate_at_end)  // check if the animation has finished
    {
        self.think="RunPlayer";  // go back to the basic routines
        return 0;
    }
}]
And add this to the 'RunPlayer' order.

Code: Select all

    if(IsKeyDown(K_KICK))   // check if the kick key is pressed
    {
        //kick

	AnimateHold(KICK);   // play kick animation
	attackdelay = self.time + ATTACKDELAY;   // set the delay before doing damage
	self.think = "kick";   // go to order 'kick'
	return 0;
    }
You will need to define all the variables (attackdelay, ATTACKDELAY, KICKPROJECTILE etc..) in the start of the script.


I really hope I made sense. I'm feeling tired for some strange reason. :? Feel free to ask if you have any questions. :)


***EDIT***
Oh ya, the scripts may have some errors. Just set 'Console(true);' in the first order to get rid of them.
Pain is only psychological.
Masta_J
Posts: 37
Joined: Tue Apr 17, 2007 1:35 pm
Location: Johannesburg South Africa

Thanks

Post by Masta_J »

Such an obvious solution to a problem that i made incredibly complex! Really appreciate the help, laters...
A good warrior knows his limits, but a great warrior finds his way around them.
Post Reply