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;
}
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