Home   Help Search Login Register  

Author Topic: Eventhandler "Fired"  (Read 2826 times)

0 Members and 1 Guest are viewing this topic.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Eventhandler "Fired"
« on: 26 Jun 2007, 20:08:14 »
I want to make a trigger that detetcts when the player throws a "smekeshellgreen" on the ground. I assume this involves the eventhandler "fired", but my scriptingskills are to rusty to make it work. Can anybody point me in the right direction. I can make the trigger go off when the player fires his weapon, but I need to single out the smokeshellgreen from normal bullets and grenades.

Judging from the Comref, I need to play around with this select 4, but I don't know how.
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Eventhandler "Fired"
« Reply #1 on: 26 Jun 2007, 22:34:21 »
In the init line of your soldier:
Code: [Select]
eh = this addEventHandler["fired", {if (_this select 4 == "SmokeShellGreen") then {activatetrigger=true}}]

In your trigger condition:
Code: [Select]
activatetrigger

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Eventhandler "Fired"
« Reply #2 on: 26 Jun 2007, 22:43:10 »
Thanks. I was trying to do something like that but I screwed it up all the time. Testing now  :yes:
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Eventhandler "Fired"
« Reply #3 on: 27 Jun 2007, 00:57:30 »
...and it's working like a charm. Now, can anyone tell me how I "catch" the smokegrenade in a script? I want to setPos an invisible H at it's location for a helicopter extraction.

I tried to catch it with the syntax
Code: [Select]
_LZ = nearestobject [_this select 0, _this select 4], but it didn't work out at all. I'm sure one of you scritping gurus will point out why it's not working in no time and all, and hopefully also explain what I'm doing wrong. Thank's in advance  :D

EDIT: Ooops, a double post. Sorry. My sincere apologies  :banghead:
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Eventhandler "Fired"
« Reply #4 on: 27 Jun 2007, 01:06:20 »
init field
Code: [Select]
eh = this addEventHandler["fired", {if (_this select 4 == "SmokeShellGreen") then {_this  exec "getLZ.sqs"}}]

Code: [Select]
;getLZ.sqs
;4 secs, to ensure the grenade is on the ground and smoking
~4
_ammo = nearestObjects [_this select 0, [_this select 4], 100]

?count _ammo == 0: hint "NOT DETECTED";exit

LZ = getPos (_ammo select 0)

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Eventhandler "Fired"
« Reply #5 on: 28 Jun 2007, 16:19:47 »
I haven't tested this yet, due to lack of time. But before I test it: Can someone explain the difference between the suggested
Code: [Select]
_ammo = nearestObjects [_this select 0, [_this select 4], 100]

And my original (ad hoc) version:
Code: [Select]
_ammo = nearestobject [_this select 0, _this select 4]

What part of the code returns the position of the grenade? The COMREF includes three different commands and I cannot tell the exact difference between them...

position nearestObject type
Operand types:
position:Array
type:String
Type of returned value:
Object
Description:
Find object nearest to given position with given type.
Used In:
ArmA
Example:
obj = position player nearestObject "Building"

nearestObjects pos
Operand types:
pos:Array
Type of returned value:
Array
Description:
Returns a list of nearest objects of the given types to the given position or object, within the specified distance.
Pos may be using format [[x,y,z], ["type",...], limit] or [object, ["type",...], limit].
Used In:
ArmA
Example:
nearestObjects [player, ["Car","Tank"], 200]

position nearObjects radius or [typeName, radius]
Operand types:
position:Object or Array
radius or [typeName, radius]:Number or Array
Type of returned value:
Array
Description:
Find objects in the circle with given radius.
If typeName is given, only objects of given type (or its subtype) are listed.
Used In:
ArmA
Example:
_list = position player nearObjects 50

Sorry if I seem a little confused, but I want to understand exactly how this is done, for future scripts as well
« Last Edit: 28 Jun 2007, 16:24:37 by nominesine »
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Eventhandler "Fired"
« Reply #6 on: 28 Jun 2007, 17:28:36 »
nearestobject [_this select 0, _this select 4] looks for objects within a 50m circle.

_ammo = nearestObjects [_this select 0, [_this select 4], 100], here you set the range, 100m in this case.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Eventhandler "Fired"
« Reply #7 on: 28 Jun 2007, 19:03:07 »
So if I understand you correctly the script...

