Forum

Sniper Rifle

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Sniper Rifle

Postby redrum » Wed Sep 19, 2007 4:38 pm

Guys, I followed the tutorial on the sniper rifle. Works great!

I wanted to change the damage that it deals to be proportional to the distance of the shot.

I tried this change to the code, but it won't compile :(

/* //all new function new

sniper rifle
================
W_FireSniper
================
*/
void() W_FireSniper =
{
local vector dir;
local float damage;

damage = 300 + random()*50 + random()*50; //up to 400, never less than 300

- sniper damage

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

self.punchangle_x = -2;

self.currentammo = self.ammo_shells = self.ammo_shells - 10; //set to whatever you want
dir = aim (self, 100000);
FireBullets (1, dir, '0 0 0', damage);

org = self.origin + '0 0 16';
traceline (org, org + v_forward*300, TRUE,
self);
};

I added the lines in bold.
Am I on the right path of thinking?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Orion » Wed Sep 19, 2007 6:06 pm

Notice the very first line:

Code: Select all
local vector dir;


You have to change it to this:

Code: Select all
local vector dir, org;


Because there's an "org" vector, but you forget to create a local vector at the very top of the function. This with floats and string too.
But local void isn't needed, of course.
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby FrikaC » Wed Sep 19, 2007 7:39 pm

Traceline tests a line in space. So yes, you're on to something, but you don't do anything with the results the traceline gives you.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Urre » Thu Sep 20, 2007 6:34 am

redrum: the problem in this case is that the function you're calling, FireBullets, already does a traceline, and deals damage to whatever it hits, so you can't really see how far it went, and thus scale the damage. I'd recommend you make your own bullet firing inside that code. Remove the following lines (the last three):

Code: Select all
FireBullets (1, dir, '0 0 0', damage);

org = self.origin + '0 0 16';
traceline (org, org + v_forward*300, TRUE, self);


Then add something along the lines of(note: copy pasting won't guarantee to make it work, you need to fix it yourself):

Code: Select all
traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + dir*4096, FALSE, self);
damage = 1000 - vlen((self.origin+self.view_ofs) - trace_endpos);
if (damage < 1)
   damage = 1;
if (trace_ent.takedamage)
{
   T_Damage(trace_ent, self, self, damage);
   SpawnBlood (trace_endpos, trace_plane_normal*200, damage);
}
else
{
   WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
   WriteByte (MSG_BROADCAST, TE_SPIKE); // makes a ricochet sound
   WriteCoord (MSG_BROADCAST, trace_endpos_x);
   WriteCoord (MSG_BROADCAST, trace_endpos_y);
   WriteCoord (MSG_BROADCAST, trace_endpos_z);
}


The interesting line here is the one that assigns the damage. What it does is start at 1000 damage, and then removes the distance the bullet went from the damage, making it only do 1 damage if it travelled further than 1000 quake units. Most Quake rooms aren't this large, so that should rarely happen in your average Quake map. I'm mentioning this cause I figure you might want to change it somehow, perhaps even make it do more damage the further it travels, which would be a lot easer in fact. If you want to do that, remove these lines:

Code: Select all
damage = 1000 - vlen((self.origin+self.view_ofs) - trace_endpos);
if (damage < 1)
   damage = 1;


And make it say:

Code: Select all
damage = 50 + vlen((self.origin+self.view_ofs) - trace_endpos);


That line makes it do a minimum of 50 damage (when you're so close you can see the pores on the opponents skin) up to however far the bullet went. So this rewards long shots, which could make for some cool gameplay.

Hope you get it working!
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby redrum » Thu Sep 20, 2007 2:44 pm

Thanks for the info, I'll give it a shot! (pun intended)
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest