Jump to content
Sign in to follow this  
almanzo

Basic trigger scripting question

Recommended Posts

Hi!

I am very new to scripting. Like, brand new. Haven't really written any code exept a basic course in Delphi many years ago. I get how languages work, but I am not familar with common commands and are a bit slow.

Now, I have started with a campain. I have been thinking about doing so for a long time. It is for now not a usual campain, simply a string of MP missions to play with my coop group. I am working with my first mission atm.

So, here comes my question.

What I want to have done is this:

One of the objectives given to the players, are to free their leader, who are held captive by opfor and are scheduled to be executed after 15 minutes after the game starts. For now, I have two triggers for this. I have named the leader "lead", and on mission start, he is set as captive.

When the time runs out, the first thing that happens, after 900 seconds, is that the officer starts to say a speech with the say command. I have even managed to have him lipsync while talking. :D Another trigger is set to run after 949 seconds, and this trigger sets the lead unit to not be captive anymore.

Now comes my question. Is there a way to have both of these actions be in the same trigger.

is it possible to do something like this (I am not writing code now, just how I imagine the code :P)

So, I have used the basic condition maker in the trigger, so timeout 900 on everybody.

then this comes in the on act:

"man1 say ["pang",5], then add 51 then lead setcaptive false"

Share this post


Link to post
Share on other sites

use spawn in triggers for that effect:

_null = [man1,lead] spawn {
_man1 = _this select 0;
_lead = _this select 1;
_man1 say ["pang",5];
sleep 51;
_lead setcaptive false;
};

Share this post


Link to post
Share on other sites

Thank you very much Demonized!

I'm finding this to be very much fun. Arma has recruited a new mission maker :P

Share this post


Link to post
Share on other sites

welcome in the club, its addictive :D

make sure to give the guide in my sig a read if you havent already, its old but gives good ideas on how to acomplish many things in Arma.

Share this post


Link to post
Share on other sites

And now I've tried the script, and it worked as I wanted it to.

I have one question though. Why is the "spawn" command needed?

Why can't you have the script look like this:

_man1 say ["pang",5];
sleep 51;
_lead setcaptive false;

What is it that the spawn does. Isn't the "sleep" command what I was looking for?

I want to wrap my head around how it works. The link to the wiki didn't really help me that much. Though, I might just be stupid :P

Share this post


Link to post
Share on other sites

It is because the 'on act' of triggers run in the 'non-scheduled environment' which means they are not allowed to spend long time, since that would slow the engine. Sleep won't work in non-scheduled environment. By using spawn we start some code that runs in parallel in the scheduled environment where you can use sleep.

http://community.bistudio.com/wiki/Code_Optimisation#Threads

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×