1) searches for objects within hundred meters of the unit with the eventhandler, but it will only recognize objects fired by the unit who threw the grenade (_this select 0) and only of the same ammo class as the round he fired (_this select 4)...

2) then it converts them into a private variable within the script named _ammo

Right? And _ammo is an array containing only one object (if the unit only threw one grenade)?? And LZ is a variable that contains the location of the contents in _ammo??? Am I reading this right? I have no testing opportunities until tomorrow, but if it works this way, then I understand the logic behind all this (I hope).
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Eventhandler "Fired"
« Reply #8 on: 28 Jun 2007, 20:26:52 »
1) wrong
2) wrong again  :P

_ammo = nearestObjects [_this select 0, [_this select 4], 100]

objects closer than 100m to unit contained in _this select 0 of type contained in _this select 4.

_ammo is the list of objects found, more than problably containing one or no objects. If more than one object is found, the returned list is sorted by distance to _this select 0. And we get _ammo select 0 as the object that will mark the LZ.

Offline Trexian

  • Members
  • *
Re: Eventhandler "Fired"
« Reply #9 on: 02 Aug 2008, 21:21:41 »
I have a somewhat similar question.

I want to add an eventhandler for each unit in a trigger I created.  When a unit in that trigger fires, a variable is incremented. Such as:

Code: [Select]
_fireTrig setTriggerStatements ["this", "{addEventHandler ["fired", {_count = _count + 1}]} foreach thislist"];

Now, I've established _count in main scope, so I think it should work.  I keep getting an error that there's a missing ] but I think I have them all matched up?

TIA. :)
Sic semper tyrannosauro.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Eventhandler "Fired"
« Reply #10 on: 02 Aug 2008, 21:52:20 »
I would say it will not work.
The trigger will execute its statement in which condition? Some side present? If so, as soon as a single unit of that side gets into the trigger area, this unit will get the handler, but not the rest that will get into the trigger 1 second later.

You may do another thing, add the event handler to any unit that might get into the trigger. When the unit fires, check if the unit or the unit's vehicle is inside the list of the trigger and if so, increase a global counter.

Offline Trexian

  • Members
  • *
Re: Eventhandler "Fired"
« Reply #11 on: 02 Aug 2008, 21:59:16 »
Ah, right.  I see the logic issue.  (I think.) ;)

I was attempting to set a dynamic trigger that, when the trigger was created, any unit within the trigger area would get the eventhandler.  So, the set of units getting the eh would be finite, and known at the time the trigger was created.  My trigger activations are:

Code: [Select]
_fireTrig setTriggerActivation ["ANY", "PRESENT", true];
I expect the trigger to usually have a short duration.

You raise another possibility, though.  Basically, "nested" triggers.  Very early in the script, establish a larger trigger area, and assign the eh to the units in that trigger.  Later, when needed, create the smaller trigger of the area I want, and then count the "fireds."

Does that make more sense? :)

Edit:
Used a workaround.

Put the eventhandler in a script, and made the variable public:
Code: [Select]
{_x addEventHandler ["fired", {count = count + 1}];} foreach thislist;
And the trigger statement:
Code: [Select]
_fireTrig setTriggerStatements ["this", "execVM 'firedEH.sqf'", "deleteVehicle _Boss"];
Edit - more digging, and I think this is what I really want. :)
Code: [Select]
list trigger
Operand types:
trigger: Object
Type of returned value:
Array
Description:
List of units that would activate given trigger.
For trigger of type "Not present" the list is the same as that returned for "present".
Used In:
OFP/ArmA
Example:
_tlist = list triggerOne

Once I generate the list in the trigger, I can add the eventhandler in the same script.  (I think.) ;)

Edit.

Ok, riddle me this, gurus. :)

I set up the trigger, then use:

Code: [Select]
_fireList = list fireTrig

(Yes, I took the underscore off of the name throughout.)  :good:

But then the addeventhandler doesn't work.

If I use the
Code: [Select]
{_x addEventHandler ["fired", {count = count + 1}];} foreach thislist;in a separate sqf, it works.

But, if I put
Code: [Select]
{_x addEventHandler ["fired", {count = count + 1}];} foreach _fireList;it doesn't.

No error console or anything, it just doesn't increment it.

Is this the scope monster coming to bite me?  I initially set _count outside any loops.

Thanks for any ideas. :)
« Last Edit: 04 Aug 2008, 15:31:12 by Trexian »
Sic semper tyrannosauro.