Home   Help Search Login Register  

Author Topic: Trigger for any AI  (Read 738 times)

0 Members and 3 Guests are viewing this topic.

Uldics

  • Guest
Trigger for any AI
« on: 30 Apr 2004, 16:06:59 »
Trigger condition: side player == WEST AND alive player AND (vehicle player) in thisList

But this is only working on real players, not on AI. How do I make it work also on any AI? Is there any universal word I could place instead of "player"? I tried placing the actual name of an AI instead of "player", but that worked only on that one AI. There should be a smarter way of making one trigger for all AI.

Some extra information:
Trigger activation: sfzHandler = player addEventHandler ["hit",{_this exec "spawnkill.sqs"}]   

Trigger deactivation: player removeEventHandler ["hit",sfzHandler]

spawnkill.sqs is making the shooter of our west AI to be killed and gives the AI his life back.

Offline Wadmann

  • OFPEC Patron
  • ****
  • I'm the next evolutionary step after a llama!
Re:Trigger for any AI
« Reply #1 on: 30 Apr 2004, 20:45:02 »
Uldics:

I think you want to use "foreach units thislist" to allow any unit (that meets your other conditional criteria) that is in the trigger area to be included in the array of units that will be affected by your script. As I am not really a scripter, I am not sure how to incorporate this into your condition. Usually it is used like this:

"_x setdammage 1" foreach units thislist

Try something like this:

Make a trigger that will cover all of the units that you want the eventhandler applied to and add this:

West present
Condition this

then add this to the OnActiv field:

sfzHandler = [_x addEventHandler ["hit",{_this exec "spawnkill.sqs"}]] foreach units thislist  

If the above does not work,perhaps you can use a different trigger to make an array of all the players that need the eventhandler then use that array to add the eventhandler to the units like so:

Name - Arraytrigger
West Present
On Actv -  west_liveunits = thislist

Then make a trigger that covers the entire island (or you may be able to put this in your init.sqs) and put this in the OnActiv field:

sfzHandler = [_x addEventHandler ["hit",{_this exec "spawnkill.sqs"}]] foreach west_liveunits

Let me stress that I have very little scripting knowledge but I am a fairly quick learner. You more than likely have far more knowledge than myself so you may see that some of this could be garbage. One other thing that stands out is your use of _this. You may need to change that to _x for my (or your earlier) method to work. As usual, I am posting from work so check all syntax and commands (especially my use of (),[],{} and ""). If you are lucky, maybe CD or GB will see your post and give you a definite answer. I gave this one a shot as I hate to see questions go unanswered. ;)


                                                            Wadmann  
Check out my Camouflage Collection! New items added 31 July 2005.

Uldics

  • Guest
Re:Trigger for any AI
« Reply #2 on: 01 May 2004, 09:20:57 »
This (foreach) is working, but only for units who are inside the trigger at the beginning. Also when all the west units leave the trigger and one of them returns, its working for him, but not for the second unit who returns after the first one. Because trigger is already activated when the second enters area - he doesnt get any eventhandler. If there just was something like in thislist, but "justleftthislist", if you know what i mean  :)
I want every west unit in trigger area to be protected, allways inside and never outside. By the way I dropped the additional files, now my trigger activation field looks like:
"_x addEventHandler [""hit"",{_this select 1 setDammage 1; _this select 0 setDammage 0}]" forEach thislist
But the problem still persists: only the first one entering the area gets protection (or all inside the area at the beginning).

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Trigger for any AI
« Reply #3 on: 02 May 2004, 02:23:18 »
The method you're trying to use isn't really the best way...

To do this via the sort of trigger you've got you would need one trigger for every unit on the map.

I think you'd be best to use a trigger/script combo like this one:


Trigger

Radius: covering spawn
Condition: West present (repeatedly)
Name: wspawntrig
Condition Field: (west countside thislist) != wcount
OnActivation Field: "_x exec {spawnkill.sqs}" foreach thislist; wcount = (west countside thislist)


init.sqs (or the init field of a unit)

wcount = 0


Spawnkill.sqs

_this addeventhandler ["hit",{(_this select 1) setdammage 1; (_this select 0) setdammage 0}]

@ not (_this in list wspawntrig)
_this removealleventhandlers "hit"
exit


You'll need a separate trigger for the East/Guer/civ spawns,  though you can probably modify the same script to service them all ;)

A single trigger can't really track multiple units, as it can't tell when a certain unit is not in it's radius any more. If it only had to deal with a single unit, that'd be fine. However more than one and there simply isn't any easy (read: sensible ;D) way around that by using only one trigger.

Anyway try something like that and see how you go.

Uldics

  • Guest
Re:Trigger for any AI
« Reply #4 on: 02 May 2004, 09:56:58 »
Thanks Sui! It works!
It doesnt work with units returning to the area, but I'll figure it out, I hope :)

I had made a try, which looked much alike yours, but was working only on one of the units. I thought my script wasnt possible to run on more than one AI. Maybe I messed up something with "this" or "_this". Or maybe because I started the script in every AI init field. I'm just beginning with the stuff :)

Uldics

  • Guest
Re:Trigger for any AI
« Reply #5 on: 02 May 2004, 10:28:03 »
Ok now I made it also working for the returning units. I think it should work also when respawning.

spawnkill.sqs :

#loop
_this addeventhandler ["hit",{(_this select 1) setdammage 1; (_this select 0) setdammage 0}]
@ not (_this in list wspawntrig)
_this removealleventhandlers "hit"
@ (_this in list wspawntrig)
goto "loop"
exit


As I see from the trigger, it doesnt matter what the condition is, thislist allways holds all units in trigger area.

Now I just need to test it on real players ;)