Home   Help Search Login Register  

Author Topic: Detecting Units And Storing Them In A Variable  (Read 1369 times)

0 Members and 2 Guests are viewing this topic.

RunAwayScientist

  • Guest
Detecting Units And Storing Them In A Variable
« on: 24 Jun 2004, 23:00:36 »


        What specific commands in a script can I use to detect a unit and store it in a variable for later use?

      For example, there's a dead soldier on the ground and you have a script running which, when the dead soldier is detected infront of a player, will add an action to that player to call an ambulance. The player calls the ambulance, the ambulance moves to the dead guy, puts him in the ambulance, and it drives off (No use saving dead guys!).
 
  Something like, "NameOfPerson = TheUnitNearPlayer". Then use scripts to detect if "TheUnitNearPLayer" is damaged. "?(Damage NameOfPerson >= 0.5): NameOfPerson addaction ["(Radio Ambulance)", "RadioAmbulance.sqs";exit"


         I think this would be helpful if the unit doesn't have a name either. In another example, you'd have a script running which would tell any East soldier (during a scenario) to surrender if he is damaged too much and give up. It would detect any SOLDIER, which wouldn't apply to a tank crew or such.

         Are there specific class names that you could apply? Maybe detecting if there is a tank infront of you instead of a man.

---RunAwayScientist

RunAwayScientist

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #1 on: 10 Jul 2004, 00:40:23 »

      Any ideas?

--RunAwayScientist[AF]

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Detecting Units And Storing Them In A Variable
« Reply #2 on: 10 Jul 2004, 03:29:56 »
Hmm... not sure if I get what you're getting at there, Runaway...

So you want the player to walk up to a dead (or dying) unit, and you want it to be added to an array?

The best thing I can think of is to run a script in the background checking the player's knowsabout values against all units... eg.

? (player knowsabout unit1) and not (alive unit1): array = array + [ unit1 ]

Not sure if I'm hitting anywhere NEAR the head of the nail here...

ponq

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #3 on: 10 Jul 2004, 11:30:54 »
Just theory...but maybe this could work:

place a trigger on your map:
activation anybody (or a side), once
present

condition: this

OnActivation: UnitList = thislist
_____

This trigger stores all the units (of a side or anybody) in the array UnitLIst.

Now you need a script which checks the health of all the soldiers:
Code: [Select]
ActionAddedAlready = False
_i= 0
#loop
?ActionAddedAlready: goto "WaitAWhile"
~0.01
;select the dude from the list
_dude = Unitlist select _i

;get the dmg of the dude, and if dmg go add the action
_dmg = GetDammage _dude
?(_dmg > = 0.5): goto "HelpTheDude"

;add 1 to _i so the next dude gets grabbed.
_i = _i +1
? _i >= (count UnitList): _i = 0

goto "loop"

#WaitAWhile
~1
goto "loop"

#HelpTheDude
;first we check if the player is near the dead guy
;if the player is more than 5 meters away we won't addaction:

_dis = player distance _dude
?(_dis > 5): goto "Loop"


;here you add the action
;and we don't want a dozen addactions to run at the same time, so we set the check boolean to true, so the sciprt won't search the next dmg-ed dude until we set this boolean false again.
ActionAddedAlready = True
z = _dude addaction ["Call for Ambulance", "ambulance.sqs"]
goto "Loop"

Now it is important to add this line at the top of the Ambulance.sqs:
Code: [Select]
ActionAddedAlready = FalseThis will reset the boolean, so we can add a new action.

You'd also want to remove the Action again.

_____

Instead of using the trigger to get all the units, you could prolly also add a EventHandler "Killed" to all the units. And when they get killed, just add them to the array UnitLIst.

____

Again, I haven't tested this. But I hope it works.

RunAwayScientist

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #4 on: 10 Jul 2004, 22:45:26 »

     Damn! Nice script! It takes intellegence to understand something, but it takes a genius to make it!

   What the heck is a boolean?

  Does the UnitList select _i select a random unit from the list? Obviously it's a list like [Unit1,Unit2,Unit3], but does the _i make it random or something? I have no idea.

     No, my original question was to get the name of the unit standing infront of another unit. For example, if Unit1 is standing infront of Unit2, I want to get the name of that unit.

    I assume I'm working with units WITHOUT a pre-determined name....Such as a randomly created AI out of no where.

