Forum

Some questions for my singleplayer mod...

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Re: Some questions for my singleplayer mod...

Postby Daya » Mon Jun 17, 2013 7:57 pm

So I checked the Hand Grenade tutorial found in the site. Going into this while knowing this won't go well, I attempted anyway.

I put ".float axecharge;" at line 221 in defs.qc

I included this inside the W_FireAxe function (The lightning bolt is used as a placeholder as I said earlier) :

Code: Select all
*/
void() Charge =
{
   if (self.axecharge == 0)
      sound (self, CHAN_WEAPON, "player/charge.wav", 1, ATTN_NORM);
   
   if (self.axecharge >= 15)
   {
      self.axecharge = 15;
      self.punchangle_x = -2;
   }
   else
   {
      self.axecharge = self.axecharge + 1;
      sprint (self, "*");
   }
   self.attack_finished = time + 0.1;
};

void() W_FireAxe = //AKA W_FireLaser
{
   local   vector   source;
   local   vector   org;

   if (self.axecharge > 3) //if the charge value is above 3, The laser will be shot (I copy/pasted W_FireLightning's code)
   {
      if (self.t_width < time)
      {
         sound (self, CHAN_WEAPON, "weapons/gauntl2.wav", 1, ATTN_NORM);
         self.t_width = time + 0.6;
      }
      self.punchangle_x = -2;


      org = self.origin + '0 0 16';
      
      traceline (org, org + v_forward * self.axecharge * 10, TRUE, self); // I assume this is the lightning bolt's length, so I added in the charge value

      WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
      WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
      WriteEntity (MSG_BROADCAST, self);
      WriteCoord (MSG_BROADCAST, org_x);
      WriteCoord (MSG_BROADCAST, org_y);
      WriteCoord (MSG_BROADCAST, org_z);
      WriteCoord (MSG_BROADCAST, trace_endpos_x);
      WriteCoord (MSG_BROADCAST, trace_endpos_y);
      WriteCoord (MSG_BROADCAST, trace_endpos_z);

      LightningDamage (self.origin, trace_endpos + v_forward*4, self, 40);
      
      self.axecharge = 0;
      sprint (self, "\n");
      self.attack_finished = time + 0.7;   
   }
   else // If the charge's value is below 3, the traditionnal axe stuff comes in
   {
      makevectors (self.v_angle);
      source = self.origin + '0 0 16';
      traceline (source, source + v_forward*64, FALSE, self);
      if (trace_fraction == 1.0)
         return;
      
      org = trace_endpos - v_forward*4;

      if (trace_ent.takedamage)
      {
         trace_ent.axhitme = 1;
         SpawnBlood (org, '0 0 0', 20);
         T_Damage (trace_ent, self, self, 20);
      }
      else
      {   // hit wall
         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
         WriteCoord (MSG_BROADCAST, org_x);
         WriteCoord (MSG_BROADCAST, org_y);
         WriteCoord (MSG_BROADCAST, org_z);
      }
      self.axecharge = 0;
      sprint (self, "\n");
      self.attack_finished = time + 0.5;   
   }   
};


And I put this between the death and jump code inside client.qc:

Code: Select all
   
   if (self.weapon == IT_AXE && self.axecharge > 0 && !self.button0)
   {
      player_axe1();      
      W_FireAxe();


And I end up with this when I compile: http://image.noelshack.com/fichiers/201 ... e-prob.png

So that means copy-pasting W_FireLightning wasn't the thing to do. What should I do then?


Oh and before I forgot once again, I'd like for the weapon viewmodel to tilt up & down whever I look up or down, similar to nQuake. How can I do this?
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Re: Some questions for my singleplayer mod...

Postby gnounc » Tue Jun 18, 2013 12:31 am

Not certain, but it looks like LightningDamage hasnt been defined yet. So you need to add whats known as a forward declaration, or a prototype.
somewhere before you call lightning damage paste this in the global scope:

Code: Select all
void LightningDamage(vector p1, vector p2, entity from, float damage);


and see if that fixes your compile problems



A prototype lets the compiler know what arguments to expect so it can check for obvious errors when you call it.
You have to prototype any function that hasnt been defined before you use it.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: Some questions for my singleplayer mod...

Postby Daya » Tue Jun 18, 2013 9:00 am

I put your code just before the axe code, it compiled nicely (I think), I started quake, tried to go to the start map, but I got this instead:

http://image.noelshack.com/fichiers/201 ... rerror.png

Man, this laser axe stuff is more complicated than it should.
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Re: Some questions for my singleplayer mod...

Postby gnounc » Tue Jun 18, 2013 10:54 am

That I dont know anything about I'm afraid.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: Some questions for my singleplayer mod...

Postby r00k » Tue Jun 18, 2013 1:50 pm

What that error means is that you modified the defs.qc file. :O

Anytime you add your own variables, it's best to add them at the BOTTOM of defs.qc or make a complete new file, ie defs2.qc (and add it in progs.src below defs.qc)...
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Some questions for my singleplayer mod...

Postby frag.machine » Tue Jun 18, 2013 1:57 pm

Daya wrote:I put your code just before the axe code, it compiled nicely (I think), I started quake, tried to go to the start map, but I got this instead:

http://image.noelshack.com/fichiers/201 ... rerror.png

Man, this laser axe stuff is more complicated than it should.



The message about "progdefs.h out of date" is a nasty error, but luckly quite easy to avoid. Instead of adding a ".float axecharge;" at defs.qc, just place it at the top of weapons.qc and this error will disappear. I know, that's just plain crazy, but it works. :)

The actual error cause is a behavior I never completely understood: the QuakeC compiler calculates a CRC based on the number of entity fields declared in defs.qc (but only in this file, ignoring any other .qc files - go figure... ). This CRC is stored into the progs.dat and later compared by the engine against the entity structures declared in progdefs.h. If they don't match the engine refuses to execute the progs.dat and halts. That's why moving the declaration to say, weapons.qc will avoid the error.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2073
Joined: Sat Nov 25, 2006 1:49 pm

Re: Some questions for my singleplayer mod...

Postby r00k » Tue Jun 18, 2013 2:24 pm

i quickly made something thats close to your lazer axe rail thing. U might need to tweak some values to get what u want.

Basically as you hold down the firebutton (axe selected), it will increase the laser 10 units ever time + 0.1sec
once it reaches 200 units (about 1/3 the distance of the lg), the laser reset to 0 and builds back up.

all i did was make a copy of fireAXE and replace with this..
Code: Select all
.float rail_dist;
void() W_FireRail =
{
   local   vector   source;
   local   vector   org;

   makevectors (self.v_angle);
   
   source = self.origin + '0 0 16';
   
   traceline (source, source + v_forward * self.rail_dist, FALSE, self);
   
   if (trace_fraction == 1.0)
      return;
   
   org = trace_endpos - v_forward * 4;

   if (trace_ent.takedamage)
   {
      SpawnBlood (org, '0 0 0', 20);
      T_Damage (trace_ent, self, self, 500);
//optional : reset rail here   
//self.rail_dist = 1;
   }
   else
   {   // hit wall
      sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
      WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
      WriteByte (MSG_BROADCAST, TE_GUNSHOT);
      WriteCoord (MSG_BROADCAST, org_x);
      WriteCoord (MSG_BROADCAST, org_y);
      WriteCoord (MSG_BROADCAST, org_z);
   }
};

then in w_Attack, instead of calling the axe anim/w_FireAxe, i call this
Code: Select all
   if (self.weapon == IT_AXE)
   {
      sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
      /*
      r = random();
      if (r < 0.25)
         player_axe1 ();

      else if (r<0.5)
         player_axeb1 ();

      else if (r<0.75)
         player_axec1 ();

      else
         player_axed1 ();
      */
      W_FireRail();
      
      self.attack_finished = time + 0.1;
      self.rail_dist = self.rail_dist + 10;
      
      if (self.rail_dist > 200)
         self.rail_dist = 0;
   }


then at the bottom of W_WeaponFrame, i added this
Code: Select all
   if (self.button0 == FALSE)
      self.rail_dist = 1;


it works but like i said you might want to adjust the rate of fire the speed of the increase or whatever to suit your needs..
you could also reset self.rail_dist AFTER it hits something

Opps! just saw your message at the top of this page.
my code wont axe if less and charge up, it just extends the rail length until it hits something or max length of 200 is reached.

it will kill enemies instantly though ;)
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Some questions for my singleplayer mod...

