area
elevator
var
z_level=1;
list/L = list();
proc
findDoor(){
if(L.len == 0)
createList();
for(var/Other/Turfs/door/elevatorDoor/o in L) {
if(o.z == src.z_level) {
return o;
}
}
}
createList()
for(var/Other/Turfs/door/elevatorDoor/o in world) {
if(istype(o.loc.loc,/area/elevator))
L.Add(o);
}
elevator_Panel
parent_type = /obj;
icon = 'Turf.dmi';
icon_state = "elevpanel";
proc
go(var/t) {
var/area/elevator/a = src.loc.getArea();
var/Other/Turfs/door/s = a.findDoor();
s.locked = TRUE;
s.Close();
while(a.z_level != t) {
if(t > a.z_level) { //3-->1, FALSE
a.z_level++;
}
else if(t < a.z_level) { //2--> 1
a.z_level--
}
for(var/mob/M in a) {
if(M.client){
spawn(-1) {
quakeEffect(M,25);
M.loc = locate(M.x,M.y,a.z_level);
}
} else {
spawn(25)
M.loc = locate(M.x,M.y,a.z_level);
}
}
sleep(25);
for(var/obj/o in a) {
if(istype(o,/Other/Turfs/door))
continue;
o.loc = locate(o.x,o.y,a.z_level);
}
viewers() << "Ding! Reached Floor [a.z_level]";
var/Other/Turfs/door/o = a.findDoor();
o.locked = FALSE;
o.Open();
if(a.z_level != t)
o.locked = TRUE;
}
}
console
var/busy = FALSE:
verb
goToLevel() {
set src in view(1);
var/t = input("Which level?","Elevator") as null|anything in list(1,2,3);
if(!t) return;
if(t > 3) return;
else
busy = TRUE;
src.go(text2num(t));
busy = FALSE;
}
panel
icon_state = "switch";
Click()
var/elevator_Panel/console/C = locate();
var/area/elevator/a = C.loc.getArea();
if(usr in a) return;
if(a.z_level != usr.z) {
if(C.busy)
usr << "Sorry, wait for the elevator to stop operations.";
else
viewers() << "Clicked.";
C.busy = TRUE;
C.go(usr.z);
viewers() << "Ding!";
C.busy = FALSE;
} else
usr << "The elevator is here. Go in already.";
Problem description:
Hope someone can take a look at this for me. It's a bit messy and maybe not efficient but it's my elevator system. It works fine going from floor 1 to 2, floor 2 to 3, floor 1 to 3, but coming back down there seems to be problem. Specifically, when it's floor 3 - 1 and I use the goToLevel verb to go to 1 before the door closes, it does everything but stays at floor 3 and repeats forever. And yes the door Open() have sleep() in them.
Can you add a "world << "[t]" " in the while() to check the t and make sure it's actually getting a num.