GuyStandingInfrontofUnit1 = GetTheNameOfTheGuyStandingInfrontOf Unit1

GuyStandingINfrontOfUnit1 setDammage 400000

exit


Something like that. Is there a command to find a unit that's infront of another unit, or maybe even 2 meters from him. Some sort of global variable command that searches for the closest unit to another unit?

  You guys have some funny avatars....A brown migit puppet, and then a sleek looking race car. What'll they think of next? (Flying sleek race cars flown by brown puppets with migits)

     My idea is something like the "Hide  Body" command that pops up with the special ops guys and dead bodies.


--RunAwayScientist[AF]

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Detecting Units And Storing Them In A Variable
« Reply #5 on: 10 Jul 2004, 22:58:54 »
In this context a boolean is a type of variable which can be either true or false.     They are very common in mission design and are often used to "switch on" (or off) triggers, loops, scripts, etc..   Boolean isn't that great a word to describe this sort of variable (perhaps "binary" would be better) but its in common use on this site.

There is nothing special about the variable name:  any allowed variable name in OFP can be used for a boolean or non-boolean variable.

(It is named after a George Boole, an English mathematician of the 19th century.   It's all to do with and, or, not and so on.    Google doubtless has more.)
Plenty of reviewed ArmA missions for you to play

ponq

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #6 on: 10 Jul 2004, 23:08:09 »
@RunAwayScientist

You can search for the nearest unit. Use the distance command for that

_dis = unit1 distance unit 2

I don't exactly get what you want though. Could you describe a situation with what you want? Does it only apply to the player to do the newaction? Is this for SP or MP?

Carpaazi

  • Guest
Re:Enemy surrebder if too much dmg
« Reply #7 on: 12 Jul 2004, 12:20:49 »
I also would like to know if any "genius" could write a script (if there ain't already) that would notice if enemy unit has taken too much dmg, like hit in the arms and couldn't shoot good anymore or some specific dmg amount and would give up and surrender.

That surely would give atmosphere to missions

Lihamatti

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #8 on: 12 Jul 2004, 17:10:58 »
Thanks Ponq. I needed that kind of script too. The only problem I'm having is that if a man enters the triggered area, the UnitList will change (the entered man will replace some other man's number (already in triggered area), I haven't tested but I guess it will replace Unitlist select 0) Anyone got this same problem, or is it just me doing something wrong? Any solutions?

Lihamatti

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #9 on: 12 Jul 2004, 18:12:48 »
Damn, now I got more problems and I can't figure out what's wrong. This is driving me crazy  >:(

I made a very simple script for testing but I can't get it to work and have no idea what could possibly be wrong. Here is the script:
Quote
_player = _this select 0
_i = 0
#loop
~1
_man = unitlist select _i
?(getdammage _man > 0.1) : goto "kill"
_i = _i + 1
?(_i > 2) : _i = 0
goto "loop"

#kill
_player setdammage 1
exit


I have made a trigger, which activates by anybody, and in "on activation" I wrote: unitlist = thislist
I have 2 men in the trigger area and the player (name player) + 1 man outside area with init: [player] exec "myscript.sqs"
Someone know what the heck is wrong?

ponq

  • Guest
Re:Detecting Units And Storing Them In A Variable
« Reply #10 on: 12 Jul 2004, 18:54:00 »
the player init's field is likely executed before the trigger is even initialized.

I suggest you call the script from the trigger itself:
unitlist = thislist; [p1] exec "myscript.sqs"

I don't know about the name "player". Player is a reserved name I think, I'd say use p1.

And in reaction to #8, the unitlist will be updated. But why is that a problem? Once you spot a "candidate" you get out of the list to do some more checks on him anyway.
« Last Edit: 12 Jul 2004, 19:09:06 by ponq »