Home   Help Search Login Register  

Author Topic: Attaching Flare Trap Script to a placeable object  (Read 872 times)

0 Members and 1 Guest are viewing this topic.

Nesto

  • Guest
Hey everyone,

Just wondering if it's possible to link the Flare Trap script to a placeable object..

Basically I need a night mission where the team needs to defend a camp and I'd like to link a bunch of Flare Trap scripts to an object the players can pick up and plant on the ground (like a mine or something to that effect).

Any thoughts, is this even possible?

Kaliyuga

  • Guest
Re:Attaching Flare Trap Script to a placeable object
« Reply #1 on: 19 Dec 2002, 23:25:16 »
an object the players can pick up and plant on the ground (like a mine or something to that effect)



 It's possible... but that would be called an add-on ;)


Bremmer

  • Guest
Re:Attaching Flare Trap Script to a placeable object
« Reply #2 on: 20 Dec 2002, 02:12:14 »
Not necessarily - the objects could simply be created from an action menu, of prevoiusly created in the editor, placed in a discrete location and then moved to the correct point when the unit 'places' them (this is the method used in one of the Red Hammer missions - its also the method I would recommend as it allows you to prename the objects. Simplest is usually best in my book).

OK so heres how I would do it ->

Create the maximum number of available objects in your mission (lets say 10) and name them obj1 ... obj10. Next you want to create an array of the objects; in an init line or file put objarray = [obj1,obj2,obj3....obj10] (obviously including all the object names). Also initialise an index that will pick objects from the array and check if all the objects have been used; put objindex = 0 in an init line or file.
Give the player an added action by puting place = player addAction ["Place Object","place.sqs"] in their init field. The script for placing the object should look something like this:

Code: [Select]
;place.sqs
;select the next object
_obj = objarray select objindex
;position the object in front of the player
_obj setpos [(getpos player select 0) + 2 * sin (getdir player), (getpos player select 1) + 2 * cos (getdir player)]
_obj setdir getdir player
;increase the index so the next object is selected
objindex = objindex + 1
;check whether to remove the added action
? objindex > 9 : player removeaction place
[_obj] exec "flaretrap.sqs"
exit

Now to add the flare trap. First we need a list of all units except the player (we don't want him setting off his own traps) -> set up a trigger covering everyone on the map. Set it to anyone present, and make the on activation allunits = thislist - [player]. We already activted the flare trap script using the place script, so all that is left are the details of that script:

Code: [Select]
;flaretrap.sqs
;get the object
_obj = _this select 0
#loop
~2
;check if there are any units within 10m of the trap
? "_x distance _obj < 10" count allunits == 0 : goto "loop"
;create the flare
_flare = "flare" camcreate [getpos _obj select 0, getpos _obj select 1, 100]
exit

Note that I used a loop in preference to @ as it will eat up less cpu time (especially if allunits is a big list).

Hopefully this is along the lines of what you are looking for, if not then I'm sure we can come up with something else.

 :)

Offline Dinger

  • Contributing Member
  • **
  • where's the ultra-theoretical mega-scripting forum
Re:Attaching Flare Trap Script to a placeable object
« Reply #3 on: 20 Dec 2002, 08:05:16 »
Use mines. Put a "Fire" Eventhandler on the mine.  When it fires, use nearestobject to interceive the fired object.  Then call an array that you've indexed your flaretrap triggers to, and put one on the spot. Orient to the facing of the player, not the mine, since the latter is random.
Good luck.
Dinger/Cfit

Nesto

  • Guest
Re:Attaching Flare Trap Script to a placeable object
« Reply #4 on: 23 Dec 2002, 00:18:55 »
Those are some interesting ideas,  I'll try it out this weekend.

Thanks,

Nesto