Home   Help Search Login Register  

Author Topic: targets  (Read 6778 times)

0 Members and 1 Guest are viewing this topic.

Offline 22jacket

  • Members
  • *
  • I'm a llama!
targets
« on: 10 Nov 2007, 02:35:01 »
Hi there,

How can I make the targets as in the training mission in arma come up and down either randomly or once shot once stay down and use a trigger say radio to bring them back up.

also how to count how many targets have been hit ie 30 round mag 30 targets how many down..after person has finished shooting

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #1 on: 10 Nov 2007, 10:38:42 »
I have written a whole script to do pretty much what you are asking, but I wrote it a very long while ago, so it is a bit grim (naive and over-complex) ;P I'll give you a shorter and simpler version instead, especially since my version was for a whole team running a FIBUA, which isn't quite what you want.

This script counts shots and hits, keeping the targets down once hit, until the player has shot them all or used too much ammo (To keep the target down, you need to animate the target when it is on the way up again, not on the way down):
Code: (shooting.sqf) [Select]
_targets = _this select 0;
_maxShots = _this select 1;

shotsFired = 0;
numHits = 0;

// Detect when the player has fired a weapon.
_firedEventIndex = player addEventHandler ["FIRED",
{
shotsFired = shotsFired + 1;
}
];

// Detect when a target has been hit.
{
_hitEventIndex = _x addEventHandler ["HIT",
{
_target = _this select 0;
_shooter = _this select 1;

// Only allow the player to score the first time the target is hit.
_target removeEventHandler ["HIT", _target getVariable "targetHitEventIndex"];

// Only add score for the local player.
if (_shooter == player) then
{
numHits = numHits + 1;
};

// Animate on every client though.
if (not (isNull player)) then
{
[_target] spawn
{
_target = _this select 0;

// Wait until the target is completely flat on the ground.
waitUntil {(_target animationPhase "terc") == 1};

// Wait until the target starts moving up.
waitUntil {(_target animationPhase "terc") != 1};

// Push the target back down again.
    _target animate ["terc", 1];
    };
   };
}
];

_x setVariable ["targetHitEventIndex", _hitEventIndex];
} forEach _targets;

// Keep going until used all allowed shots or hit all targets.
waitUntil { (shotsFired == _maxShots) or (numHits == (count _targets)) };

player removeEventHandler ["FIRED", _firedEventIndex];

{
// Make sure that the event handler has been removed.
_x removeEventHandler ["HIT", _x getVariable "targetHitEventIndex"];

// Raise the target again.
_x animate ["terc", 0];
} forEach _targets;

hint format ["You hit %1 targets out of %2 with %3 shots", numHits, count _targets, shotsFired];

From this, you can probably work out how to have a target down at the start of the mission or how to pop all the targets up from a trigger. Having them pop up and down at random makes things a lot more complex though. To achieve this, you could have a _targetsLeft array from which you remove one element at random each time, raising it for a short while and adding a hit event handler then lowering it and removing the hit event handler again).

** EDITED **
I hadn't properly tested it, but the script was longer than I should have written off the top of my head! Fine now.
« Last Edit: 10 Nov 2007, 11:34:34 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline 22jacket

  • Members
  • *
  • I'm a llama!
Re: targets
« Reply #2 on: 10 Nov 2007, 19:19:35 »
sorry to be a pain but is this set up by a trigger ...bit of a newie to editing xx

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #3 on: 10 Nov 2007, 23:35:58 »
This script can be called however you like, but it expects you to give it two parameters: an array of pop-up targets to use and the number of shots to allow the player. You could use a trigger to set it off, using all the targets within 1000m and allowing 30 shots:
Code: (trigger activation) [Select]
[nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";

Alternatively, you could set up the list of targets manually (in case you have a lot of firing ranges in the mission and it would be difficult to just pull in the targets with a nearestObjects command):
Code: (init.sqf) [Select]
targetsRange1 = [targetA, targetB, targetC, targetD];
targetsRange2 = [targetE, targetF, targetG, targetH];

Code: (trigger activation for range 1) [Select]
[targetsRange1, 30] execVM "shooting.sqf"

One issue unaddressed is that this script is not really MP compatible, which I would assume you'd want since you specifically asked the question in the MP forum (I answered the question, but forgot what the forum was; sorry!). The script really would get into a tizzy in MP, when I think about it! Before trying to add the complexity of a full MP-compatibility (which wasn't specificly mentioned in your original request), I think it better that you describe what level of MP you need: Do you need groups to run the ranges at the same time? Groups to shoot on a single range at a time? More than just the shooter to see the scores? What about JIP? What about people logging out in the middle of running a range? Argh, I hate MP ;P Anyway, more details of what you actually need would help...
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline 22jacket

  • Members
  • *
  • I'm a llama!
Re: targets
« Reply #4 on: 11 Nov 2007, 19:34:48 »
Its just for training..ie start of on 30 target range ....see how many they get in 30 rounds... also to test new weapons etc then advance to contact..move along targets pop up..then contact drills done...and cqb..in town..and sniper range

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #5 on: 11 Nov 2007, 22:20:05 »
Although that info is helpful, what I was really wanting to confirm was whether you wanted players to cooperate in the training or you just wanted individuals to do the separate ranges without interacting with each other (though I realise now that in the latter case, you might as well just write a single-player version, so I guess you didn't mean that!). The script I gave you was just a demonstration of how to count the number of shots and hits and display them at the end rather than a complete solution. What I was trying to explain in my last post was that it definitely wasn't multi-player compatible, so although it answers most of your direct questions, it doesn't supply you with everything you want (this is the forum asking specifically about multi-player game issues, so I assume that is what you want: a multi-player training/shooting range mission).

As I've said, I wrote a FIBUA training course script in the past, that allows groups to run through a town shooting targets, and I think I'd be better rewriting and that to be more generic (and releasing it properly) would be better than continuing to expand this "back of an envelope" script for you to completely satisfy your needs.

More importantly for now, I can't go any further on this at the moment, since I'm away from my ArmA machine for a few days.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline 22jacket

  • Members
  • *
  • I'm a llama!
Re: targets
« Reply #6 on: 12 Nov 2007, 22:49:49 »
ok dude ..cheers for your help so far xx :good:

Offline 22jacket

  • Members
  • *
  • I'm a llama!
Re: targets
« Reply #7 on: 19 Nov 2007, 22:10:44 »
just wondering,,,which is best way to do the fibua type range....walk along--trigger activates target to come up..

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #8 on: 19 Nov 2007, 23:25:20 »
That is probably the best way, though mine just had a lot of targets up with 70% chance of appearance so it didn't always look the same (Well, someone else made the FIBUA course; I just wrote the script). There was a trigger at the start to push all the targets up and reset the score...and one at the end to tell you the score. We also had the blue targets in to represent civilians that you weren't allowed to shoot.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Sig USMC

  • Members
  • *
Re: targets
« Reply #9 on: 25 Jul 2008, 09:08:37 »
How do you exec this in a trigger? Not familar with execVM. get a syntax error when adding to activation field. Sorry new at scripting
Quote
[nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";

I'm doing the same thing for my squad, here are some details that I could really use help on.

Rifle Range Objectives:

- MP compatiable
- 30 Targets (TargetE) named tg1-tg30
- Magazine Max count "1"
- Hit/Miss Count
- Display Score Values at the end of shooting session(190-209 = Marksman, 210-219 = Sharpshooter, 220-250 = Expert
- Reset Targets


Help would be greatly apprciated
« Last Edit: 25 Jul 2008, 10:17:29 by Sig USMC »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #10 on: 25 Jul 2008, 11:26:32 »
Unlike exec, execVM returns a value, so the editor requires you to use it, even though it is not required in a script context. Since we don't want to use the value, the absolute safest place to dump it is in a variable "nil" (since nil is a keyword, you can't actually extract the value from the "nil" variable, so it can't damage other code, which might happen if you put it into another variable).
Code: [Select]
nil = [nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";
I'd advise you just to use an init.sqf (or init.sqs) file instead though, since you shouldn't put init onto an object that isn't directly associated with it (if you put the init into all the player objects, then you get the script running once for each player. If you put it into just one player object, then it isn't run if no-one plays as that soldier in MP):
Code: (init.sqf) [Select]
[nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";
Your specific objectives are more complex (if you are new to scripting as you have said, you wouldn't be able to do it, even with help). If someone wants to write the script for you, then that is another thing ;P
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Sig USMC

  • Members
  • *
Re: targets
« Reply #11 on: 25 Jul 2008, 22:32:22 »
I appreciate the help Spooner, I got it working as you stated in the init.sqf. I guess the next step is trying to complete the rest of the objectives. The reset target animations are simple but I have to figure out how to do the scoring system afterwards.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: targets
« Reply #12 on: 26 Jul 2008, 01:24:29 »
Actually, I have an old script rotting away somewhere which does something quite close to what you are asking for. It is designed for a FIBUA style course though, so isn't quite the same as a range. I won't have access to the machine it is on for another week or so, but I'll get it to you then (if I forget, then please remind me ;P).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline weamdreaver

  • Members
  • *
Re: targets
« Reply #13 on: 10 Jun 2009, 16:07:51 »
This script can be called however you like, but it expects you to give it two parameters: an array of pop-up targets to use and the number of shots to allow the player. You could use a trigger to set it off, using all the targets within 1000m and allowing 30 shots:
Code: (trigger activation) [Select]
[nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";

I tried it with your script. I have set a trigger with on Act: [nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";
But I get an error message when I try to close the trigger. "Type Script, expected nothing"

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: targets
« Reply #14 on: 10 Jun 2009, 20:29:28 »
Try putting this, instead:
Code: [Select]
dummy = [nearestObjects [player, ["TargetEPopup"], 1000], 30] execVM "shooting.sqf";Note the "dummy =" in front.