Throwing Axes

Created By:

[SL1CK]-=MERL1N=-

EMail

Phillm@netlink.com.au

Difficulty Scale

Easy/Medium

Web Page

 http://users.netlink.com.au/~phillm



Step 1
In this tutorial you need another model, an axe. This can easily be found by downloading the throwaxe.zip file with a throwing axe in it, and extracting it, putting in in quake\mypatch\progs.

..

Step 2
Right. Make a new file "throwaxe.qc" and add this into it :)

void () AxeTouch = {

local float clink;

local float damage;

if ( ((other == self.owner) && (self.num_bounces == 1)) ) { // if its the owner, and it aint bounced...

return ; // dont worry about it :)

}

else // otherwise

{

self.avelocity = '300 300 300'; // air velocity

self.movetype = MOVETYPE_BOUNCE; // how it moves (bounces)

setsize (self,'-1 -2 -3','1 2 3'); // size of entity

self.nextthink = time + 5; // wait 5 secs...

self.think = SUB_Remove; // get rid of it

}

if ( (other.takedamage && (self.velocity != VEC_ORIGIN)) ) { // if it is a hurtable thing...

if ( (self.num_bounces == 1) ) { // if it aint bounced yet

spawn_touchblood (40); // draw some blood

SpawnChunk (self.origin,self.velocity); // chuck a chunk

other.punchangle_x = -20; // angles

other.axhitme = 1;

if ( (other.health < 21) ) { // if hurtable has less than 21 health (changeable)

damage = 50000; // GIB IT!!!

} else { // otherwise

damage = 80; // do 80 damage (changeable)

}

T_Damage (other,self,self.owner,damage);

} else { // otherwise (back to bounce thing)

other.punchangle_x = -10;

spawn_touchblood (25); // spawn some blood

self.velocity = (self.velocity * -0.5); // change speeds

other.axhitme = 1;

if ( (other.health < 21) ) { // if less than 21 health

damage = 50000; // um...

} else {

damage = 20; // otherwise do 20 (changeable)

}

T_Damage (other,self,self.owner,20);

}

} else { // if it aint hittin a hurtable...

clink = (random () * 2); // bounce it

if ( (clink <= 1) ) {

sound (self,CHAN_WEAPON,"player/axhit2.wav",1,ATTN_NORM); // play sound (precache)

} else {

sound (self,CHAN_WEAPON,"weapons/tink1.wav",1,ATTN_NORM); // sound (precache)

}

}

self.num_bounces = (self.num_bounces + 1); // add to the bounces

if ( (self.num_bounces > 12) ) { // if it gets to 12

SUB_Remove (); // get it outta here!

}

};

..

Step 3

Pretty big touch function eh :) now we gotta spawn this babby and were almost home

void () W_ThrowAxe = {

local entity missile;

sound (self,CHAN_WEAPON,"weapons/woosh.wav",1,ATTN_NORM); // get a woosh noise // add it to qucke\mypatch\sounds\weapons (precache)

self.punchangle_x = CONTENT_SKY;

missile = spawn (); // spawn it

missile.owner = self; // own it

missile.movetype = MOVETYPE_FLYMISSILE; // fly movement

missile.solid = SOLID_TRIGGER; // solid entity with a touch function

makevectors (self.v_angle); // shoot it forward the way yer facing

missile.velocity = aim (self,10000);

missile.angles = vectoangles (missile.velocity);

missile.velocity = (missile.velocity * 600); // speeds etc...

missile.touch = AxeTouch; // if it hits call the touch func

missile.nextthink = (time + 600); // if it is flyin fer 10 mins

missile.think = SUB_Remove; // get rid of it :)

setmodel (missile,"progs/throwaxe.mdl"); // preache this new model

setsize (missile,VEC_ORIGIN,VEC_ORIGIN);

setorigin (missile,((self.origin + (v_forward * 2)) + '0 0 16')); // location of first spawnin

missile.avelocity = '-500 0 0';

missile.num_bounces = 1; // set the bounce level

};

..

Step 4

OK, as you can see 'num_bounces' is a new .float, so open up defs.qc, scroll to the bottom...

add .float num_bounces;

..

 Step 5

Right. Now we actually have to have a weapon that will shoot this. I will change the shotgun, you do this to whatever. Open up weapons.qc and go down to 'player weapon use'.

The first lot here shows the weapon model used for the weapon and the ammo. Since i cant figure out how to have a no ammo weapon (please tell me) we will leave it to show the ammo as shells, you wont loose any, dont worry :)

find the IT_SHOTGUN (shotgun) bit and change the model from "progs/v_shot.mdl" to "progs/v_axe.mdl", this will give it an axe model.

Just before w_attack you will se some empty voids such as 'void() player_rocket1;' at the end of these add 'void() W_ThrowAxe;'

This will let it know that we intend to define the axe throw function later on, but we want to talk about it now :)

Keep going to w_attack and change yer shotgun to this...

else if (self.weapon == IT_SHOTGUN)

{

player_axe1 (); // others will see your model chuck an axe

W_ThrowAxe (); // throw an axe

self.attack_finished = time + 0.75; // time between shots (change it if u like)

}

..

Step 6

The only thing left to do now is to open up progs.src and add 'throwaxe.qc' just AFTER 'weapons.qc'

That's it you're done! Breathe a sigh and compile, and run. Dont forget to precache the models and sounds at the top of wepons.qc :)