Postby Daya » Tue Jun 18, 2013 3:46 pm

I tried R00k's code, and I got a blocked swinging axe animation with a looping axe swinging sound when I hold the button, meaning the axe attack is constantly looped at 0.1 seconds of framerate even though i'm not pressing the button right now. The distance variable is still working when I'm holding the key, and I have to switch to another weapon to escape this. (this code in client.qc was still there, but i replaced W_FireAxe by r00k's W_FireRail:

Code: Select all
   if (self.weapon == IT_AXE && self.axecharge > 0 && !self.button0)
   {
      player_axe1();     
      W_FireAxe();


There's also other codes related to the old laser axe code in weapons.qc that I forgot, but you can still check the Hand Grenade tutorial in the site to know where I put them.)

So I tried to backpedal to my latest laseraxe code but now everything is messed up, it cannot recognize spawnblood, damage, and other variables. I'm completely lost right now.

I hate to do this, but here's the link to my mod for those who want to solve my problem : http://www.mediafire.com/?tzw23oeya4rrgvc . Just extract it inside your quake or darkplaces folder under a folder named "doake".
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Re: Some questions for my singleplayer mod...

Postby r00k » Tue Jun 18, 2013 4:16 pm

ok lemme look at your code (wow that dl was 10mbs!) :P
ill try to fix the axe/rail the way u want all charged up maybe a finer incremental increase like +1 faster once hit the next attack comes 0.5 seconds later?

find this in weapons.qc
void LightningDamage (self.origin, trace_endpos + v_forward*4, self, 40);

and delete it.

then in player.qc all the w_firerails change back to w_fireaxe and u can recompile where u last left off.

ill post a fix to the axe/laser to include your charge code. :D
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Some questions for my singleplayer mod...

Postby Daya » Tue Jun 18, 2013 4:51 pm

Just as a little reminder, I don't want it to be a continuous laser, but a one-shot laser like the railgun. And I use the lightning bolt as a placeholder until I do a flat model to materialize the laser (since I don't think darkplaces includes a transparent flat laser model).
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Re: Some questions for my singleplayer mod...

Postby r00k » Tue Jun 18, 2013 5:26 pm

right,
but if u hold the fire button down to increase the range its firing at each increment in range. Do u just want it to build up to max distance then "discharge"?

oof the reason u have constANT firing of the axe is u added w_fireaxe in playerprethink ! :P
Last edited by r00k on Tue Jun 18, 2013 5:48 pm, edited 1 time in total.
r00k
 
Posts: 1108
Joined: Sat Nov 13, 2004 10:39 pm

Re: Some questions for my singleplayer mod...

Postby Daya » Tue Jun 18, 2013 5:33 pm

If the player releases the firebutton during the charge, the laser will be shot given the charge's value during release.

If possible, I'd like for the charge to hold when it reaches its maximum value (something a bit below the original lightning bolt's maximum range). If not, the laser must be fired when i reaches its maximum value.
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Re: Some questions for my singleplayer mod...

Postby Daya » Thu Aug 08, 2013 4:19 pm

Bumping this thread (hoping I'm not getting warnings for this...) because I decided to continue doing my singleplayer mod (Also this thread should be moved to another location, like "Programming Help").

Anyway, I'm still looking for a way to make my charge weapon a thing : For reminder, it replaces the axe: under a short value of charge when releasing the fire button, the code executes the W_FireAxe code. Above said value, a Q3 Railgun-like laser will be shot, but not an hitscan one (aside from the fact it's instantaneous [i can use the lightning model as a placeholder]) as its length depends from the charge value at the time the firebutton has been released.

I'm also still looking for a way to "port" Team Fortress' Assault Canon. I have the sourcecode of version 2.5, but looking at HEAVY.qc , I can't understand it.
Daya
 
Posts: 12
Joined: Mon May 13, 2013 9:21 am

Previous

Return to Programming Tutorials

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest