Home   Help Search Login Register  

Author Topic: EventHandlers in a script?  (Read 575 times)

0 Members and 1 Guest are viewing this topic.

Niven

  • Guest
EventHandlers in a script?
« on: 15 Dec 2004, 12:13:48 »
Hi all,

I've made a script that forces a helicopter to crash when it takes damage.
The script activates an EH to watch for damage, which then forces the chopper to crash.

It works fine with a slight flaw.
When the missile/rocket hits, the chopper is forced back, which looks unrealistic.

I've tried getting the velocity of the chopper before the impact and then setting it back, directly after the impact but i'm getting scalar errors when I try to pass the x,y,z to the EH.


Heres the two parts of the event:

Code: [Select]
Apache flyinheight 40

;Get the initial velocity of the chopper
_Speed = velocity Apache

_xVelo = _Speed select 0
_yVelo = _Speed select 1
_zVelo = _Speed select 2

Apache AddEventHandler ["hit", {[Apache, _Speed] exec "crash.sqs"}]



hint format["X:%1 Y:%2 Z:%3", _xVelo, _yVelo, _zVelo]

exit


Code: [Select]
_Target = _This select 0
;Get the initial velocity of the chopper
_Velocity = _this select 1
_xVelo = _Velocity select 0
_yVelo = _Velocity select 1
_zVelo = _Velocity select 2

hint format["X:%1 Y:%2 Z:%3", _xVelo, _yVelo, _zVelo]

;Stop the rotors spinning
_Target setfuel 0

;camcreate 2 shells that hit each other at the choppers x,y,z
bomb1 = "HEAT105" camcreate getpos _Target
bomb1 = "HEAT105" camcreate getpos _Target

; set velocity of chopper back to original vel before explosion caused an offset.
_Target setvelocity [_xVelo, _yVelo, _zVelo]

;======================================================================================

#Crash


_Height = getPos _Target select 2

_Direction = getDir _Target

_Dir = (random(0.8))+1

;_Target FlyInHeight (_Height - 2)

_Target setDir (_Direction + _Dir)

drop ["cl_basic","","Billboard",1,random(4),[-1,-6,2],[random(1),random(1),random(0.1)+0.4],1,random(0.1)+0.5,0.5,random(0.1),[random(0.1)+0.2,random(1)+2,random(1)+3],[[0.2,0.2,0.2,1],[1,1,1,0]],[0],0,0,"","",_Target]

? _Height < 2 : bomb1 = "HEAT105" camcreate [getpos _Target select 0, getPos _Target select 1, (getPos _Target select 2) +1]
? _Height < 2 : bomb1 = "HEAT105" camcreate [getpos _Target select 0, getPos _Target select 1, (getPos _Target select 2) +1]

? _Height < 2 : goto "End"

~0.01

goto "Crash"

;=========================================================================================

#End

exit


~Any help is much appreciated  ;D

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:EventHandlers in a script?
« Reply #1 on: 15 Dec 2004, 14:53:49 »
well in your first script you should have a loop to keep updating the _speed variable, so it will be the most recently velocity used by your EH

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:EventHandlers in a script?
« Reply #2 on: 15 Dec 2004, 20:16:04 »
The variable _speed is not defined within your eventhandler code. Think of the code between the braces in your EH as an entirely separate script. In your case, the script never puts a value into the variable _speed. You could use a global variable instead of a local one (speed instead of _speed).
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline Raptorsaurus

  • Editors Depot Staff
  • *****
Re:EventHandlers in a script?
« Reply #3 on: 15 Dec 2004, 22:08:00 »
Quote
global variable instead of a local one (speed instead of _speed).
Actually you cannot use "speed" as a global variable because it conflicts with the SPEED command which returns the speed of a vehicle.  Use SPD or somthing like that instead.

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:EventHandlers in a script?
« Reply #4 on: 16 Dec 2004, 00:00:31 »
Actually you cannot use "speed" as a global variable because it conflicts with the SPEED command which returns the speed of a vehicle.  Use SPD or somthing like that instead.

Ah! Glad you caught that one. Many times I've pulled out my hair trying to figure out what is wrong, and it was due to this sort of bad variable naming.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!