Inside3D!
     

Sniper Rifle

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
redrum



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Wed Sep 19, 2007 4:38 pm    Post subject: Sniper Rifle Reply with quote

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 Sad

/* //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 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
Orion



Joined: 12 Jan 2007
Posts: 413
Location: Brazil

PostPosted: Wed Sep 19, 2007 6:06 pm    Post subject: Reply with quote

Notice the very first line:

Code:

local vector dir;


You have to change it to this:

Code:

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.
_________________
There's no signature here. Stop looking for one.
Back to top
View user's profile Send private message
FrikaC
Site Admin


Joined: 08 Oct 2004
Posts: 947

PostPosted: Wed Sep 19, 2007 7:39 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Thu Sep 20, 2007 6:34 am    Post subject: Reply with quote

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:
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:
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:
damage = 1000 - vlen((self.origin+self.view_ofs) - trace_endpos);
if (damage < 1)
   damage = 1;


And make it say:

Code:
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!
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
redrum



Joined: 28 Mar 2007
Posts: 367
Location: Long Island, New York

PostPosted: Thu Sep 20, 2007 2:44 pm    Post subject: Reply with quote

Thanks for the info, I'll give it a shot! (pun intended)
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group