Forum

Bomb doesn´t explode

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Bomb doesn´t explode

Postby Stealth Kill » Sat Feb 16, 2008 4:23 am

Hi,

I have a problem.
My "bomb" should explode after 30seconds if it touches the "func_bomb_target" brush but it doesnt explode.



Here is my code


Modified Grenate code
Code: Select all
/*
================
W_FireC4
================
*/
void() W_FireC4 =
{
   local   entity bomb, mpuff;
   
   self.currentammo = self.ammo_c4a = self.ammo_c4a - 1;
   
   sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);

   self.punchangle_x = -2;

   bomb = spawn ();
   bomb.owner = self;
   bomb.movetype = MOVETYPE_TOSS;
   bomb.solid = SOLID_BBOX;
   bomb.classname = "bomb";
      
   

   makevectors (self.v_angle);

   if (self.v_angle_x)
      bomb.velocity = v_forward*0 + v_up * 0 + crandom()*v_right*0 + crandom()*v_up*0;
   else
   {
      bomb.velocity = aim(self, 10000);
      bomb.velocity = bomb.velocity * 0;
      bomb.velocity_z = 0;
   }

   bomb.avelocity = '0 0 0';

   bomb.angles = vectoangles(bomb.velocity);
   
   bomb.touch = BombTouch;
   
   setmodel (bomb, "progs/c4.mdl");
   setsize (bomb, '0 0 0', '0 0 0');      
   setorigin (bomb, self.origin);
};


func_bomb_target

Code: Select all
void() func_bomb_target =
{

   self.angles = '0 0 0';
   self.movetype = MOVETYPE_PUSH;
   self.solid = SOLID_NOT;
   
   setmodel (self, self.model);

if (other.classname != "bomb")
{
BombThink;
}

   if (!(self.spawnflags & 1))
      self.model = string_null;
};


i tried with

if (other.touch != "bomb")
{
BombThink;
}

but game crashed.



BombTouch code

Code: Select all
void() BombTouch =
{
   if (other == self.owner)
      return;      // don't explode on owner
   if (other.takedamage == DAMAGE_AIM)
   {
      BombExplode();
      return;
   }

if (other.classname != "func_bomb_target")
{
BombThink;
}

   sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);   // bounce sound
   if (self.velocity == '0 0 0')
      self.avelocity = '0 0 0';
};



BombThink code

Code: Select all
void() BombThink =
{

   local   entity bomb;


   bomb.nextthink = time + 30;
   bomb.think = BombExplode;
};



Bombexplode code is the same as GreanadeExplode.
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Postby leileilol » Sat Feb 16, 2008 5:02 am

Your "BombThink;"'s are missing ()s.
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby Spike » Sat Feb 16, 2008 5:11 am

Firstly: you're not actually calling the BombThink function.
Its only a function call if it includes the brackets after it. Otherwise its a useless statement that means absolutly nothing.

BombThink; <- this does feck all
BombThink(); <- this is what you should have used.

Secondly, its quite likly that your bomb will touch your trigger several times (every single frame it moves in, as well as any frames where force_retouch is set). Every frame that it touches, it will reset the nextthink timer - so it'll never blow up if a cunning user manages to find the right triggers elsewhere on the map (force_retouch stuff).

Thirdly, your func_bomb_target is a spawn function. not a touch function. Using 'other' in there is generally a bad plan.

Fourthly, your func_bomb_target is not solid. It cannot be touched. Ever. I don't know wether you wanted it as trigger or bsp, (if trigger, it still cannot be touched, but can do the touching - which your code does not attempt to support - see note 3).

if (other.touch != "bomb")
makes no sense. I don't see why it would crash though.
I guess its frikqcc treating other.touch as a string... but functions should be low enough that they're within the string table.
But still, in that spawn function, 'other' is not set to anything meaningful. I don't see why that would result in a crash. Compiler error sure (with fteqcc definatly) but not crash (frikqcc will compile it, even though it makes no sense).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby FrikaC » Sat Feb 16, 2008 5:31 pm

Frikqcc made some hacks to make the nehahra code compile, I thought I removed them, but I guess some of the newer versions have them in there still. I really need to get around to fixing that. My recommendation is to just use fteqcc however.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Stealth Kill » Wed Apr 16, 2008 7:50 pm

This is my new code

void() func_bomb_target =
{

self.movetype = MOVETYPE_PUSH;
self.solid = SOLID_BSP;
setsize (self, self.mins , self.maxs);
setorigin (self, self.origin);
setmodel (self, self.model);
self.classname = "func_bomb_target";
return;

if (other.classname != "bomb")
BombThink();
return;


};


void() BombTouch =
{

sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);
if (self.velocity == '0 0 0')
self.avelocity = '0 0 0';
};

void() BombThink =
{

self.nextthink = time + 30;
self.think = BombExplode;

};


it doesn´t explode can someone help?
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Postby Electro » Wed Apr 16, 2008 11:56 pm

Doing a return; at the end of a void function does nothing.... it's already leaving it ;)

Secondly, having the
return;
after
self.classname = "func_bomb_target";

means it's returning out of the function, and your
if (other.classname != "bomb")
is never actually being reached.


Another thing to keep in mind, is that you should probably consider having the func_bomb_target spawn the bomb model. Otherwise when you do BombExplode or whatever, I assume you will be doing a remove... in which case you'll be removing the func_bomb_target. So it wouldn't be reusable from then on (it'd be gone). Could be wrong though, not sure what you're doing with your exploding.
Benjamin Darling
http://www.bendarling.net/

Reflex - In development competitive arena fps combining modern tech with the speed, precision and freedom of 90's shooters.
http://www.reflexfps.net/
Electro
 
Posts: 312
Joined: Wed Dec 29, 2004 11:25 pm
Location: Brisbane, Australia

Postby Elite_Babe1990 » Mon Aug 25, 2008 5:54 am

You forgot () <-s
I may be cte but I can pwn u at halo!
User avatar
Elite_Babe1990
 
Posts: 4
Joined: Thu Aug 14, 2008 10:22 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest