| Author |
Topic: Problems with elevator script |
| levidhuyvetter |
General Member Since: Apr 15, 2012 Posts: 8 Last: Apr 19, 2012 [view latest posts] |
|
|
|
Category: CoD4 Scripting Posted: Tuesday, Apr. 17, 2012 03:23 pm |
 |
Hi,
I have some problems with my elevator script. This is my script:
Code: main() {
level.elevatorUp = false;
level.elevatorMoving = false;
thread elevator_start();
}
elevator_start() {
elevatortrigger = getentarray("elevatortrigger","targetname");
if (isdefined(elevatortrigger)) {
for (i = 0; i < elevatortrigger.size; i++) {
elevatortrigger[i] thread elevator_think();
}
}
}
elevator_think() {
for(;;) {
self waittill ("trigger");
if (!level.elevatorMoving) {
if (!level.elevatorUp) {
thread elevator_moveUp();
}
if (level.elevatorUp) {
thread elevator_moveDown();
}
}
}
}
elevator_moveUp() {
elevator = getentarray("elevator","targetname");
elevatordoor = getent("elevatordoor","targetname");
level.elevatorMoving = true;
elevatordoor playsound ("elevatordoor");
elevatordoor movey (-95, 4, 0.5, 0.5);
elevatordoor waittill ("movedone");
wait 4;
elevatordoor playsound ("elevatordoor");
elevatordoor movey (95, 4, 0.5, 0.5);
elevatordoor waittill ("movedone");
if (isdefined(elevator)) {
for (i = 0; i < elevator.size; i++) {
elevator[i] movez (2364, 10, 0.5, 0.5);
}
elevator[7] waittill ("movedone");
}
level.elevatorUp = true;
level.elevatorMoving = false;
thread elevator_start();
}
elevator_moveDown() {
elevator = getentarray("elevator","targetname");
elevatordoor = getent("elevatordoor","targetname");
level.elevatorMoving = true;
if (isdefined(elevator)) {
for (i = 0; i < elevator.size; i++) {
elevator[i] movez (-2364, 10, 0.5, 0.5);
}
elevator[7] waittill ("movedone");
}
elevatordoor playsound ("elevatordoor");
elevatordoor movey (-95, 4, 0.5, 0.5);
elevatordoor waittill ("movedone");
wait 4;
elevatordoor playsound ("elevatordoor");
elevatordoor movey (95, 4, 0.5, 0.5);
elevatordoor waittill ("movedone");
level.elevatorUp = false;
level.elevatorMoving = false;
thread elevator_start();
}
The elevator exists out of a couple of brushes and there is a door on the downside but not on the upside. There are also 2 use_touch triggers one on the upside an one on the downside, they have the same targetname.
First problem: When the elevator is up and i press "F" to go down the elevator does go down but when i get down the door there already opened and is already closing. How do write in the code do wait till the elevator's (wich is an array) move is done to execute the code to open the door? the trick i used by selecting a part of the array doesn't work.
Problem 2: When the elevator is up and you ar down and you press "F" the elevator should come down open the doors and then go up again. But when the doors close it stays at the ground and then you have to press "F" again but then the doors open again and close en only then the elevator goes up. I know how to solve this problem but i don't know how to write it in cod. I have to get which of the triggers in the array is pressed and due to that run another part of script that does the right thing. For example if you are down the code looks and see the elevator is up and then looks which one of the triggers in the array you triggered and if he sees that the trigger at the downside is triggered it threads for example something called "elevator_comeDown()" where there is the right code to move the elevator down open the door, close the door and move the elevator up again. someone has an idea how to determine which trigger of an array is triggered (in an if statement or something).
Problem 3: this is not really a problem but something i'm planning to do. the elevator is a box of brushes with 2 openings. I want to make a door in both of the openings (when the elevator comes down one door opens and when the elevator arrives at the top bot of these doors open) but those doors have to move with the elevator so they need to have the same targetname as the parts of the elevator but i have to select them by a different targetname in the script to open them. so the should need to have some kind of a second targetname to open them. someone has any ideas?
Problem 4: this is not really about scripting but it's a small problem so i put it here. I entered a hintstring for the triggers of the brush but when i step into the trigger in the game it says "unlocalized(mytext)" instead of just my text. Also i want it to say "Press "F" to use the elevator" but not everybody uses F to interact with triggers so how do i enter this in my entity inspector?
I'm sorry for my long post but i'm trying to solve these problems for a long time and they were stacking up so if someone could help me to solve them i can work again on the rest of my map.
I'm also sorry for my bad english. |
 |
|
|
| DeekCiti |
 |
General Member Since: Mar 13, 2008 Posts: 1293 Last: Jul 9, 2016 [view latest posts] |
|
|
|
|
| levidhuyvetter |
General Member Since: Apr 15, 2012 Posts: 8 Last: Apr 19, 2012 [view latest posts] |
|
|
|
|
| IzNoGoD |
General Member Since: Nov 29, 2008 Posts: 694 Last: Nov 10, 2012 [view latest posts] |
|
|
|
Category: CoD4 Scripting Posted: Tuesday, Apr. 17, 2012 07:43 pm |
 |
either remove the elevator_start() from the elevator_moveup() and elevator_movedown() parts, or remove the for(;;) from the elevator_think. If you decide to remove the elevator_start, remove the thread part of the thread elevator_up and thread elevator_down from elevator start too.
Or just use this script i just wrote:
Code:
main()
{
level.elevator_moving=false;
level.elevator_down=-1; //-1 for being up, 1 for being down
trigs=getentarray("elevatortrigger","classname");
eledoor=getent("elevatordoor","targetname");
elevators=getentarray("elevator","targetname");
for(i=0;i<trigs.size;i++)
trigs[i] thread elevator_wait(elevators,eledoor);
}
elevator_wait(elevators,door)
{
while(true)
{
self waittill("trigger");
if(!level.elevator_moving)
{
level.elevator_moving=true;
door playsound("elevatordoor");
door movey(95,4,0.5,0.5);
door waittill("movedone");
wait 4;
door playsound("elevatordoor");
door movey(-95,4,0.5,0.5);
door waittill("movedone");
for(i=0;i<elevators.size;i++)
{
elevators[i].targetorigin=elevators[i].origin+(0,0,2364);
elevators[i] movez(level.elevator_down*2364,10,0.5,0.5);
}
wait 10;
while(!alldone(elevators))
wait 0.05;
level.elevator_down*=-1;
level.elevator_moving=false;
}
}
}
alldone(elevators)
{
for(i=0;i<elevators.size;i++)
{
if(elevators[i].origin!=elevators[i].targetorigin)
return false;
}
return true;
}
Untested, as always with my code, but it should work. (unless my fingers played tricks on me while typing) |
 |
|
|
| levidhuyvetter |
General Member Since: Apr 15, 2012 Posts: 8 Last: Apr 19, 2012 [view latest posts] |
|
|
|
Category: CoD4 Scripting Posted: Tuesday, Apr. 17, 2012 08:36 pm |
 |
IzNoGoD writes...Quote: either remove the elevator_start() from the elevator_moveup() and elevator_movedown() parts, or remove the for(;;) from the elevator_think. If you decide to remove the elevator_start, remove the thread part of the thread elevator_up and thread elevator_down from elevator start too.
Or just use this script i just wrote:
Code:
main()
{
level.elevator_moving=false;
level.elevator_down=-1; //-1 for being up, 1 for being down
trigs=getentarray("elevatortrigger","classname");
eledoor=getent("elevatordoor","targetname");
elevators=getentarray("elevator","targetname");
for(i=0;i<trigs.size;i++)
trigs[i] thread elevator_wait(elevators,eledoor);
}
elevator_wait(elevators,door)
{
while(true)
{
self waittill("trigger");
if(!level.elevator_moving)
{
level.elevator_moving=true;
door playsound("elevatordoor");
door movey(95,4,0.5,0.5);
door waittill("movedone");
wait 4;
door playsound("elevatordoor");
door movey(-95,4,0.5,0.5);
door waittill("movedone");
for(i=0;i<elevators.size;i++)
{
elevators[i].targetorigin=elevators[i].origin+(0,0,2364);
elevators[i] movez(level.elevator_down*2364,10,0.5,0.5);
}
wait 10;
while(!alldone(elevators))
wait 0.05;
level.elevator_down*=-1;
level.elevator_moving=false;
}
}
}
alldone(elevators)
{
for(i=0;i<elevators.size;i++)
{
if(elevators[i].origin!=elevators[i].targetorigin)
return false;
}
return true;
}
Untested, as always with my code, but it should work. (unless my fingers played tricks on me while typing)
I think in your code when the elevator is triggered when it's up (and you are up) the door will also open. Tell me if i'm wrong |
 |
|
|
| DeekCiti |
 |
General Member Since: Mar 13, 2008 Posts: 1293 Last: Jul 9, 2016 [view latest posts] |
|
|
|
Category: CoD4 Scripting Posted: Tuesday, Apr. 17, 2012 09:34 pm |
 |
levidhuyvetter writes...Quote: The solution to my first problem worked fine thanks for that.
But when i use PLATFORM_HOLD_TO_USE for my hintstring it just says unlocalized(PLATFORM_HOLD_TO_USE)
Yeah, For some reason, the waittill movedone doesn't work correctly with move x,y or z. Don't know why. I always just used a wait time, matched with the time defined in the move function. Glad it works, just hope it doesn't pose another problem later.
Can you post what you are using currently for your hintstring?
What type of trigger it is, and or how you created it. Does the trigger work ingame to trigger your script?
I know it works because I've used it and I copied it directly from one of my maps to make sure it was correct. I'm sure it's a simple fix.
Problem 3, I think this can be fixed by first, giving them the same targetname as the elevator, yes, but then giving them a sub name:
Key: script_noteworthy
Value: doors_a
Key: script_noteworthy
Value: doors_b
That way you can collect them in script and tell them to do something else. I don't know if it is the best way, but I've done it this way before. I'm sure someone with better experience in scripting can give you better advice. Or you could just give them separate targetnames, and move them separately when the elevator moves, and slide them in the direction when needed without giving them a script_noteworthy.
edited on Apr. 17, 2012 02:48 pm by DeekCiti
I also just noticed that you do Not hide your triggers when a player starts the elevator. You will need to do this, otherwise a second player could potentially hit the other trigger and start moving the elevator in ways you do not want, basically messing up all the movements for the rest of the map. You can fix it by doing this:
Code:
self waittill ("trigger");
self maps\mp\_utility::triggerOff();
Then turn them back on when all the moving is complete, by changing the off, to on. " maps\mp\_utility::triggerOn(); "
You could even create a separate thread called "buttonsOff" and "buttonsOn" or something with the functions and variables defined to turn on and off your triggers so no other players can't mess with them while this thing is moving. Just a heads up. |
 |
|
|
| IzNoGoD |
General Member Since: Nov 29, 2008 Posts: 694 Last: Nov 10, 2012 [view latest posts] |
|
|
|
|
| levidhuyvetter |
General Member Since: Apr 15, 2012 Posts: 8 Last: Apr 19, 2012 [view latest posts] |
|
|
|
|
|
|
mp_TempleCall of Duty: Mods: Multiplayer (624.12Kb)
|