PDA

View Full Version : About doors :)



pollo
1st February 2014, 17:58
How can I do so many doors without using a function for each one?

I mean, I dont want to do this:


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

door1()
{
...

I want to make like a script which allows you to open every door, instead of using a new function for each one. I know this because I've seen in jm_cruise map. I also know that I must use arrays, but it's a bit hard for me ;)

Can you help me? Any help will be appreciated <3

serthy
1st February 2014, 20:10
// create a prefab (new map)
// model your door -> script_model or script-brushmodel
// select your trigger first then your door hit W (arrow from trig to door appears)
// save it and paste this prefab as many times as you like in your map

init()
{
doorTrigs = getEntArray( "targetname" , "trigger_door" ); // maybe switch params

for( i = 0 ; i < doorTrigs.size ; i++ )
{
if( !isDefined( doorTrigs[i].target ) )
continue;

door = getEnt( doorTrigs[i].target , "targetname" ); // maybe switch params

if( !isDefined( door ) )
continue;

doorTrigs[i] thread doorThink( door );
}
}

doorThink( door )
{
while( isDefined( self ) )
{
self waittill( "trigger" , player );

door rotateYaw( 90 , 1.0 );

door waittill( "rotatedone" );

self waittill( "trigger" , player );

door rotateYaw( -90 , 1.0 );

door waittill( "rotatedone" );
}
}

pollo
2nd February 2014, 15:42
Thank you mate :)

I was thinking about making doors (not prefabs) and linking the trigger to them, but it linked all of the doors. Ty very much :)