Home   Help Search Login Register  

Author Topic: If height >=10 then SAY SOMETHING  (Read 1464 times)

0 Members and 1 Guest are viewing this topic.

Offline XTimmy

  • Members
  • *
If height >=10 then SAY SOMETHING
« on: 31 Dec 2008, 18:32:05 »
Hey.
I've been working on my 'first' mission for a few days now and it's beginning to grind ever so slightly.  I've reached a point where I need a function rather than a script.
Then I decided a Trigger would work just as well.
Basically I've got a helicopter rising in the distance. And when it hits a certain height (10) Crossroads says something to the affect of 'oh no'

I simply cannot get this to work.   

My current set up  (which dosen't return an error, it simply returns nothing is thus)
A trigger, axis a/b = 0/0,
Condition:
(getpos testheli select 2) >= 10
On Act
[sidefriendly, "HQ"] Sidechat "oh no"

I've tried variations of everything [side, "HQ"] Sidechat "oh no"   etc etc but it simply dosen't pop up. Any thoughts? 

(If someone could also make this into a .sqf so I've got an example function to learn the syntax for a looping script off that'd be great)

Offline Deadfast

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #1 on: 31 Dec 2008, 18:43:44 »
Try this:

Code: [Select]
HQ = [west, "HQ"]; HQ sideChat "Oh no!";


Here's the SQF:
Code: [Select]
while {alive testheli} do //loop as long as testheli is alive
{
if ((getPos testheli select 2) >= 10) then //check if testheli's height is greater or equal 10
{
HQ = [west, "HQ"];
HQ sideChat "Oh no!";
};

sleep 1; //wait 1 second before continuing - always sleep if the loop runs for extended amount of time or the game will freeze!
};
« Last Edit: 31 Dec 2008, 18:51:19 by Deadfast »

Offline XTimmy

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #2 on: 01 Jan 2009, 00:56:33 »
Sleep is exactly the command I've been looking for! 
Thanks for the help in both threads Deadfast!  :D

Offline Deadfast

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #3 on: 01 Jan 2009, 02:37:06 »
You're much welcome :)


I wish you good luck in learning SQF ;)

Offline Ext3rmin4tor

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #4 on: 01 Jan 2009, 12:24:43 »
There is also waitUntil

which is equivalent to @ in SQS scripts if you're interested
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Deadfast

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #5 on: 01 Jan 2009, 12:44:14 »
IIRC waitUntil eats up more resources so I'd personally avoid it in this case ;)


BTW Timmy, I just realized you might want to have the message display only once.

In that case use exitWith instead of then with the if condition (it's similar to break in C-like languages):

Code: [Select]
while {alive testheli} do
{
if ((getPos testheli select 2) >= 10) exitWith //if the condition is true execute the code and then exit the while cycle scope
{
HQ = [west, "HQ"];
HQ sideChat "Oh no!";
};

sleep 1;
};
« Last Edit: 01 Jan 2009, 12:47:48 by Deadfast »

Offline XTimmy

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #6 on: 01 Jan 2009, 13:14:34 »
Nice to know but it only needs to execute once.
« Last Edit: 01 Jan 2009, 13:28:15 by bedges »

Offline Deadfast

  • Members
  • *
Re: If height >=10 then SAY SOMETHING
« Reply #7 on: 01 Jan 2009, 15:43:52 »
Yep, that's why you need exitWith ;)