id Tech Forums

id Tech 4 (Doom3/Prey/Q4) => id Tech 4 Level Editing => Topic started by: douglas quaid on December 17, 2015, 09:16:06 PM

Title: Simple moving platform script...
Post by: douglas quaid on December 17, 2015, 09:16:06 PM
Hey guys.

As I've just started modding again after a long absence, I appear to have forgotten how to code (script). I was wondering what script I would need to make a moving platform ie. moves on it's own with no triggers when the level loads. Also, what code do I need to add to the script file for the mover to move forward, and then move back to it's starting point, and then repeatedly do so while the level is being played. I know this is probably very basic for most of you but I do forget sometimes, and I've done a search but haven't found what I'm looking for. :D

Thanks,

Quaid.
Title: Re: Simple moving platform script...
Post by: MrC on December 17, 2015, 11:51:44 PM
https://www.3dbuzz.com/training/view/doom-3-modding/series-2/controlling-movers (https://www.3dbuzz.com/training/view/doom-3-modding/series-2/controlling-movers) Hopefully this might be a good refresher for what you're looking for.
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 18, 2015, 08:37:37 AM
Man, 20 minutes?  I'm impatient.  :)

Assuming you remember how to use Radiant, here's a quicky:

1) make your func_mover.  BE SURE it's a func_mover.  Func_static's work too but they don't work correctly when moving (had lots of fun with this years ago!)

2) THE CHEATER WAY: put a target_null where you want mover to go.  Put a target_null where you want the target_null to start (most likely where you create the func_mover).

3) set the settings on the func_mover for speed, time, accel, whatever.  D3RAdiant has info on what each means.

4) jot down the names of the func_mover & the null's.

5) Save the map.

6) make a .script file in the same folder as the map.  IE if the map is "maps/game/mover.map" put the script in "maps/game/mover.script"

7) setup your script.

I've attached an example map & script for you.   I also recommend the handy dandy D3 script help file: http://www.moddb.com/members/thehappyfriar/downloads/doom-3-reference-page

Just extract the .zip to your maps folder & dmap it and it will work.
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 19, 2015, 05:44:58 AM
Thanks for the help guys. That map Friar is also appreciated, but when I tried the target null approach it doesn't seem to work for me. Maybe I'm doing something wrong... I've tried this also and am getting no results, any ideas?

void platform_1()
{
sys.wait(2);
$platform_1.moveToPos('2672 832 -488');
sys.waitFor($platform_1);
sys.wait(3);
$platform_1.moveToPos('1584 832 -488');
sys.waitFor($platform_1);
}
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 19, 2015, 08:11:24 AM
Do you run that function in your main function?
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 19, 2015, 09:01:37 AM
Yeah, I think so... :(

void main ()
{

// Call Moving Platform to function
func_mover_1 ();
}
Title: Re: Simple moving platform script...
Post by: MrC on December 19, 2015, 02:32:36 PM
The name of the function you're calling in main is "func_mover_1 ();" but the name of the function is "void platform_1()", perhaps that might be why it isn't working for you?
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 19, 2015, 04:13:20 PM
Good point MrC but I have changed it around and is still not working. :(
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 19, 2015, 04:59:42 PM
Please post the whole script file.
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 20, 2015, 02:08:39 AM
In the editor I created 'func_mover_1' for the platform I want to move. Below is everything I have in the script file.

void main ()
{

// Call Moving Platform to function
func_mover_1 ();

}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Moving Platform

void func_mover_1 ()
{
sys.wait(2);
$func_mover_1.moveToPos('2672 832 -488');
sys.waitFor($func_mover_1);
sys.wait(3);
$func_mover_1.moveToPos('1584 832 -488');
sys.waitFor($func_mover_1);
}
Title: Re: Simple moving platform script...
Post by: MrC on December 20, 2015, 03:36:43 AM
Ah, ok. As per this: http://www.3dbuzz.com/training/view/doom-3-modding/series-2/intro-to-functions (http://www.3dbuzz.com/training/view/doom-3-modding/series-2/intro-to-functions)

It's mentioned in the video that the main() function should always be the last function in the script, so just put main at the bottom instead of the top and hopefully that'll get it working.
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 20, 2015, 07:55:07 AM
I'd also highly suggest you NOT have function names the same as any entity in the map.  It might be an issue.  I know (though testing) that there's certain reserved key works for scripts & you can't use those names in variable/function names, but it's always been a hit and miss to find them. 

I'd say MrC is right, put the main at the end and it should work.
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 20, 2015, 11:45:45 AM
Thanks guys. What MrC advised seemed to work but the platform only travels to the first position. What do you think is preventing it from traveling to the return position and then looping both phases?
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 20, 2015, 02:29:00 PM
You have it happens once.  You need it in a loop. 
void moving ()
{
    while (1)
        {
            $func_mover_1.moveTo($target_null_2);
            sys.waitFor($func_mover_1);
            $func_mover_1.moveTo($target_null_1);
            sys.waitFor($func_mover_1);
        }
}


The while(1) keeps going until 1 isn't true.  Since 1 is always true because I'm not changing it, it always loops.
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 20, 2015, 06:05:57 PM
Edited...

Worked a treat Mr. Friar :D but I have another problem...

I tried adding a second mover but this one doesn't work even when I used the same code...
// Moving Platform 1

void platform_1 ()
{
        while(1)
{
$platform_1.moveToPos('2672 832 -488');
sys.waitFor($platform_1);
sys.wait(.001);
$platform_1.moveToPos('1584 832 -488');
sys.waitFor($platform_1);
sys.wait(.001);
}

}


// Moving Platform 2

void platform_2 ()
{
        while(1)
{
$platform_2.moveToPos('1584 832 280');
sys.waitFor($platform_2);
sys.wait(.001);
$platform_2.moveToPos('2672 832 280');
sys.waitFor($platform_2);
sys.wait(.001);
}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



void main ()
{
// Call Moving Platform 1 to function
platform_1 ();

// Call Moving Platform 2 to function
platform_2 ();
}


What do you think?
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 20, 2015, 10:06:15 PM
Looks like that loop is stopping the game from going to the platform_2 function.

I changed them to threads (add "thread" before "platform_1" & 2) and then it works.

You can remove that sys.wait(0.001).  That's so small it won't matter.
Title: Re: Simple moving platform script...
Post by: Phrozo on December 20, 2015, 10:08:06 PM
EDIT: THF beat me to it ;P

The main thread for the map script is still running platform_1 (), but it never stops because it contains a while loop that runs forever. This means platform_2() will never get called.

The solution is to thread those functions so they can continue looping without locking the main thread. All you have to do is change the main function to this:

void main ()
{
// Call Moving Platform 1 to function
thread platform_1 ();

// Call Moving Platform 2 to function
thread platform_2 ();
}
Title: Re: Simple moving platform script...
Post by: The Happy Friar on December 20, 2015, 11:47:30 PM
Using an in game trigger would also be another way to solve this.
Title: Re: Simple moving platform script...
Post by: douglas quaid on December 21, 2015, 07:11:44 AM
Ah that's great guys, thanks. Working well now. Thanks again.