Forum

Activate an entity(MOVETYPE_BOUNCE) via impulse?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Activate an entity(MOVETYPE_BOUNCE) via impulse?

Postby Moi » Wed Jul 21, 2010 11:58 am

hi everyone.
i'm looking for a simple solution to let a map object fall from the ceiling when a keyboard key is pressed. My first idea was to create a func_train which checks if a global variable is set to 0 or 1. if the variable is set to 1 (via an impulse) the func_train starts following its waypoints.
However before completing this idea I thought of a better one. I was planning to create a solid map entity and reset its self.movetype once a special key is pressed. that's how i tried it:

Code: Select all
//basically just a little modified func_train
void() func_impulse_train =
{

self.solid = SOLID_BSP;

//start as 'pushable' entity since trainactivated is initialized with 0
   if(self.trainactivated==0){self.movetype = MOVETYPE_PUSH;}

//once impulse 22 is activated, let the entity bounce down
   else if(self.trainactivated==1){self.movetype = MOVETYPE_BOUNCE;}
   

   self.blocked = train_blocked;
   self.use = train_use;
   self.classname = "train";

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);

// start trains on the second frame, to make sure their targets have had
// a chance to spawn
   self.nextthink = self.ltime + 0.1;

//restart the function to recheck the state of trainactivated
   self.think = func_impulse_train;
   

};


For some reason it won't work. I'd be glad to hear from you guys :D
Moi
 
Posts: 12
Joined: Tue Jul 20, 2010 10:47 pm

Postby Spike » Wed Jul 21, 2010 12:16 pm

nextthink works differently depending on movetype.
for movetype_push its dependant upon self.ltime.
for anything else, its dependant upon time.

movetype_bounce will clip the object against others as though its a bounding box.
considering you're making a bsp object, your origin starts at '0 0 0'.
so your movetype_bounce will never get anywhere.

also, please don't use your spawn function as a think function. its not pretty.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Moi » Wed Jul 21, 2010 12:30 pm

Spike wrote:nextthink works differently depending on movetype.
for movetype_push its dependant upon self.ltime.
for anything else, its dependant upon time.

Thanks for the quick reply. I should have added that I also included the gyro and sagdoll libraries, so I have no idea if they have an influence on the code.

movetype_bounce will clip the object against others as though its a bounding box.

That's the effect I'm looking for :D

considering you're making a bsp object, your origin starts at '0 0 0'.
so your movetype_bounce will never get anywhere.

I'm not sure if I'm understanding you correctly. The object I was talking about was created in worldcraft using the tietoEntity feature. So it's definitely visible on the map and also works with my code when initialized with MOVE_BOUNCE(when I reverse the if case in 'my' code).

also, please don't use your spawn function as a think function. its not pretty.

Hehe by now you should've guessed that you are talking to a QC n00b. Thanks for the advice :D
Moi
 
Posts: 12
Joined: Tue Jul 20, 2010 10:47 pm

Postby Spike » Wed Jul 21, 2010 2:08 pm

Moi wrote:I'm not sure if I'm understanding you correctly. The object I was talking about was created in worldcraft using the tietoEntity feature. So it's definitely visible on the map and also works with my code when initialized with MOVE_BOUNCE(when I reverse the if case in 'my' code).

geometry created and present inside the bsp? then its a bsp object, and its origin will be '0 0 0', even if its mins/max are in one tiny non-central part of the map.
And because its origin is '0 0 0', its not going to collide against the world in the place that you actually expected.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Moi » Wed Jul 21, 2010 2:48 pm

Spike wrote:geometry created and present inside the bsp? then its a bsp object, and its origin will be '0 0 0', even if its mins/max are in one tiny non-central part of the map.
And because its origin is '0 0 0', its not going to collide against the world in the place that you actually expected.


Well, funny thing is that it does fall and collide against the world when it's initialized as self.movetype = MOVETYPE_BOUNCE. But again calling "impulse 22" while it's falling won't turn it to MOVETYPE_PUSH as the (reversed) code checking the variable suggests.Sorry for my vague description of "it won't work" in my first post btw.

Anyway are you suggesting finding the position of func_impulse_train in my map after "impulse 22" was called and then reset the entity's movetype? Or even better: How would an experienced QC coder solve the problem :D
Moi
 
Posts: 12
Joined: Tue Jul 20, 2010 10:47 pm

Postby frag.machine » Wed Jul 21, 2010 3:04 pm

One way would be to create a BSP type entity that behaves like a func_wall, adding a use() function that, when triggered, removes the original entity and spawns a new one with MOVETYPE_BOUNCE in the same place. And make your impulse code to find the entity and fire its use() function instead setting the global var.
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: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Moi » Thu Jul 22, 2010 1:22 pm

thanks frag.machine. I've tried it the way you described but failed to implement it due to my limited qc knowledge. but i came up with a similar way, which is kinda a mix of my original idea and your idea:

Code: Select all
//misc.qc
void() func_dropped_weight =
{
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_PUSH;

   self.blocked = weight_blocked;

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);
   

};



Code: Select all
//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
   e.movetype = MOVETYPE_BOUNCE;
   }



Am I missing anything QC related in that code that might cause issues in future?
Moi
 
Posts: 12
Joined: Tue Jul 20, 2010 10:47 pm

Postby frag.machine » Thu Jul 22, 2010 3:59 pm

Moi wrote:thanks frag.machine. I've tried it the way you described but failed to implement it due to my limited qc knowledge. but i came up with a similar way, which is kinda a mix of my original idea and your idea:

Code: Select all
//misc.qc
void() func_dropped_weight =
{
   self.solid = SOLID_SLIDEBOX;
   self.movetype = MOVETYPE_PUSH;

   self.blocked = weight_blocked;

   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);
   

};



Code: Select all
//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
   e.movetype = MOVETYPE_BOUNCE;
   }



Am I missing anything QC related in that code that might cause issues in future?


In a quick look I'd say you should check if the entity exists before changing .movetype:
Code: Select all
//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }

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: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Thu Jul 22, 2010 4:15 pm

MOVETYPE_PUSH has a distinct preference for SOLID_BSP, although DP doesn't really care.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Moi » Thu Jul 22, 2010 4:22 pm

frag.machine wrote:
In a quick look I'd say you should check if the entity exists before changing .movetype:
Code: Select all
//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }



Thanks. I guess it also would be a good idea to remove e if find() isn't successful, wouldn't it?
Btw does find return some king of a null pointer if the entity is not found?



MOVETYPE_PUSH has a distinct preference for SOLID_BSP, although DP doesn't really care.

yeah I had to use SOLID_SLIDEBOX to stop the crashing in makaqu.
Moi
 
Posts: 12
Joined: Tue Jul 20, 2010 10:47 pm

Postby frag.machine » Thu Jul 22, 2010 7:01 pm

Moi wrote:
frag.machine wrote:
In a quick look I'd say you should check if the entity exists before changing .movetype:
Code: Select all
//ImpulseCommands

if (self.impulse == 22)
   {
   local entity e;
   e=find(world,classname,"func_dropped_weight" );
        if (e != world) {
          e.movetype = MOVETYPE_BOUNCE;
        }
   }



Thanks. I guess it also would be a good idea to remove e if find() isn't successful, wouldn't it?
Btw does find return some king of a null pointer if the entity is not found?


There's no such thing as "null" in QuakeC; if find() fails, a reference to entity 0 (== world) is returned. It's safe to just ignore it.
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: 2090
Joined: Sat Nov 25, 2006 1:49 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest