Inside3D!
     

applying health to weapons
Goto page 1, 2  Next
 
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: Mon Oct 08, 2007 8:41 pm    Post subject: applying health to weapons Reply with quote

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 Crying or Very sad
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Tue Oct 09, 2007 8:09 am    Post subject: Reply with quote

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



Joined: 01 Mar 2006
Posts: 329
Location: Upstate, New York

PostPosted: Tue Oct 09, 2007 10:35 am    Post subject: Reply with quote

That reminds me of my favorite UT mutator explodable weapons & ammo...
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
redrum



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

PostPosted: Tue Oct 09, 2007 2:26 pm    Post subject: Reply with quote

ok, thanks.
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
redrum



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

PostPosted: Wed Oct 10, 2007 10:10 pm    Post subject: Reply with quote

Ok, trying it with healthpacks now.

I made this function:

Code:
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:
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:
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 Crying or Very sad
Any help?
_________________
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 Oct 10, 2007 10:37 pm    Post subject: Reply with quote

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

Just erase remove(self); from health_explode(). Wink
_________________
There's no signature here. Stop looking for one.
Back to top
View user's profile Send private message
redrum



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

PostPosted: Thu Oct 11, 2007 2:30 am    Post subject: Reply with quote

Respawns now, but I can't grab it. It's solid.
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
redrum



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

PostPosted: Thu Oct 11, 2007 2:47 am    Post subject: Reply with quote

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



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Thu Oct 11, 2007 8:19 am    Post subject: Reply with quote

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
_________________
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: Fri Oct 12, 2007 2:40 pm    Post subject: Reply with quote

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 Confused
_________________
Welcome to the Overlook Hotel 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
Seven



Joined: 06 Oct 2007
Posts: 19
Location: Germany

PostPosted: Fri Oct 12, 2007 6:57 pm    Post subject: Reply with quote

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 Smile
Thank you very much for your effort and everybody who helped to find the solution.

Regards,
Seven
Back to top
View user's profile Send private message
redrum



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

PostPosted: Fri Oct 12, 2007 8:17 pm    Post subject: Reply with quote

I spoke too soon.
There are still some problems Crying or Very sad
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 69.113.123.178:27500
Back to top
View user's profile Send private message Send e-mail
redrum



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

PostPosted: Sat Oct 13, 2007 5:35 pm    Post subject: Reply with quote

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



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Sat Oct 13, 2007 6:59 pm    Post subject: Reply with quote

I knew I forgot something!

Add self.touch = SUB_Null; and self.solid = SOLID_NOT; to ItemDie, and it should work
_________________
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: Sat Oct 13, 2007 11:43 pm    Post subject: Reply with quote

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 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
Goto page 1, 2  Next
Page 1 of 2

 
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