Forum

applying health to weapons

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

applying health to weapons

Postby redrum » Mon Oct 08, 2007 8:41 pm

I'm trying to make it that weapons can be shot at and blow up. Kinda like explo boxes.
I took some code from explo_box and tried to apply it to the RL, but I could not get it working.
I figured this should be easy enough for me to handle but I guess not :cry:
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 Urre » Tue Oct 09, 2007 8:09 am

First of all, weapons aren't solid in the way they need to be so they could be shot at. Then, they don't have a death function. If you add those (solidity should be SOLID_BBOX, death function could/should be spawning an explosion at their origin, and putting them in a respawn state, just like if you had picked them up), and give them some health, you should have it working, as long as the respawn function sets them back to SOLID_BBOX, rather than SOLID_TRIGGER.
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby xaGe » Tue Oct 09, 2007 10:35 am

That reminds me of my favorite UT mutator explodable weapons & ammo...
User avatar
xaGe
 
Posts: 461
Joined: Wed Mar 01, 2006 8:29 am
Location: Upstate, New York

Postby redrum » Tue Oct 09, 2007 2:26 pm

ok, thanks.
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 redrum » Wed Oct 10, 2007 10:10 pm

Ok, trying it with healthpacks now.

I made this function:

Code: Select all
void() health_explode =                                                               
{
   self.takedamage = DAMAGE_NO;
   self.classname = "explo_box";

   T_RadiusDamage (self, self, 160, world, "");
   WriteByte (MSG_MULTICAST, SVC_TEMPENTITY);
   WriteByte (MSG_MULTICAST, TE_EXPLOSION);
   WriteCoord (MSG_MULTICAST, self.origin_x);
   WriteCoord (MSG_MULTICAST, self.origin_y);
   WriteCoord (MSG_MULTICAST, self.origin_z+32);
   multicast (self.origin, MULTICAST_PHS);
                remove (self);

   self.nextthink = time + 10;                                                 self.think = SUB_regen;
                stuffcmd (other, "bf\n");
   self.model = string_null;
                self.owner = other;
                activator = other;
   SUB_UseTargets();
};


I put it just below void() StartItem.

Then I added code to void() item_health

Code: Select all
void() item_health =
{       
   self.touch = health_touch;

   if (self.spawnflags & H_ROTTEN)
   {
                   self.solid = SOLID_BBOX;
                   self.movetype = MOVETYPE_NONE;
      precache_model("maps/b_bh10.bsp");
      precache_sound("items/r_item1.wav");
      setmodel(self, "maps/b_bh10.bsp");
      self.noise = "items/r_item1.wav";
      self.healamount = 20;
      self.healtype = 0;
                self.health = 20;
           self.th_die = health_explode;
           self.takedamage = DAMAGE_AIM;
   }
   else
   if (self.spawnflags & H_MEGA)
   {
                   self.solid = SOLID_BBOX;
                   self.movetype = MOVETYPE_NONE;
      precache_model("maps/b_bh100.bsp");
      precache_sound("items/r_item2.wav");
      setmodel(self, "maps/b_bh100.bsp");
      self.noise = "items/r_item2.wav";
      self.healamount = 100;
      self.healtype = 2;
                self.health = 20;
           self.th_die = health_explode;
           self.takedamage = DAMAGE_AIM;
   }
   else
   {
                   self.solid = SOLID_BBOX;
                   self.movetype = MOVETYPE_NONE;
      precache_model("maps/b_bh25.bsp");
      precache_sound("items/health1.wav");
      setmodel(self, "maps/b_bh25.bsp");
      self.noise = "items/health1.wav";
      self.healamount = 30;
      self.healtype = 1;
                                self.health = 20;
                   self.th_die = health_explode;
                   self.takedamage = DAMAGE_AIM;
   }
   setsize (self, '0 0 0', '32 32 56');
   StartItem ();
};


I also changed void() SUB_regen to this:

Code: Select all
void() SUB_regen =
{
   self.model = self.mdl;                                                    // restore original model
   self.solid = SOLID_BBOX;                                                  // allow it to be touched again
   sound (self, CHAN_VOICE, "items/itembk2.wav", .8, ATTN_NORM);             // play respawn sound
   setorigin (self, self.origin);
};


They explode, but don't respawn :cry:
Any help?
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 Oct 10, 2007 10:37 pm

I don't need to heat up my head, it's simple.

Just erase remove(self); from health_explode(). ;)
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Postby redrum » Thu Oct 11, 2007 2:30 am

Respawns now, but I can't grab it. It's solid.
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 redrum » Thu Oct 11, 2007 2:47 am

Changed SUB_regen() back to SOLID_TRIGGER;

Now I can walk thru the paks but I still don't get them?
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 Urre » Thu Oct 11, 2007 8:19 am

There are some issues with your code I'll try to point out, but I'm not sure it will change anything in practice.

First of all, are you going to make all items explodable? If so, it will all be so much easier to do, since then you can simply change some basic item functions and be done with it, instead of largely recoding certain items.

