Home   Help Search Login Register  

Author Topic: foreachunit  (Read 902 times)

0 Members and 1 Guest are viewing this topic.

TC

  • Guest
foreachunit
« on: 24 Oct 2005, 13:44:48 »
hello all

I am making a mission in which the player and his team face respawning enemies, using ajm's respawn script. In this mission, i have also used a bulletcam script and death cam script which has a random chance of being activated each time a unit fires or is killed.

my problem is trying to get the respawning unis to have the "killed" and "fired" event handlers in thier init fields, as obviously they dont have one. I have tried using "foreachunit in group this" on a trigger which covers the entire map, and is activated by any units repeatedly, so basically, anybody tht dies or fires on the map executes a script. But i cant get the respawning units to use the eventhandlers!!

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re:foreachunit
« Reply #1 on: 24 Oct 2005, 13:51:37 »
Doesn't "foreachunit in group this" in the trigger has to be "foreach in thislist"?
« Last Edit: 24 Oct 2005, 13:51:51 by Trapper »

TC

  • Guest
Re:foreachunit
« Reply #2 on: 24 Oct 2005, 14:27:47 »
hmm, does'nt work either. I think that "foreach in thislist" is actually trying to detect how many units are inside a vehicle called thislist!

Also, i remember seeing something written about eventhandlers at one point, saying how you can actually detect which unit killed a dead unit, what weapon has been fired etc, but i cant find this article anywhere!!

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re:foreachunit
« Reply #3 on: 24 Oct 2005, 18:04:08 »
Comref says:
Quote
Triggers
Condition expression is used to determine when the trigger is activated. Boolean variable this is set during evaluation of condition expression to primary sensor activation condition. Array variable thisList is set to list of all vehicles that would satisfy primary sensor activation condition. Condition must return boolean value.
On Activation and On Deactivation expressions define action that is peformed when trigger condition changes to true or false. Expression must either be an assignment or return nothing (see type none).
Variable denoting trigger can be created by filling in name field
So no one should name a unit thislist. :)

I'm sure you know the complete forEach syntax:
{_x addEventhandler ["killed",{_this exec "playerKilled.sqs"}]} forEach thisList

(Oh, and the additional in before was probably wrong)

The event handler tutorial you're looking for is located in the Editors Depot, http://www.ofpec.com/editors/browse.php?category=1_2&start=25 .

TC

  • Guest
Re:foreachunit
« Reply #4 on: 26 Oct 2005, 13:56:30 »
Ah excellent!! cheers, all works!!

Umm, now another dilema....

This works for units placed on the map at the sart of a mission, but i have units respawning and they dont have the event handlers attached?

Also, i have used a camera script like this:

?_this select 1= "UKF_LAW80Launcher": goto "next"
_Town = random 70
~0.1
?(_Town>0 && _Town<68):exit
?(_Town>68 && _Town<70):goto "next"

#next
_Missile =  _this select 0
? isNull  _Missile : exit
? !(track) : exit
_ok = createDialog "Speed"
? !(_ok) : exit
setAccTime 0.01
_Type= typeOf _Missile

_cam = "camera" camcreate [0,0,0]
_cam cameraeffect ["internal", "back"]


sliderSetRange [100, 0.01, 1]
sliderSetSpeed [100, 0.5, 2.0]
sliderSetPosition [100, 0]
sliderSetRange [99, 0.1, 1]
sliderSetPosition [99, 1]
sliderSetSpeed [99, 0.1, .25]
sliderSetRange [98, -180, 180]
sliderSetPosition [98, 0]
sliderSetSpeed [98, 0.5, 2.0]
sliderSetRange [97, -15000, 15000]
sliderSetPosition [97, 0]
sliderSetSpeed [97, 0.5, 2.0]
#loop
? _Type != typeOf _Missile : goto "end"
[ _Missile ,_cam,(sliderPosition 99),(sliderPosition 98),(sliderPosition 97)] call PosBullcam
setAccTime (sliderPosition 100)
? ctrlvisible 100 : goto "loop"


#End
? (getpos _cam select 1 == 0) or !(_Type != typeOf _Missile) : goto "SkipSlowEnd"
closedialog 0
 setAccTime 0.2
~0.5
#SkipSlowEnd
_cam cameraeffect ["terminate", "back"]
 camdestroy _cam
closedialog 0
setacctime 0.5
exit



Which im using to simulate a bullet camera, which will only activate on a random chance, but will always activate if the unit the EH is attached to fires the weapon "UKF_LAW80Launcher", but unfortunatley it doesnt like the first line of code??? ??? ???

any ideas?
« Last Edit: 26 Oct 2005, 13:58:42 by TC »

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re:foreachunit
« Reply #5 on: 26 Oct 2005, 14:43:32 »
Then try to edit the respawn scripts. It's possible to place an init line in createUnit commands.

Example:
"SoldierWB" createUnit [getMarkerPos "barracks", groupAlpha, {this addEventhandler ["killed",{_this exec "playerKilled.sqs"}]}, 0.5, PRIVATE]


?_this select 1== "UKF_LAW80Launcher": goto "next"