Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 6 Guests
Online:

LATEST FORUM THREADS

»
warfare
CoD4 Map + Mod Releases
Voting menu on maps
CoD+UO General
Hauling 911
CoDBO3 General

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Problems with elevator script
levidhuyvetter
General Member
Since: Apr 15, 2012
Posts: 8
Last: Apr 19, 2012
[view latest posts]
Level 0
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.
Share |
DeekCiti
General Member
Since: Mar 13, 2008
Posts: 1293
Last: Jul 9, 2016
[view latest posts]
Level 8
Category: CoD4 Scripting
Posted: Tuesday, Apr. 17, 2012 05:54 pm
Problem 1, I think can be solved by using, wait (10); instead of elevator[7] waittill ("movedone");. Just a quick look though.

Problem 4, using the hintstring. I think only a hintstring can only be used on a [trigger_use_touch] which I think you are using. Anyways, it should have the following K/V to work as a hintstring:

Key: hintstring
Value: My Text Here

If you wanted to make it so it says, press "F" or whatever button the user has set for the use key, then you would use this:

Key: hintstring
Value: PLATFORM_HOLD_TO_USE

Maybe you are getting an error, because you are using a character in your text that the game doesn't like.
Share |
levidhuyvetter
General Member
Since: Apr 15, 2012
Posts: 8
Last: Apr 19, 2012
[view latest posts]
Level 0
Category: CoD4 Scripting
Posted: Tuesday, Apr. 17, 2012 07:04 pm
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)
Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
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)
Share |
levidhuyvetter
General Member
Since: Apr 15, 2012
Posts: 8
Last: Apr 19, 2012
[view latest posts]
Level 0
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
Share |
DeekCiti
General Member
Since: Mar 13, 2008
Posts: 1293
Last: Jul 9, 2016
[view latest posts]
Level 8
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.
Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
Category: CoD4 Scripting
Posted: Tuesday, Apr. 17, 2012 10:04 pm
Might be an issue with there being only 7 elevators, and you calling elevators[7] causing a undefined entity error, which you dont get cause you have developer disabled.

Arrays are zero-based, so the first entity will go in the [0], second in [1] and the 7th will go in [6]

Ofcourse, if you have 8 elevators, this is not an issue.
Share |
levidhuyvetter
General Member
Since: Apr 15, 2012
Posts: 8
Last: Apr 19, 2012
[view latest posts]
Level 0
Category: CoD4 Scripting
Posted: Tuesday, Apr. 17, 2012 11:45 pm
@DeekCiti i'll post what i have for my hintstring tomorrow and also i try your solution tomorrow.

@IzNoGoD i don't have 7 or 8 elevators i have only one elevator that exists out of 8 parts so that's not the problem but i got a solution already it's in the comments. Thanks anyway
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»