Forum

The func_elevator challenge

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

The func_elevator challenge

Postby OneManClan » Tue Aug 13, 2013 4:09 pm

Hi guys.

THE PROBLEM:
The elevator doesn't move.

OBJECTIVE
To make a fully functioning elevator. I'm not sure if I'm close (but with some minor stupid detail messing things up), or WAYYY off track. Anyway here's the idea, any feedback welcome:

Firstly, the definition of the func_elevator itself:

Code: Select all
void() func_elevator =
{

   self.solid = #SOLID_BSP;
   self.movetype = MOVETYPE_PUSH;
   self.blocked = SUB_Null;
   self.use = SUB_Null;
   self.classname = "func_elevator";
   setmodel (self, self.model);
   setsize (self, self.mins , self.maxs);
   setorigin (self, self.origin);
   

   self.nextthink = self.ltime + 0.1;
   self.think = elevator_think;
 }




1. path_elevatorstop (to identify floors)
These are simpler alternatives to path_corners, they have unique targetnames, and store the spots where the elevator has to stop. They also have a variable '.button_pressed', which stores whether someone has pressed the accompanying button.

Code: Select all
// a simpler replacement for path_corner
//
 void() func_elevatorstop =
 {

   setorigin (self, self.origin);
   self.use = ElevatorButtonPress;


 }

void () ElevatorButtonPress =
{
   self.button_pressed = 1;  // this does get set to 1 when the button is pushed
};




2. buttons (regular buttons)
One for each floor (and duplicates in the elevator itself). Each one has a .target - its' accompanying path_elevatorstop.


3. Identifying which buttons were pushed. dprints show that the function below ALWAYS returns 0, even when e.button_pressed == 1!?
Code: Select all
// get the next target
float () elevator_next =
{


      // find the first func_elevatorstop entity
      e = find (world, classname, "func_elevatorstop");
      while (e)
      {
      
         
         //check if the button has been pressed
         if (e.button_pressed == 1)
         {

            // store it as our current target = lets go to this floor
            self.goalentity = e;
            return 1;
   
         
         }
         
      e = find (e, targetname, self.target);
      }

      // no buttons have been pressed
      self.goalentity = world; //This is ALWAYS the result?!?
      return 0;

   
}



And finally, since self.goalentity is always == world, the following function means the elevator just sits there.

Code: Select all
void() elevator_think =
{
   

         // if we just arrived at a stop, mark it as 0
         if(self.goalentity)
         self.goalentity.button_pressed = 0;

            if(elevator_next())
            {
               
               SUB_CalcMove (self.goalentity.origin, 200, elevator_think);
               // i believe the above line means we dont enter this function
               // again until we reach self.goalentity.origin

               
            }
         else
            {
               
               self.velocity = '0 0 0';
               self.think = elevator_think;
               self.nextthink = self.ltime + 3; // check again in 2 seconds

            }
            




}



There it is. Sorry for the chunk of code, but I'm kind of stuck, and have no idea whether it's a stupid syntax error, or some fundamental flaw in the implementation.

thanks
OneManClan
 
Posts: 243
Joined: Sat Feb 28, 2009 2:38 pm

Re: The func_elevator challenge

Postby Dr. Shadowborg » Tue Aug 13, 2013 11:23 pm

Maybe I'm misunderstanding what you want to do here, but extras_r4 has an elevator that has buttons that move with it.

Also Missionpack2 / DoE's source has multi-stop elevators as well.
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Re: The func_elevator challenge

Postby r00k » Wed Aug 14, 2013 1:03 am

i think if goal_entity.buttonpressed ever equals 1 ur mod will crash
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Re: The func_elevator challenge

Postby frag.machine » Wed Aug 14, 2013 2:31 pm

First, I suggest you first change the .think delay to a smaller value, the standard 0.1 sec is good and wont bog down the game. After this, place some dprints where entity status should be changed, this may bring some clues.
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

Re: The func_elevator challenge

Postby OneManClan » Wed Aug 14, 2013 4:57 pm

Thanks for the responses guys.

The solution (credit: Spike) has been found!:

SUB_CalcMove(self.goalentity.origin - self.mins, 200, lift_think);

I can't comment further because I'm still learning about exactly how mins, maxs absmin etc etc work.
Next challenge: to make the buttons in the lift move with the lift!! :shock:
OneManClan
 
Posts: 243
Joined: Sat Feb 28, 2009 2:38 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest