Home   Help Search Login Register  

Author Topic: Counting Vehicles through a Trigger  (Read 1821 times)

0 Members and 1 Guest are viewing this topic.

Offline Mock360

  • Members
  • *
Counting Vehicles through a Trigger
« on: 31 Mar 2007, 03:21:14 »
Been researching all day. I'm a relative noob when comes to scripting. Here is what I am trying to accomplish in a multiplayer scenario. I need to count the number of a specifc vehicles that pass through a trigger. When the count gets to three an IED is exploded [that i can script!]. The trucks are named [trk1, trk2...] but start out empty and may be crewed by any combination of sixteen players. Thanks in advance for saving what hair I have left.


Edit--- Since there has been no respponse, I will assume that this is impossible to do. Thanks anyway. 8)
« Last Edit: 04 Apr 2007, 03:00:43 by Tim Drushal »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Counting Vehicles through a Trigger
« Reply #1 on: 05 Apr 2007, 19:05:33 »
Whoa pard!

Are you trying to make sure a certain number of vehicle are in the trigger at once? If so:
1. In your "init.sqs" put
Code: [Select]
truck_array = [trk1,trk2,.....]2. In you trigger Condition:
Code: [Select]
({_x in thislist} count truck_array) > N
Where N is the number you want.

If you are trying to count to total number of vehicles that pass through a trigger that is more compilcated but can be done. Let me know if this is the case.

« Last Edit: 06 Apr 2007, 01:00:40 by Mr.Peanut »
urp!

Offline Mock360

  • Members
  • *
Re: Counting Vehicles through a Trigger
« Reply #2 on: 05 Apr 2007, 23:28:51 »
Thank you for replying Mr. Peanut. I will try to explain a little more.

What I am trying to do is initiate an ambush with an IED. I would like to trigger the IED to explode as the third truck (of four) passes through the trigger. The trigger executes an explosion script that is placed on a game logic. I could sync the trigger to a particular vehicle but in a multi-player environment THAT truck may not be the third through the trigger. I guess in plane speak it would look like... trk1 passes through trigger - truck_array=1, trk3 passes through trigger - truck_array=2, trk4 passes through trigger - truck_array=3 --- BOOM!!!. I hope this is a better explanation. Thanks for your attention. :)

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Counting Vehicles through a Trigger
« Reply #3 on: 06 Apr 2007, 00:59:56 »
Okay,
The funny thing is that this seemingly innocent problem does not have a simple answer. Since the vehicles are player controlled they may enter the trigger any which way in any combination. One vehicle could enter the trigger and then back out, or two vehicles could enter the trigger together and before the trigger resets the third vehicle could enter.

Easiest possible way
edit: Add game logic named server to the map.
Place a large trigger that not only covers the mine area, but covers any place any of the vehicles could be after entering the trigger. The trigger list object will then represent all vehicles in the trigger. The place the trigger to whatever side present and add the lines I gave you above. This is the best way if you are certain that the first two vehicles will still be within the trigger when the third enters. Not sure what you are using as an explosive but if you are dealing with a large trigger, chances are it will fire on all machines and you can simply camcreate your explosives. (I personally like using the CoC mines because all you have to do it set the mines damage to 1 and it explodes for all clients.)

Harder Way
If what you want is a trigger to count vehicles going over it without fail, the trick is to count them on the server only.
1) In your "init.sqs" put the truck_array line I posted previously. Below it add:
Code: [Select]
ied_array = []
ied_flag = FALSE

2) Now you must make trigger to count the trucks. Name it ied_trigger. Set it to whatever side detected and activate repeatedly. For conditions put:
Code: [Select]
(local server) and (({_x in thislist} count truck_array) > 0)In OnActivation:
Code: [Select]
[] exec "ied_count.sqs"
3) "ied_count.sqs"
Code: [Select]
if ((count ied_array) > 0) then {exit}
#loop
{if not (_x in ied_array) then {ied_array = ied_array + [_x]}} foreach list ied_trigger
if ((count ied_array) >= 3) then {ied_flag = TRUE ; exit}
~0.1
goto "loop"

4) One more trigger. Condition:
Code: [Select]
ied_flagOnActivation:
Code: [Select]
your ied explode code here
4) Now, since the trigger listed in 4) will only fire on the server, you should use createVehicle to create your explosive, if that is how you want to do it. If you want to use camCreate then you must change the following line in "ied_count.sqs"
Code: [Select]
if ((count ied_array) >= 3) then {ied_flag = TRUE ; exit}to
Code: [Select]
if ((count ied_array) >= 3) then {ied_flag = TRUE ; publicVariable "ied_flag" ; exit}Then the trigger in 4) will fire on all machines.

Of course, I have not tested this code.�  :blink:�  Try it and let me know. I will be away for Easter so I will not be able to respond immediately. If someone has a more elegant way of achieving the same goal I would like to see it.



 
« Last Edit: 10 Apr 2007, 17:37:46 by Mr.Peanut »
urp!

Offline Mock360

  • Members
  • *
Re: Counting Vehicles through a Trigger
« Reply #4 on: 06 Apr 2007, 04:44:39 »
Thank You!!!

I will try both ways tomorrow and let you know which works best. I really do appreciate your help. :)

EDIT:  Tried the "hard way" this morning because it more closely replicates what I was try do. Nothing happened. No error message or ied activation. Ran out of time to test this morning will try again later.

EDIT 2: Okey dokey. After I placed the game logic "server" on the map and modified the following line:

if ((count ied_array) >= 3) then {ied_flag = TRUE ; publicVariable ied_flag ; exit}

to

if ((count ied_array) >= 3) then {ied_flag = TRUE ; publicVariable "ied_flag" ; exit}

it worked FANTASTIC!!!!.

THANK YOU Mr. Peanut your code worked flawlessly!!! :clap:
« Last Edit: 07 Apr 2007, 00:20:50 by Tim Drushal »

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Counting Vehicles through a Trigger
« Reply #5 on: 10 Apr 2007, 17:38:38 »
Glad it worked for you. Sorry about forgetting the gamelogic "server" and the quotes in the publicVariable command. I am a little rusty.  :whistle:
urp!