Home   Help Search Login Register  

Author Topic: Adding eventhandlers to script created units  (Read 498 times)

0 Members and 1 Guest are viewing this topic.

Demmun

  • Guest
Adding eventhandlers to script created units
« on: 24 Oct 2004, 00:48:28 »
Greetings,

The situation I have is this;

-I begin a mission with several enemy units scattered about the map that consist of a leader.

-As I approach the leaders, several units are created and grouped to the leader via a create unit script.

-An engagement occurs.

-The player wins and the dead bodies are removed when the player leaves the area.

-The player moves on to the next area where another leader is located and the create unit process happens again.

My idea here is to create a mission with what appears to be a great number of enemy units, but without the CPU lag that happens when the units are added directly to the map in the mission editor.

This process works great as is.


The problem I have is this;

-I am using an eventhandler added to the init field of the leaders that randomizes their accuracy. This random accuracy prolongs the engagements and creates a great effect.

-----this addeventhandler ["fired", {[_this select 0] exec "randomfire.sqs"}]-----

"randomfire.sqs" is my script that changes the accuracy of the units.

-The units that are created via script and grouped to the leaders do not use this eventhandler after they are created. Their accuracy remains unchanged and ruins the extended firefight effect.


My question is;

-How can I get the created units to use the eventhandler?

-Can I give the created units names when they are created? I could then use a trigger to add the evenhandler to each created unit.

-Can I simply add the eventhandler to the entire group at once via a trigger? If I can, what changes do I make to the syntax?

I am new to the creation and use of scripts and such so please keep that in mind when replying.

Any help you can give on this problem will be greatly appreciated.


Thank you in advance for any time you may devote to my problem.

-Demmun

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Adding eventhandlers to script created units
« Reply #1 on: 24 Oct 2004, 11:27:59 »
Quote
-How can I get the created units to use the eventhandler?

-Can I give the created units names when they are created? I could then use a trigger to add the evenhandler to each created unit

"SoldierWB" createUnit [pos,group,"soldierName=this; this addEventHandler [""fired"", {[_this select 0] exec ""randomfire.sqs""}]",skill,rank]

Now, no guarantees of course, but in theory that should work just fine...

Altough, if using this method the naming of the soldier becomes quite obsolete...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Demmun

  • Guest
Re:Adding eventhandlers to script created units
« Reply #2 on: 24 Oct 2004, 12:20:33 »
Thank you so much. I have been working on this mission for the last couple of days and this problem has been holding me back. Your solution worked perfectly.

Again, I thank you.

-Demmun