Jump to content
Sign in to follow this  
aook002

"if" statement...

Recommended Posts

Hi all,

I'm wondering am I able to make a script execute using an IF clause ? In a kind of an eventhandler way ?

What im trying to do is have a script execute when a certain condition is met. And this condition is when a helicopter reaches half health.

Somrthing like this...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">If heli = damage 0.5 exec "rotor.sqs"

I know that's completely wrong but I hope it help you to get the drift.

Thanks

Aook  rock.gif

Share this post


Link to post
Share on other sites

Way 1:

Write in the init of the heli:

<span style='color:red'>fixed</span>

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this] exec "checkhealth.sqs"

checkhealth.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_heli = _this select 0

#check

~1

? ((damage _heli)>0.5) : goto "check"

_heli exec "rotor.sqs"

----

Way 2:

Write in the init of the heli:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventhandler ["hit", {if ((damage (_this select 0))<=0.5) then {[_this select 0] exec "rotor.sqs"}}]

----

Way 2 would consume less CPU, but I don't know if it worked in every case, you had to try that.

Share this post


Link to post
Share on other sites

Cheers hardrock, ill try as soon as I can...

But i'm off to bed now  sad_o.gif  Gcse's tomorrow.....eeeeeeek.

Thanks

Aook smile_o.gif

Share this post


Link to post
Share on other sites

Erm....i cant seem to get it to work  sad_o.gif

Would it be easier if I told you the heli was called >> crash.

And that i'm using MrZigs tail rotor script, which needs to be execed something like this

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[crash,true,2] exec "rotor.sqs"

PS: I'm trying to use the Way 1: Using "checkhealth.sqs"

Thanks

Aook  smile_o.gif

Share this post


Link to post
Share on other sites

Sorry, I made a mistake in my example above. You have to replace "_this" with "this" in the init (but not inside the addEventHandler command!). I edited this thread now, please try it again.

As long as you write the command in the init of the heli that should crash, you can use this. But at the moment you write the command in some trigger or script, you have to replace this with the name of the chopper, in your case crash.

I don't know about that tail rotor script, do you have to write the command in the init of the helicopter?

<span style='color:red'>Edit:</span> Oh I see what you mean.

In this case you have to edit checkhealth.sqs:

Replace

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_heli exec "rotor.sqs"

with

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[_heli,true,2] exec "rotor.sqs

Dunno if that's the right syntax though

Share this post


Link to post
Share on other sites

Thanks for the reply hardrock, but i still have a slight problem...  sad_o.gif

My helicopter is called crash

In the init line of the heli is:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this] exec "checkhealth.sqs"; this exec "damage.sqs"

checkhealth.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_heli = _this select 0

#check

~1

? ((damage _heli)>0.5) : goto "check"

[_heli,true,2] exec "rotor.sqs

damage.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">crash setdamage 0.1

~1.5

crash setdamage 0.2

~1.5

crash setdamage 0.3

~1.5

crash setdamage 0.4

~1.5

crash setdamage 0.5

~1.5

crash setdamage 0.6

hint "Helicopter should now be crashing..."

exit

rotor.sqs - By MrZig

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;;-----------------------------------------

;;[heli,true,2] exec "rotor.sqs"

_heli = _this select 0

_ox = 0

_oy = -9.5

_h = 0

_size = 2

;;-----------------------------------------

_speedX = velocity _heli select 0

_speedY = velocity _heli select 1

_driver = driver _heli

_heli setfuel 0

_random = true

_maxkills = 4

?count _this == 2: _random = _this select 1; _maxkills = 4

?count _this == 3: _random = _this select 1; _maxkills = _this select 2

_driver sidechat "Mayday! Mayday! This is Super Six One, our Blackhawk is going down! I repeat, our Blackhawk is going down! Requesting backup! Mayday! Mayday!"

#loop

_param=(random 3)*_size

?(_param>1.5):_param=random 2.5

?(_param<0.95):_param=0.95+_param

?(_size<1):_param=random 0.75

? (speed _heli)>15:_param=_param/2

_heli setvelocity [_speedX,_speedY,-14]

_height = getpos _heli select 2

_dir = getdir _heli

_heli setdir (_dir) +5.5

~0.001

?getpos _heli select 2 <= 1 : goto "loop2"

