Array help

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

Moderator: Core Staff

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

Array help

Post by Major Tom » August 14th, 2010, 5:34 am

So I recently started working with arrays and I have a question about them.
How do I get trigger 1 to open door 1 with out having to put the numbers in?
Any help would be appreciated.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 14th, 2010, 6:58 am

say u have 10 triggers and 10 doors named respectively - so trig1 is to open door1, trig2 is to open door2 and so on.

the code below lets the ten triggers open the corresponding doors (in the example, the doors move upstairs)

Code: Select all

main()
{
	for (i = 1; i < 11; i++)
		thread openMe(i);
}

openMe(i)
{
	door = getEnt("door"+i, "targetname");
	trig = getEnt("trig"+i, "targetname");
	
	while (1)
	{
		trig waittill("trigger");
		door moveZ(100, 1);
	}
}

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

Re: Array help

Post by Drofder2004 » August 14th, 2010, 1:08 pm

Thats not an array, thats just scripting.

You can do the following.

Make your doors.
Give them a targetname of simply "door".

Now make your triggers.
(Do not give them a targetname)

Next select your first door, then select your first trigger and press W to link them.
Do this for all combinations, making sure to select the DOOR first.

Now

Code: Select all

main()
{
   doors = getentarray("door", "targetname");
   for(i=0li<doors.size;i++)
      doors[i] thread doorThink();
}

doorThink()
{
   trig = self.target;
   
   while(1)
   {
      trig waittill("trigger");
      // Start opening door etc
   }
}
The only problem with this code is making the door rotate in the correct direction.
There are several ways you can do this...

1. Make sure all doors and hinges are in the same place, so that rotating 90 degrees will always work.
2. Make different arrays for doors that rotate different directions
3. Use the script_noteworthy attribute to assign the doors a value to which you can recall in the scripts, and then coding an "if" or "switch" statement...
4. Using a script origin linked to the door and scripting the door to move to the origin and back...
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

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 14th, 2010, 1:14 pm

in fact, is there a difference between these ways (in-game)?

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 14th, 2010, 1:20 pm

brushmodels have their own set of angles, so rotating should work. u can change their angles so that they fit to the necessary direction.

example:

key: angles
value: 0 90 0

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

Re: Array help

Post by Drofder2004 » August 14th, 2010, 3:52 pm

megazor wrote:in fact, is there a difference between these ways (in-game)?
Yes, the use of an array gives you more options if you wish to expand on the idea.
megazor wrote:brushmodels have their own set of angles, so rotating should work. u can change their angles so that they fit to the necessary direction.

example:

key: angles
value: 0 90 0
Although this is true, you do not always wish to rotate the door clockwise, so the doors that you wish to open anti-clockwise, you would need to change the code.
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: Array help

Post by Major Tom » August 14th, 2010, 9:01 pm

I'll have to try that, thanks.

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 15th, 2010, 1:26 am

gives you more options
for example:

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

Re: Array help

Post by Drofder2004 » August 15th, 2010, 9:39 am

megazor wrote:
gives you more options
for example:
array.size = No need for me to count my entities.
Prefab = No need for me to name every individual script object in the map, I also do not need to worry about how many I use.
Reduced human error = What happens when you accidently skip a number while making the 34th door on your map?


Go create a map with 50 doors and 50 triggers and I will do the same, see who finishes first?
- You make 100 different individual entities
- I make 1 entity and link the trigger, prefab, copy and paste 50 times.
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

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 15th, 2010, 1:38 pm

well the things u enumerated sound nice but they arent 'options', they just save time of a mapper. what i meant was some advantage in-game.

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

Re: Array help

Post by Drofder2004 » August 15th, 2010, 2:47 pm

An array is just an easy accesible list, in this case of entities.

Consider it a group I can easily move around.
It makes scripting life easier, as I only have to write ONE line of code to get the array, and not create a loop to define the array. Once the array has been created I can easily and uniformly use the array using a SINGLE varaible, I can assign a variable to a global variable and not require multiple threads when obtaining a single unit from the array.

I can always reference the count of arrays array[array.size-1] will always reference the last entry.
When assigning array contents I can dynamically change the contents without changing the varialbe being used...


Are you just trolling now, or are you seriously not taking the fact that arrays are better than looping threads?
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

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: Array help

Post by megazor » August 15th, 2010, 3:24 pm

u wrote almost the same. u just should have said there was no difference in-game. thats what i was wondering of. lol.

and btw, i may be blind but ur code loops threads as well as mine does.

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

Re: Array help

Post by waywaaaard » August 15th, 2010, 5:13 pm

Don't forget that you are supposed to write some nice and clear code that is reusable.
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: Array help

Post by Major Tom » August 15th, 2010, 9:49 pm

Well I probably screwed it up, but capital W turned on show entities as wireframe and w didn’t say that it did anything. Still tried the script out and it didn’t work.

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

Re: Array help

Post by Drofder2004 » August 16th, 2010, 1:28 pm

Post your script in full.
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

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests