Moving doorknob

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

Moderator: Core Staff

Post Reply
Major Tom
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: May 9th, 2009, 6:59 am

Moving doorknob

Post by Major Tom » May 9th, 2009, 1:12 pm

Is there a way to make a doorknob move with the door when you activate it? I set the doorknobcrystal xmodel as a script_model and set the targetname value the same as my door, the door works fine but the door knob wont move. Any help?

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

Re: Moving doorknob

Post by waywaaaard » May 9th, 2009, 1:25 pm

give it another targetname and attach the doorknob to the door with ent 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:

Major Tom
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: May 9th, 2009, 6:59 am

Re: Moving doorknob

Post by Major Tom » May 9th, 2009, 1:46 pm

Forgive me for noobeshness but im new to scripting and not sure exactly where to put that.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Moving doorknob

Post by Rezil » May 9th, 2009, 2:10 pm

quoted from modsonline:
Getting Started in Scripting (Moving Things)
2004-07-04 17:17:38
An introduction to scripting for CoD
1) If you want to make something move in the game, you need both mapping and scripting .

2) Anything that moves is a script_whatever (script_model for a model, script_brushmodel for a brush)

3) Anything that moves must have an origin (a script_model inevitably has one of them, a script_brushmodel does not have any by itself).

Now lets get on with the tutorial

To create a script_brushmodel with an origin

OK, lets create moving brushes.

First of all, the brushes should be created representing the object to be moved. I suggest you start with an artistic assembly of paving stones.
You can use any number of brushes.
Then, you create a brush with textures/common/origin, that you can size and place as you want.Later, the center of this brush will be in fact the origin of your script_brushmodel, that you will dimension and place it suits.

Finally, select all your brushes including the brush origin.
Then right-click in the 2d window and select script/brushmodel.

You now have your script_brushmodel.

If you want to select it, SHIFT+ALT+left-click in the 3d window (camera view) and that will select all the brushes of the component. If you want to move a brush individually, you also can, just select it and move it like a normal brush .

If you want to remove a brush component of your script_brushmodel it is not of problem. On the other hand, if you want to add a brush component, it is a little more work.

First, select the script_brushmodel in its entirety (Shift+Alt+left-click). Then, right-click in the 2d window and chose “ungroup entity” (all your brushes are back to normal now).

Add your new brush and follow the above steps to recreate the script_brushmodel.

Like any entity, a script_brushmodel can have keys/values.
We will give ours:

“targetname” “simpson”
*where “targetname” is the key and “simpson” is the value

To recover an entity in a script

By now, you should have a script_model or a script_brushmodel in your map. You’re off to a good start, but now we need to tell the game engine exactly how to handle this situation…so a little scripting is necessary.

- To recover an entity which is the only one to have a particular “targetname” of "simpson"we use:
entity = getent ( "simpson ", "targetname”);

- To recover all the entities which have an identical “targetname” of "simpson" we use:
entities = getentarray ("simpson ", "targetname”);

Now, you are looking at this and saying “If I use getentarray() and only have 1 entity with the “targetname” of “simpson” – will it still work?” The answer is YES…but if you use getent() and have several entities with the “targetname” of “simpson” the script will crash.

In short:
getent ( value, key) turns over an entity
getentarray (value, key) turns over a table of entities.

Threads and the key word "self"

A thread (not a thread which is part of the script) is carried out independently of the remainder of script.

For example, if I make:

function1();
function2();
The function2 will be carried out after the end of the function1.

On the other hand, if I make:

thread function1();
function2();
The function2 will be carried out immediately, at the same time as the function1.

I could also make:

thread function1();
thread function2();
If I want other parts of script to be carried out at the same time as the function1 and the function2.

Now, let us suppose that I make:
simpson1 thread function();
simpson2 thread function();
The same function will be carried out 2 times in parallel.

Following the syntax then:

< entity > thread < function > ;
Indicates in script that when it carries out the function requested, self-service refers to the .

Example:

simpson1 thread function();
simpson2 thread function();
According to the thread "self" will refer to "simpson1" or "simpson2".

If you make your function calls like this:
thread function();
Self "will be inherited" through the self-service of the higher function.

If that confused you, here is a small example:

simpson1 thread function();
simpson2 thread function();

function()
{
thread function2();
}

function2()
{
iprintlnbold ("Hello”);
}

In function(), "self" is either "simpson1", or "simpson2".
In function2() "self" amounts to the same thing. So, the call:
thread function();
is equivalent to:
self thread function();

Here, simpsons.size is the size of the table simpson (that is to say the number of entities having the “targetname” of "simpson ").
For each entity, one launches the thread function(); in which "self" will refer to one of simpsons table.

To make the entities move

OK, so here we are, the answer to your initial question.

This is the syntax to make something move:

< entity > < movement_function > ( < movement_paramaters >, < time >, < acceleration >, < deceleration >);

< entity >: the entity that you want to make move.
< movement_function >: one of the many functions allowing movement tricks in COD, we will see them later.
< movement_paramaters >: according to the function, it is a number of units, an angle, or a vector.
< time >: time what will take the entity to achieve the required movement.
< acceleration >: optional parameter, which indicates for how long the required movement is in phase of acceleration.
< deceleration >: optional parameter, which indicates for how long the required movement is in phase of deceleration.
*IMPORTANT NOTE*
< acceleration > + < deceleration > must be lower or equal to < time >, if not script will crash.

Various functions of movement

In what follows, < vector > is in this form:
(X , Y, Z) Which are you co-ordinates on the map

moveto (< vector >, < time >, < accel >, < decel >)
Moves to the position specified < vector >.

Examples:

simpson moveto ((100,200,300), 1); // will move simpson to the co-ordinates (100,200,300)

simpson1 moveto (simpson2.origin, 1); // will move simpson1 to the same place simpson2 is

movex (< units >, < time >, < accel >, < decel >)
Moves along the specified X axis (< units>, 0, 0) from the current co-ordinates.

Example:

simpson movex ( 10, 1); // will move simpson +10 units on the x axis.

movey ( < units >, < time >, < accel >, < decel >)
Moves along the specified Y axis (< units>, 0, 0) from the current co-ordinates.

Example:

simpson movey ( 20, 1); // will move simpson +20 units on the y axis.

movez ( < units >, < time >, < accel >, < decel >)
Moves along the specified Z axis (< units>, 0, 0) from the current co-ordinates.

Example:

simpson movez ( 30, 1); // will move simpson +30 units on the axis of Z.

movegravity ( < vector >, < time >)
Moves according to a during < time > seconds (complying with the rules of physics). The force of launching depends on the length of the vector.

Example:

simpson movegrativy ( (0,0,100), 2); // will launch simpson into the air 100 units at a physically calculated speed so that simpson will stop have stopped moving after 2 seconds

rotateto (< vector >, < time >, < accel >, < decel >)
Rotation according to 3 axis' (X, Y, Z). Add the angles to the entity.

Examples:

simpson rotateto ( (0, 0, 90), 1); // will make simpson rotate 90 degrees from simpsons angle of origin.

simpson rotateto ( (10, 20, 30), 1); // will add 10, 20 and 30 degrees respectively on, the X, Y and Z axis of the entity simpson.

rotateyaw ( < angle >, < time >, < accel >, < decel >)
To add < angle > degrees on the axis "yaw ".

rotatepitch ( < angle >, < time >, < accel >, < decel >)
To add < angle > degrees on the axis "pitch".

rotateroll ( < angle >, < time >, < accel >, < decel >)
To add < angle > degrees on the axis "roll".

rotatevelocity ( < vector >, < time >)
Rotates an entity degrees per second for a specified time .

Example:

simpson rotatevelocity ( (0, 0, 90), 10); // makes the entity simpson rotate 90 degrees per seconds on the axis of Z, for 10 seconds.

To wait for the end of the movement

To wait a specific number of seconds for the movement to end:
wait (< time >);

If that is not feasible, to wait for the real end of the movement:

< entity > waittill ("rotatedone”);
if the movement is a rotation

< entity > waittill ("movedone”);
if the movement is a displacement

A small example: a door which slides

For a practical exercise, we will make a door which slides vertically (upwards).
In this example, we will not try to do something reusable, therefore we will use getent () instead of getentarray ().

1) MAPPING

Create a script_brushmodel for the door, keep in mind to include a brush origin inside; give it the “targetname” "slide".
Create a trigger_use (with textures/common/trigger and give it the “targetname” "slider_trigger ".

2) SCRIPTING

Here is the script, and, having read all that precedes you should be able to include/understand how it goes.
main()
{
thread door_slider ();
}

door_slider ()
{
door = getent ("slide ", "targetname”);
trig = getent ("slider_trigger ", "targetname”);
while (1)
{
trig waittill ("trigger");
door movez (80, 2, 0, 0.5);
door waittill ("movedone”);
wait (4);
door movez (-80, 2, 0, 0.5);
door waittill ("movedone”);
}
}

StrYdeR
I would like to thank Valoche for laying down the groundwork for this tutorial
Read this.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Moving doorknob

Post by Drofder2004 » May 9th, 2009, 4:15 pm

Read Lev's post not Rez's. Readin all that will just confuse you.

Post your current script.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Moving doorknob

Post by Rezil » May 9th, 2009, 4:53 pm

Forgive me for noobeshness but im new to scripting and not sure exactly where to put that.
He is new to scripting so he needs to know the basics probably.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Major Tom
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: May 9th, 2009, 6:59 am

Re: Moving doorknob

Post by Major Tom » May 9th, 2009, 9:37 pm

Drofder2004 wrote:Read Lev's post not Rez's. Readin all that will just confuse you.

Post your current script.

Code: Select all

main()
{
thread door1();
}
door1()
{
door = getent ("door","targetname");
trig = getent ("door_trigger","targetname"); 
while (1)
{
trig waittill ("trigger");
wait (2);
door rotateyaw ( 90, 2, 1.5, 0.5);
door waittill ("rotatedone");
trig waittill ("trigger");
door rotateyaw ( -90, 2.1, 1.5, 0.5);
}
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Moving doorknob

Post by Drofder2004 » May 9th, 2009, 10:00 pm

Rez|l wrote:He is new to scripting so he needs to know the basics probably.
You posted a wall of unstructured text, reading that makes it like that makes it hard to understand.

Code: Select all

main()
{
thread door1();
}
door1()
{
door = getent ("door","targetname");
handle = getent("handle","targetname");
trig = getent ("door_trigger","targetname"); 
wait 0.05;
handle linkTo(door);

while (1)
{
trig waittill ("trigger");
wait (2);
door rotateyaw ( 90, 2, 1.5, 0.5);
door waittill ("rotatedone");
trig waittill ("trigger");
door rotateyaw ( -90, 2.1, 1.5, 0.5);
}
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

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

Re: Moving doorknob

Post by Nightmare » May 9th, 2009, 10:28 pm

Code: Select all

main()
{
	thread door1();
}

door1(){
	door = getent ("door","targetname");
	handle = getent("handle","targetname");
	trig = getent ("door_trigger","targetname"); 
	wait 0.05;
	handle linkTo(door);

	while (1)
	{
		trig waittill ("trigger");
		door rotateyaw (90, 2, 1.5, 0.5);
		door waittill ("rotatedone");
		trig waittill ("trigger");
		door rotateyaw (-90, 2, 1.5, 0.5);
		door waittill ("rotatedone");
	}
}
Fixed it up a bit.
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]

Major Tom
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: May 9th, 2009, 6:59 am

Re: Moving doorknob

Post by Major Tom » May 10th, 2009, 2:02 am

Ah thanks got it :D
And since we are already on the subject how can i add a second door to the script?

User avatar
Soviet
Core Staff
Core Staff
Posts: 7762
Joined: April 23rd, 2005, 9:12 pm

Re: Moving doorknob

Post by Soviet » May 10th, 2009, 3:59 am

just give it a different targetname (like door2) for all the new components and duplicate the script, changing the targetnames in it.

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

Re: Moving doorknob

Post by Nightmare » May 10th, 2009, 5:13 am

Example:

Code: Select all

main()
{
   thread door1();
   thread door2();
}

door1(){
   door = getent ("door_1","targetname");
   handle = getent("handle_1","targetname");
   trig = getent ("door_trigger_1","targetname");
   wait 0.05;
   handle linkTo(door);

   while (1)
   {
      trig waittill ("trigger");
      door rotateyaw (90, 2, 1.5, 0.5);
      door waittill ("rotatedone");
      trig waittill ("trigger");
      door rotateyaw (-90, 2, 1.5, 0.5);
      door waittill ("rotatedone");
   }
}

door2(){
   door = getent ("door_2","targetname");
   handle = getent("handle_2","targetname");
   trig = getent ("door_trigger_2","targetname");
   wait 0.05;
   handle linkTo(door);

   while (1)
   {
      trig waittill ("trigger");
      door rotateyaw (90, 2, 1.5, 0.5);
      door waittill ("rotatedone");
      trig waittill ("trigger");
      door rotateyaw (-90, 2, 1.5, 0.5);
      door waittill ("rotatedone");
   }
}
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]

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Moving doorknob

Post by Drofder2004 » May 10th, 2009, 9:57 am

Use an array? or would that be to complex to do at this stage? :D
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Major Tom
CJ Wannabe
CJ Wannabe
Posts: 17
Joined: May 9th, 2009, 6:59 am

Re: Moving doorknob

Post by Major Tom » May 10th, 2009, 3:33 pm

Lol probably. Thanks for all the help:P

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

Re: Moving doorknob

Post by Nightmare » May 10th, 2009, 7:48 pm

Drofder2004 wrote:Use an array? or would that be to complex to do at this stage? :D
Thought of that at first, but I would rather keep it simple.
No use implementing a more complex system when he still has to get used to the basics.
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 1 guest