Home   Help Search Login Register  

Author Topic: Needed: Script to test for a unit killed by player  (Read 411 times)

0 Members and 1 Guest are viewing this topic.

Dagon

  • Guest
Needed: Script to test for a unit killed by player
« on: 27 Feb 2005, 11:52:16 »
Hi there. It's been a while since I last posted (new computer, new games, yay) but I've started working on some OFP missions again. Anyway, for one of the missions i'm working on at the moment, I need a script to:

Determine if the player kills a unit on the "EAST" side within a trigger, and will set the variable "PlayerAttacks" to "TRUE".

So, when the player is inside the base (in enemy uniform, but on the resistance side - he's setcaptived, hence the need for the playerattacks variable), if he attacks any of the russian units, the playerattacks variable gets set to true - and the playerattacks script turns off his captive status and sets off the alarm as well as dispatching guards all over the place. However, if he encounters some russians, say, in the bush 8 miles away, the script won't be set off (optionally, multiple versions of the script could be used for each location.)

Since the player will have no silenced weapons, this doesn't need a test to make sure the units know the player exists - just one to test wether he's killed any units.

Bonus points if the script can be activated from outside the trigger region - in case, for example, the player plants a whole bunch of satchel charges then leaves the region before blowing them up, the alarm will still be sounded. Etc etc.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Needed: Script to test for a unit killed by player
« Reply #1 on: 27 Feb 2005, 12:57:55 »
Try running this

{{_x AddEventHandler [{killed}, {if ((_this select 1) == player) then {PlayerAttacks = true}}]} forEach (crew _x)} forEach list triggername

It will put a killed event handler on each loon in the trigger area that activates when the loon is killed and checks to see if they are killed by the player.  Note that if they leave the trigger area they will keep the event handler.

You could also try making the trigger cover the map and then running:

{{_x AddEventHandler [{killed}, {if ((_this select 1) == player) then {[_this select 0] exec "PlayerKilledLoon.sqs"}}]} forEach (crew _x)} forEach list triggername

Then in:
PlayerKilledLoon.sqs
You could check where the loon is when the player kills him.
NB the dead loon will be _this select 0 in the script


Anyway - a few ideas for you to be playing with

« Last Edit: 27 Feb 2005, 13:00:55 by THobson »