drop ["cl_basic", "", "Billboard", 1, 3*_param, [_ox+ random (0.25*_size) - random (0.25*_size) ,_oy+ random (0.25*_size) - random (0.25*_size) ,_h], [random 0.3-random 0.3, random 0.3-random 0.3,random 0.3], 1, 0.004, 0.004, 0.1, [random (1.25*_size), random (1.5*_size),random ( 2*_size),random (2.5*_size)], [[0.1,0.05,0,0.4],[0.05,0.025,0,0.25],[0,0,0,0.1],[0,0,0,0]], [0,1,0], 0.5, 0.05, "", "", _heli]

goto "loop"

#loop2

_dir = getdir _heli

_heli setvelocity [0,0,-10]

_heli setdir (_dir) +5.5

#explo

_c = 50

_size = [2, 5]

_size1 = [2, 15]

_lifetime = 3

_step = 360 / _c

_i = 0

#11

_Explosion = GetPos _heli

_cx = _Explosion select 0

_cy = _Explosion select 1

_cz = _Explosion select 2

_vel = [sin(_i * _step)*(random 15-random 15), cos(_i * _step)*(random 15-random 15), random 20]

_vel1 = [sin(_i * _step)*7.5, cos(_i * _step)*7.5,random 5-random 15]

?_cz<1:drop ["cl_basic", "", "Billboard", _lifetime, _lifetime, [_cx, _cy, 0.5], _vel, 0, 1, 0.157, 0.001, [5,7.5,10,15], [[0.05,0.025,0,0.3],[0.05,0.025,0,0.3],[0,0,0,0.3],[0,0,0,0.1]],  [0], 0.1, 0.2, "", "", ""];_debri="FxExploGround2" camcreate [(getpos _heli select 0)+random 1-random 1,(getpos _heli select 1)+random 1-random 1,_cz];_debri setvelocity [random 25-random 25, random 25-random 25, random 50];_debriA="FxExploGround1" camcreate [(getpos _heli select 0)+random 1-random 1,(getpos _heli select 1)+random 1-random 1,_cz];_debriA setvelocity [random 25-random 25, random 25-random 25, random 25]

?_cz>=1:drop ["cl_basic", "", "Billboard", _lifetime, _lifetime, [0,0,0], _vel1, 0, 0.2, 0.157, 0.001, [5,7.5,10,15], [[0.05,0.025,0,0.3],[0.05,0.025,0,0.3],[0,0,0,0.3],[0,0,0,0.1]], [0], 0.1, 0.2, "", "", _heli];_debri="FxExploGround2" camcreate [(getpos _heli select 0)+random 1-random 1,(getpos _heli select 1)+random 1-random 1,_cz];_debri setvelocity [random 25-random 25, random 25-random 25, random 50];_debriA="FxExploGround1" camcreate [(getpos _heli select 0)+random 1-random 1,(getpos _heli select 1)+random 1-random 1,_cz];_debriA setvelocity [random 25-random 25, random 25-random 25, random 25]

_i = _i + 1

?(_i < _c) : goto "11"

#crew

?!_random: goto "run"

_crew = crew _heli

_c = count _crew

_i = 0

_kills = 0

#crew2

_unit = _crew select _i

?random 1 > 0.8 && _unit != player: _unit setdammage  (random 1)

?random 1 > 0.8 && _unit != player && _kills < _maxkills: _unit setdammage 1; _kills = _kills + 1

_i = _i + 1

?_i < _c: goto "crew2"

#run

_heli setfuel 0

?!Alive _heli : exit

{_X setbehaviour "aware"} foreach _crew

_heli setdammage .90

_driver sidechat "GET OUTTA THERE! IT'S GONNA BLOW!";;

~15

_heli setdamage 1

~3

_driver sidechat "Is everyone OK!?"

exit

The error I get is:

[_heli,true,2] exec "rotor.sqs |#| Invalid number in expression

Any help? sad_o.gif

Thanks

Aook

Share this post


Link to post
Share on other sites

argh forgot the quote crazy_o.gif

"rotor.sqs<span style='color:red'>"</span> <<<<

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[_heli,true,2] exec "rotor.sqs"

Share this post


Link to post
Share on other sites

Thanks hardrock, i finally got it working with a few tweaks, and with your help  wink_o.gif

All i changed was the addition of the " for the "rotor.sqs". But when i had got this working i found that my helicopter execed the "rotor.sqs" with being full health. So I guessed that I would have to change the...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? ((damage _heli)>0.5) : goto "check"

To...

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? ((damage _heli)<0.5) : goto "check"

I think this is because the damage works the wrong way round in flashpoint like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">heli setdamage 0.1 means it has 90% health...wierd  tounge_o.gif

Anyway thanks all

Aook  biggrin_o.gif

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  

×