I'm going to assume you want all items to be explodable. First of all, remove ALL the new lines from the health box spawning code (the ones where you set self.solid, self.movetype, self.health, self.th_die and self.takedamage), so that it's just like the original health box. Now, instead of having these things in the health box specificly, we scroll up to a function called PlaceItem. First, change the solidity line to say SOLID_BBOX instead of SOLID_TRIGGER. Then add the same lines you removed except for self.solid and self.movetype (self.health, self.th_die and self.takedamage) with their appropriate values, health could be 20 just like before, and takedamage be DAMAGE_AIM, and make self.th_die point to a function called ItemDie. Then also add a line which says self.blocked = self.touch; This is used to save the touch function when it gets removed by dying, just like the model is saved in self.mdl to be restored once it respawns. We use .blocked because it's unused for items. This way we get the same functionality over all items in the game, awesome huh! (God I sound like a tutorial, maybe I should convert this to one). Rename the function you called health_explode to ItemDie, and let's change some things in it.

Remove the first two lines (self.takedamage and self.classname). self.takedamage is already set to DAMAGE_NO when it dies, so it's redundant, and changing the items classname is generally a bad idea. Then remove the stuffcmd line and the self.owner line. There is no use for these lines, since "other" points to something unknown to us. Then change activator to point to self.enemy. self.enemy is set in Killed, when the item dies, this way SUB_UseTargets works the way it should.

Now we have the death function working, so let's get on to SUB_Regen. In SUB_Regen, change self.solid to SOLID_BBOX, this is to make sure it can be shot again. Then add the following lines: self.health = 20;
self.takedamage = DAMAGE_AIM;
self.th_die = ItemDie;
self.touch = self.blocked;
Now we've restored all the important parts of the item, so it can be picked up and shot again. Hope it works! If it doesn't, feel free to post the code after you've done the changes, so we can see if I or you missed something.

NOTE: make sure to remove any dying or exploding code from ALL other items as well, because they will now automaticly do it because of our changes, it'd be bad to have separate info in those, which might mess it up
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby redrum » Fri Oct 12, 2007 2:40 pm

Thanks Urre,
I just had to remove: self.th_die = ItemDie;
from SUB_regen() and it worked!

I was getting errors b/c ItemDie(); was below SUB_regen();
and SUB_regen(); was looking for it. So I commented it out.
I also tried putting ItemDie(); above SUB_regen();
Then I got errors b/c it couldn't find SUB_regen(); (go figure.)
It seems to be working pretty good now though:)

I did want to have all the items explodable, you assumed correctly.
The only thing though, I want different items to cause more damage than others.
I want to try this out on my own first. But I'll probably need more help :?
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 Seven » Fri Oct 12, 2007 6:57 pm

Hi redrum,

can you do me a favour (and maybe others too), by post your current version (where all items have the same damage).
Because it sounds very interesting; but by following the thread I am too confused which lines must go in which .qc file.

I would be very thankful, if you could post your working modification in one post.
Really looking forward shooting a health box and watch it explode :)
Thank you very much for your effort and everybody who helped to find the solution.

Regards,
Seven
Seven
 
Posts: 301
Joined: Sat Oct 06, 2007 8:49 pm
Location: Germany

Postby redrum » Fri Oct 12, 2007 8:17 pm

I spoke too soon.
There are still some problems :cry:
I guess when I removed self.th_die = ItemDie; from SUB_regen()
it caused some trouble.

If I shoot an item now, it disappears, but it's still there (invisible).
I shot a health pack, it disappeared, then I walked into the area and I kept getting health until I was maxed out!

Seven, when it's done without any bugs, I will post the code!
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 redrum » Sat Oct 13, 2007 5:35 pm

Ok, got it to compile without commenting anything out.
I had to put void() ItemDie; at the bottom of defs.qc.
Still same problems though.

Here's what I have now:

Code: Select all
void() SUB_regen =
{       
   self.model = self.mdl;                                                // restore original model
   self.solid = SOLID_BBOX;                                              // allow it to be touched again
        self.health = 20;
        self.takedamage = DAMAGE_AIM;
        self.th_die = ItemDie;
        self.touch = self.blocked;
   sound (self, CHAN_VOICE, "items/itembk2.wav", .8, ATTN_NORM);         // play respawn sound
   setorigin (self, self.origin);
};


void() ItemDie =                                                               

        T_RadiusDamage (self, self, 80, world, "");
        WriteByte (MSG_MULTICAST, SVC_TEMPENTITY);
        WriteByte (MSG_MULTICAST, TE_EXPLOSION);
        WriteCoord (MSG_MULTICAST, self.origin_x);
        WriteCoord (MSG_MULTICAST, self.origin_y);
        WriteCoord (MSG_MULTICAST, self.origin_z+32);
        multicast (self.origin, MULTICAST_PHS); 

        self.nextthink = time + 10; 
        self.think = SUB_regen;
        self.model = string_null; 
        activator = self.enemy;
        SUB_UseTargets();
};


If I pick up an item everything is fine.

If I shoot an item, it explodes and disappears, but let's say it was a healthpak and I my health was maxed out. So, technically I'm not able to pick it up. There would be an invisible block where the healthpak should be, even though it just exploded?
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 Urre » Sat Oct 13, 2007 6:59 pm

I knew I forgot something!

Add self.touch = SUB_Null; and self.solid = SOLID_NOT; to ItemDie, and it should work
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby redrum » Sat Oct 13, 2007 11:43 pm

OK, working much better.
The mega-healthpak is giving me trouble.
After it's first re-spawn it stops working, weird.
It adds the normal 100 on the first touch, but after that I walk right thru it?
All other items are working perfect!
What could be the problem?
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

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest