elevator with rotating hatches

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
mayorsaide
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: September 16th, 2009, 5:11 am

elevator with rotating hatches

Post by mayorsaide » September 16th, 2009, 5:24 am

ok heres my problem, i have a elevator with a seperate script_brushmodel for the hatch, i can get it to rotate with script, i can get it to move in line with the elevator giving the illusion it is a part of the elevator, problem is i cant get the trigger that rotates the hatch to stay with the hatch, i have tried linkto() script and the best i can get it to do is, it all works fine ele, hatch and hatchswitch all move down together on 1st trigger press to move ele..press the move ele trigger again, it all move up no worries...but then i try trigger it a 3rd time to move down again and i get a runtime error saying, enablelinkto() already linked to entity or something...been agonising for days over this script please help...
main()
{
level.elevatormoving = false; // Elevator is not moving yet
level.elevatorfloor = 1; // Elevator starts at ground (Remember to change this if you move the elevator model to start at a different floor)
level.elevatormovespeed = 3; // Time to take, to move from ground to floor1 (floor1 to floor2 will be half of this)
level.elevatorfloor1 = -352; // Distance from ground to floor1

thread elevator1_start(); // Start thread which gets everything going
}

elevator1_start()
{
elevatormodel1 = getent ("elv1", "targetname");
hatch = getent ("elv1hatch","targetname");
elevator1up = getent ("elv1call1","targetname");
elevator1down = getent ("elv1call2","targetname");
elevator1hatchswitch = getent ("elv1hatchswitch","targetname");







elevator1up thread elevator_thinkup(); // Start thread for up trigger
elevator1down thread elevator_thinkdown(); // Start thread for down trigger

}

elevator_thinkup()
{
while (1) // Loop forever
{
self waittill ("trigger"); // Wait for someone to press use on the trigger
if (!level.elevatorMoving) // Check to see if elevator is already moving
{
thread elevator_move("up"); // Start thread to move elevator up
}
}
}

elevator_thinkdown()
{
while (1) // Loop forever
{
self waittill ("trigger"); // Wait for someone to press use on the trigger
if (!level.elevatorMoving) // Check to see if elevator is already moving
{
thread elevator_move("down"); // Start thread to move elevator down
}
}
}





elevator_move(direction)
{
elevatormodel1 = getent ("elv1", "targetname");
hatch = getent ("elv1hatch","targetname");
elevator1hatchswitch = getent ("elv1hatchswitch","targetname");
level.elevatormoving = true;


wait(1);

if (direction=="up")
{
if (level.elevatorfloor==1)

{


elevatormodel1 movez (level.elevatorfloor1,level.elevatormovespeed);
hatch movez (level.elevatorfloor1,level.elevatormovespeed);
elevator1hatchswitch enablelinkto();
elevator1hatchswitch linkto(hatch);

elevatormodel1 waittill("movedone");

level.elevatorfloor=2;
}

}
else
{
if (level.elevatorfloor==2)

{
elevatormodel1 movez (0-level.elevatorfloor1,level.elevatormovespeed);
hatch movez (0-level.elevatorfloor1,level.elevatormovespeed);

elevatormodel1 waittill("movedone");

level.elevatorfloor=1;
}

}
level.elevatormoving=false;
}

that is my script so far, i havent included the rotate part cause it seems pointless, please dont say to use the diff ele script ie movez, because if the ele is down and someone hits the down trggier it just moves down again ie through the floor =p please help

User avatar
waywaaaard
Core Staff
Core Staff
Posts: 2214
Joined: February 6th, 2006, 3:18 pm
Location: Germany/Bayern

Re: elevator with rotating hatches

Post by waywaaaard » September 16th, 2009, 10:38 am

if your trigger shall move with the brushmodel u need to

Code: Select all

trig enableLinkTo();
trig linkto(ent);
THAT HANDS WERE NOT TRACED!
visit my blog: Link
Soviet wrote:Yeah, watch out, Peds will hit you with his +5 D-Battleaxe of homosexuality :roll:

mayorsaide
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: September 16th, 2009, 5:11 am

Re: elevator with rotating hatches

Post by mayorsaide » September 16th, 2009, 1:12 pm

Code: Select all

main()
{
    level.elevatormoving = false;                                
    level.elevatorfloor = 1;                                    
    level.elevatormovespeed = 3;                                
    level.elevatorfloor1 = -352;                                   
    
    thread elevator1_start();     
    thread hatch1_rotate();                                
}

elevator1_start() 
{ 
    elevatormodel1 = getent ("elv1", "targetname");    
    elevator1call1 = getent ("elv1call1","targetname");    
    elevator1call2 = getent ("elv1call2","targetname");     
    hatch = getent ("elv1hatch","targetname");         
    elevator1up = getent ("elv1switchD","targetname");    
    elevator1down = getent ("elv1switchU","targetname");    
    elevator1hatchswitch = getent ("elv1hatchswitch","targetname");


            elevator1hatchswitch enablelinkto();
            elevator1up enablelinkto();
            elevator1down enablelinkto();
            wait(0.05);
            elevator1hatchswitch linkto(hatch);
            elevator1up linkto(elevatormodel1);
            elevator1down linkto(elevatormodel1);


    


    elevator1up thread elevator_thinkup();                        
    elevator1down  thread elevator_thinkdown();               
    elevator1call1 thread elevator_thinkcall(1);               
    elevator1call2 thread elevator_thinkcall(2);                

}

elevator_thinkup()
{ 
    while (1)                                                  
    { 
        self waittill ("trigger");                                 
        if (!level.elevatorMoving)                                
        {
            thread elevator_move("up");                        
        }
    } 
} 

elevator_thinkdown()
{ 
    while (1)                                                   
    { 
        self waittill ("trigger");                                
        if (!level.elevatorMoving)                                
        {
            thread elevator_move("down");                     
        }
    } 
}


elevator_thinkcall(callfloor)
{
    while (1)                                                   
    { 
        self waittill ("trigger");                              
        if (!level.elevatorMoving)                              
        { 
            elevator_call(callfloor);                             
        }
    } 
}

elevator_call(callfloor)
{
    elevatormodel1 = getent ("elv1", "targetname");
    hatch = getent ("elv1hatch","targetname");
    elevator1up = getent ("elv1switchD","targetname");    
    elevator1down = getent ("elv1switchU","targetname"); 
    elevator1hatchswitch = getent ("elv1hatchswitch","targetname");
    level.elevatormoving = true;
    
    if (callfloor==1)
    {
        if (level.elevatorfloor==2)
        {
            elevatormodel1 movez (0-level.elevatorfloor1,level.elevatormovespeed);
            hatch movez (0-level.elevatorfloor1,level.elevatormovespeed);
            elevatormodel1 waittill("movedone");
            level.elevatorfloor=1;
        }

    }
    else if (callfloor==2)
    {
        if (level.elevatorfloor==1)
        {
            elevatormodel1 movez (level.elevatorfloor1,level.elevatormovespeed);
            hatch movez (level.elevatorfloor1,level.elevatormovespeed);
            elevatormodel1 waittill("movedone");
            level.elevatorfloor=2;
        }

    }

    level.elevatormoving = false;
}


elevator_move(direction)
{
    elevatormodel1 = getent ("elv1", "targetname");
    hatch = getent ("elv1hatch","targetname");
    elevator1up = getent ("elv1switchD","targetname");    
    elevator1down = getent ("elv1switchU","targetname"); 
    elevator1hatchswitch = getent ("elv1hatchswitch","targetname");
    level.elevatormoving = true;
    wait(1);  
    if (direction=="up")
    {
        if (level.elevatorfloor==1)
 
        {


            elevatormodel1 movez (level.elevatorfloor1,level.elevatormovespeed);
            hatch movez (level.elevatorfloor1,level.elevatormovespeed);
            elevatormodel1 waittill("movedone");            

            level.elevatorfloor=2;

        }

    }
    else
    {
        if (level.elevatorfloor==2)
   
        {
            elevatormodel1 movez (0-level.elevatorfloor1,level.elevatormovespeed);
            hatch movez (0-level.elevatorfloor1,level.elevatormovespeed);
            elevatormodel1 waittill("movedone");

            level.elevatorfloor=1;
        }

    }
    level.elevatormoving=false;    

}






hatch1_rotate()
{
      hatch = getent("elv1hatch","targetname");
      trig = getent("elv1hatchswitch","targetname");
      while(1)
   {
      trig waittill ("trigger");
      hatch rotateroll(90,2);
      hatch waittill("rotatedone");
      wait (4);
      hatch rotateroll(-90,2);
      hatch waittill("rotatedone");
   }
}
i had the enablelinkto() in the wrong spot =p fixed it up and added triggers inside the elevator to move with it aswell as the static call triggers on the outside, hatches triggers and hatches ow move with the elevator all works perfect. feel free to use the script as it was a long process to get it to all work right so it may save you time. oh btw i realise i have the call1up functioning the down switch that was just a typo i couldnt be bothered fixing since i tested it and it all worked how i wanted it to so i didnt want to mess with the script again incase i messed it up somehow. thank you ^_^

User avatar
Nightmare
Core Staff
Core Staff
Posts: 2688
Joined: January 12th, 2006, 10:09 pm
Contact:

Re: elevator with rotating hatches

Post by Nightmare » September 19th, 2009, 11:17 pm

I simplified your code a bit, in the process I also made the script a lot more flexible.
You can now have an unlimited amount of floors without having to modify anything within the script, with the exception of the variable "level.floors".

Code: Select all

main()
{
	level.eleFloor = 1;
	level.eleIsMoving = false;
	level.eleDist = 128; 	//Distance the elevator will be traveling
	level.eleTime = 3;	//Time to reach floor
	level.floors = 2;	//Amount of floors

	thread eleStart();
}

eleStart(){
	getent("elv1hatchswitch","targetname") enableLinkTo();
	getent("elv1switchU","targetname") enableLinkTo();
	getent("elv1switchD","targetname") enableLinkTo();
	wait 0.05;
	getent("elv1hatchswitch","targetname") linkto(getent("elv1hatch","targetname"));
	getent("elv1switchU","targetname") linkTo(getent("elv1","targetname"));
	getent("elv1switchD","targetname") linkTo(getent("elv1","targetname"));

	getent("elv1switchU","targetname") thread eleCheckU();
	getent("elv1switchD","targetname") thread eleCheckD();
	for(i=1;i<=level.floors;i++)
		getent("elv1call"+i,"targetname") thread eleCheckCall(i);
	getent("elv1hatch","targetname") thread checkHatch();
}

eleCheckU(){
	self waittill("trigger");
	thread eleMove(level.eleFloor+1);
	self thread elecheckU();
}

eleCheckD(){
	self waittill("trigger");
	thread eleMove(level.eleFloor-1);
	self thread elecheckD();
}

eleCheckCall(i){
	self waittill("trigger");
	thread eleMove(i);
	self thread eleCheckCall(i);
}

eleMove(floor){
	if(!level.eleIsMoving)
		if(floor>0 && floor<=level.floors){
			level.eleIsMoving=true;
			tempDist = (floor - level.eleFloor)*level.eleDist;
			getent("elv1","targetname") moveZ(tempDist,level.eleTime,level.eleTime/2,level.eleTime/2);
			getent("elv1hatch","targetname") moveZ(tempDist,level.eleTime,level.eleTime/2,level.eleTime/2);
			getent("elv1","targetname") waittill("movedone");
			level.eleFloor = floor;
			level.eleIsMoving=false;
		}
}

checkHatch(){
	getent("elv1hatchswitch","targetname") waittill("trigger");
	self rotateroll(90,2);
	self waittill("rotatedone");
	wait 4;
	self rotateroll(-90,2);
	self waittill("rotatedone");
	self thread checkHatch();
}
Coding is Poetry. Mapping is Art.
"Cause im the sexiest mapper ever...except for nm, that sexy man" - Soviet

-=[CoDJumper.com Movies]=-
[Ambush] || [Backlot] || [Bloc] || [Bog] || [Broadcast] || [Chinatown] || [Countdown]
[Crash] || [Creek] || [Crossfire] || [District] || [Downpour] || [Killhouse] || [Overgrown]
[Pipeline] || [Shipment & Wetwork] || [Showdown] || [Strike] || [Vacant]

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests