Home   Help Search Login Register  

Author Topic: POW Capture/Join Group Script (DELAYED)  (Read 8964 times)

0 Members and 1 Guest are viewing this topic.

Offline norrin

  • Tutorial Writer
  • **
POW Capture/Join Group Script (DELAYED)
« on: 29 Oct 2007, 03:54:30 »
POW Capture/Join Group Script (revised script posted 19th April 2009)

by norrin (norrin@iprimus.com.au)

based on an idea by Bravo 6

With special thanks to Spooner at OFPEC for his help and suggestions

Description

The script adds an action to the group leader's action menu only when the group leader, a player within the group or an AI unit in the group is within 3 metres of a capturable/POW AI unit.  If the group leader then uses the action the AI unit joins his group and can be ordered around by the leader.

If the unit from your group moves away from the POW then the action will disappear but will reappear if the unit moves back to the POW.  If the group leader is killed and respawns then he will still get the action if a member of his group is within 3 metres of the POW.  Also if the POW dies or the POW joins your group or another friendly group the script exits and the action will not appear.

Test Mission
In the test mission there are three POWs.  Make sure you choose the team leader role and then just send an AI unit from your group to any of the POW.  When your team member or yourself are within 3 meters of the capturable unit the capture action will appear in the action menu.   Activate it and the POW should join your group, an icon for the POW appears in the group list in the bottom left-hand corner of the screen, it run towards you and take its place in your groups formation.

To implement
1. Copy across the info from the init.sqf and the POW_sqf folder into your mission directory
2. Name your POW units in the editor something like POW1, POW2 etc.
3. You need to define the units you want to be POWs in the _NORRN_POW array in the init.sqf.

eg:
Code: [Select]
_NORRN_POW = [POW1, POW2, POW3];
4.You'll need to place put this setCaptive true in the init line of each of your POWs so the enemy troops guarding them don't shoot them.

eg:
Code: [Select]
this setCaptive true
Limitations
* This script only works through the middle mouse scroll action menu, not when you use the action keys like: F2 (unit) + 6 (action) + 4 (Capture Pow).
* As each POW requires the group leader to run an instance of the script on his PC it maybe best not to use these scripts for too many capturable AI units.
* This code works with JIP to a limited extent as if a group leader who has liberated POWs in his group leaves the server you'll lose control of the POWs and it maybe impossible to complete an objective.  If this happens and then someone joins in the group leaders slot the POws will still be in your group however they may not appear as an icon in the leaders icons in the bottom left hand corner of the screen ie. they'll still follow you around but you may not be able to give them direct orders. Quitting and then rejoining in the leaders slot will sometimes fix this problem. 

Tested
Ver 1.08 and limited use with JIP (see limitations above).
« Last Edit: 19 Apr 2009, 12:48:30 by norrin »

Offline MattiusRochelle

  • Members
  • *
Re: POW Capture/Join Group Script
« Reply #1 on: 29 Oct 2007, 19:38:45 »
Super, Just what i need to make my Hostage Rescue Mission Work properly. I will be testing this out.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: POW Capture/Join Group Script
« Reply #2 on: 07 Nov 2007, 22:09:20 »
I don't think you need to mess about with triggers to discover when players connect. Instead, use this to ensure that the player object exists before running the scripts:
Code: (init.sqf) [Select]
if (not isServer) then waitUntil { not (isNull player) };
if (not (isNull player)) then
{
    [] execVM "POW_sqf\POW_Join_action.sqf";
    [] execVM "POW_sqf\POW2_Join_action.sqf";
};

You could unlimit the number of potential POWs (And prevent all the script repetition) by using code like:
Code: (init.sqf) [Select]
[pow1] execVM "POW_sqf\POW_Join_action.sqf";
[lostSoldier] execVM "POW_sqf\POW_Join_action.sqf";
[theColonel] execVM "POW_sqf\POW_Join_action.sqf";

The parameter passed could then be used to create dynamic code:
Code: (POW_Join_action.sqf) [Select]
_pow = _this select 0;
_group = _this select 3;

[_pow] joinsilent _group;
player sideChat "WE HAVE CAPTURED %1. OUT.", name _pow]; // You'd have to give the prisoner an identity for this to work well.
_captureVar = format ["%1_capture", vehicleVarName _pow];
call compile format ["%1 = true",  _captureVar];
publicVariable _captureVar;

Anyway, I see you are already using dynamic code in your script, so perhaps I didn't need to be so explicit. I'm sure you could work on what I've given to make it even better than what I'm suggesting.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline norrin

  • Tutorial Writer
  • **
Re: POW Capture/Join Group Script
« Reply #3 on: 08 Nov 2007, 10:44:11 »
M8 I'm still learning so thanks for your suggestions.  When I get a chance I'll update the script and incorporate your suggestions. :)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: POW Capture/Join Group Script
« Reply #4 on: 08 Nov 2007, 11:23:05 »
Glad the comments were useful. Don't worry, we are all learning every day, even Mandoble (I hope  :scratch:).

While I'm suggesting things, I think it might be possible to pass multiple soldiers to POW_Join_action.sqf and use a loop to check each of them, rather than starting multiple instances of the script:
Code: [Select]
[pow1, lostSoldier, theColonel] execVM "POW_sqf\POW_Join_action.sqf";

Not sure that would make a massive difference to load, but it might also make it easier to track how many of the POWs have been captured this way, so you could pass a number from the join to the capture script and say "We've captured Fred Bloggs, the third POW of five" in the capture script. Of course, you could just use a global variable to communicate this sort of information between the instances of the scripts, but that seems unnecessary to me.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline norrin

  • Tutorial Writer
  • **
Re: POW Capture/Join Group Script
« Reply #5 on: 23 Nov 2007, 12:25:14 »
Sorry for my mistake Spooner but I misinterpreted what you said in one of my other threads.
When you update a script, you should tell us in a new post, but put the new version in the original post and remove any older versions from that post.

I thought this meant you wanted a new thread but I can see now you meant a new post.  Please feel free to delete the other thread. :-[

Anyway

POW Capture/Join Group Script Updated

Here's the revised script ready for testing.  It's been rationalised as you've suggested but its a bit of of hybrid as it still requires multiple instances (one for each POW) running on the group leader client's PC.

Description

The script adds an action to the group leader's action menu only when the group leader, a player within the group or an AI unit in the group is within 3 metres of a capturable/POW AI unit.  If the group leader then uses the action the AI unit joins his group and can be ordered around by the leader.

If the unit from your group moves away from the POW then the action will disappear but will reappear if the unit moves back to the POW.  If the group leader is killed and respawns then he will still get the action if a member of his group is within 3 metres of the POW.  Also if the POW dies or the POW joins your group or another friendly group the script exits and the action will not appear.

Test Mission
In the test mission there are four POWs including a BLUFOR pilot and OPFOR unit.  Make sure you choose the team leader role and then just send an AI unit from your group to any of the POW.  When your team member or yourself are within 3 meters of the capturable unit the capture action will appear in the action menu.   Activate it and the POW should join your group, an icon for the POW appears in the group list in the bottom left-hand corner of the screen, it run towards you and take its place in your groups formation.

To implement
1. Copy across the info from the init.sqf and the POW_sqf folder into your mission directory
2. Name your POW units in the editor something like POW1, POW2 etc.
3. You need to define the units you want to be POWs in the _NORRN_POW array in the init.sqf.

eg
Code: [Select]
_NORRN_POW = [POW1, POW2, POW3, POW4];

Limitations
* This script only works through the middle mouse scroll action menu, not when you use the action keys like: F2 (unit) + 6 (action) + 4 (Capture Pow).
* As each POW requires the group leader to run an instance of the script on his PC it maybe best not to use these scripts for too many capturable AI units.

Tested
Ver 1.08 with JIP.
« Last Edit: 25 Nov 2007, 11:46:10 by norrin »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: POW Capture/Join Group Script
« Reply #6 on: 23 Nov 2007, 12:36:57 »
Oops, I remember that; I was actually telling you that you need to fully update the original post with any new versions rather than have an old version in the original post and make the reader search for the latest version somewhere near the end of the thread! As well as updating the file in the original post, you should update the text there to reflect the new version. Basically, anyone coming brand new to the thread should be good to go by reading the first post and downloading the attached file, without needing to go further at all.

Never mind, I understand your mistake and I'll delete the other thread in a couple of days, but it can serve as a warning/reminder to others in the mean time ;P

EDIT: You also should also only have one copy of the script downloadable in the thread (in the original post). If you make 20 releases over time, then you'd need to continually be updating all of them, which is unnecessary. It also fills our server with unnecessary copies of the file if you attach the same file again and again.

EDIT2: I've started testing this version.
« Last Edit: 23 Nov 2007, 12:57:51 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: POW Capture/Join Group Script (TESTING)
« Reply #7 on: 23 Nov 2007, 14:37:50 »
Nice script, but still some issues (I wouldn't worry too much about having to have one script instance running per POW, since there are unlikely to be dozens of them). Just because I've given a long list doesn't mean that I don't like the script, and some of the suggestions are not strictly necessary, but I thought I'd mention them:

1) You could be more explicit and say that everyone in the demo mission has "this setCaptive true" on them, so that there isn't any fighting, but in a real mission, you'd just make the POWs captives. I'd also remove weapons from the POWs in the demo, but that is just for aesthetic reasons and isn't important.

2) In capture.sqf, you broadcast data every few seconds:
Code: (capture.sqf) [Select]
NORRN_POW_string = call compile format ["'We Have Liberated POW: %1, Remaining Unliberated POWS: %2'", name _unit, _remain_POWS];
sleep 1;

publicVariable "NORRN_POW_string";
sleep 1; 

NORRN_POW_captured = true;
sleep 1;

publicVariable "NORRN_POW_captured";
sleep 5;

NORRN_POW_captured = false;
sleep 2;

publicVariable "NORRN_POW_captured";

This could cause no end of trouble with data synchronisation if two players capture someone within a few seconds of each other (MP only, of course). You should do:
Code: (capture.sqf) [Select]
NORRN_POW_string = call compile format ["'We Have Liberated POW: %1, Remaining Unliberated POWS: %2'", name _unit, _remain_POWS];
publicVariable "NORRN_POW_string";

And in the trigger initialisation:
Code: (trigger_mkr.sqf) [Select]
_trig_0 setTriggerStatements ["NORRN_POW_string != """";", "titleText [NORRN_POW_string, 'PLAIN', 0.7]; NORRN_POW_string = """";",""];

This still isn't perfect, but it requires people capturing POWs frames apart, rather than several seconds apart, for it to fail.

3) This code will only work if all of the players have been named in the editor (which you haven't asked for in the documentation):
Code: [Select]
call compile format ["capture_%1_%2 = %1 addAction [""Capture %2"", ""POW_sqf\capture.sqf"",[_unit, _group,_NORRN_POW], 0, false, true]", player, _unit];

If the players aren't varnamed, then %1 could have spaces in and ruin the creation of the capture_%1_%2 variable. In truth, though, you don't need the player's varname in the captured variable, since it isn't ever broadcast and it is always equal to player anyway. It also doesn't have to be global, since it is only ever referenced in that script. Save the mission designer some effort and use the simpler:
Code: [Select]
call compile format ["_capture_%1 = player addAction [""Capture %1"", ""POW_sqf\capture.sqf"",[_unit, _group,_NORRN_POW], 0, false, true]", _unit];

You'd need to change any script that assumed the player varname was in the captured variable too.

4) It would be nice to have the instructions in a readme.txt (just copy-and-pasting the release documentation from the forum would be fine).

5) When you make the action labels and messages, you just format the varname of the POW into it (e.g. "Capture POW1" action). It would be better if you used their name (name _unit) instead since then it is more human-friendly. This also prevents the mission-maker from using even more unreadable names, such as this_guy_is_a_POW_and_needs_releasing, which is fine as a variable name (if you like typing!), but not as a name shown to players.

6) If you recalculate "_group" every time you use it in POW_join_action.sqf, then the script won't be broken in missions where you can change groups in-game (such as Evo).

7) You might like to look at the "{ } count _array" version of count to simplify some of your code (Not important at all, but just thought I'd tell you about it)

8) Seemed to work fine in SP, though SIX_misc addon threw up an error for some reason (which didn't affect your script). I suspect it might be a global getting overwritten; You've used you NORRN tag on some of the globals, but not on others (such as:
Code: [Select]
call compile format ["POW_%1 = false", _unit];

which could overwrite a variable using the POW_ tag).

9) Not actually JIP compatible since anyone joining after someone has been captured will not be aware of this, since all the POW_* variables will be false (not a problem, but you should list it as a limitation).

10) Once released, POWs should really be unset as captives. This prevents players from using the release action until they think it is safe and prevents the player giving them a gun and using them as stealth troops ;P If the POWs stayed in a separate group and just followed the player group around, then leaving them as captives might be reasonable.
« Last Edit: 23 Nov 2007, 14:40:54 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline norrin

  • Tutorial Writer
  • **
Re: POW Capture/Join Group Script (TESTING)
« Reply #8 on: 23 Nov 2007, 22:47:28 »
Thanks Spooner its really great to get some feedback on this stuff - you're not only teaching me some new scripting tricks you're making the existing code a lot more efficient.  With a bit of luck I'll get the changes made and posted Sunday night.

Offline norrin

  • Tutorial Writer
  • **
Re: POW Capture/Join Group Script (TESTING)
« Reply #9 on: 28 Nov 2007, 02:10:29 »
I've updated the code, included a readMe.txt file and posted it at the top of the thread.

I've tried to set it up a bit better for JIP but there are still limitations as if a group leader who has liberated POWs in his group leaves the server you'll lose control of the POWs and it maybe impossible to complete an objective.  If this happens and then someone joins in the group leaders slot the POws will still be in your group however they may not appear as an icon in the leaders icons in the bottom left hand corner of the screen ie. they'll still follow you around but you may not be able to give them direct orders. Quitting and then rejoining in the leaders slot will sometimes fix this problem.

I was also wondering whether I should set up a second array in the init.sqf which contained the leaders names so that the scripts would only run on the leaders PC eg.
Code: [Select]
if (!isServer) then {waitUntil{!isNull player}};

_NORRN_POW = [POW1, POW2, POW3];
_NORRN_leader = [p1, p2]

if (isServer && time < 2) then {{call compile format ["NORRN_POW_%1 = false; publicVariable 'NORRN_POW_%1'", _x]} forEach _NORRN_POW};

if (!isNull player && player in _NORRN_leader) then
{
{[_x, _NORRN_POW]execVM "POW_sqf\POW_join_action.sqf"} forEach _NORRN_POW;

};
[] execVM "POW_sqf\trigger_mkr.sqf";

if(true) exitWith {};

or put this at the start of the  POW_Join_action.sqf
Code: [Select]
if (!local player || player != leader group player) exitWith {}; 

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: POW Capture/Join Group Script (TESTING)
« Reply #10 on: 28 Nov 2007, 10:22:02 »
The JIP problem should only be an issue in AI-enabled JIP missions, since the leader would become an AI when the leader left. Should be OK if you disable AI in the description.ext. Still, I haven't tested this, so I can't say if that would resolve the issue.

The problem with only running the script on the leader's machine is that if a leader dies, then the new leader wouldn't be able to take over, or the original leader take over again if he re-spawns. You could also get a new leader if mission is JIP (With AI-disabled) or if the mission allows players to change groups. Consider adding something like:
Code: [Select]
while { player != (leader player) } do
{
     sleep 10;
};
Inside the top of the main loop in POW_join_action, to keep non-leaders from doing to much CPU work.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
Re: POW Capture/Join Group Script (TESTING)
« Reply #11 on: 22 Feb 2008, 19:41:46 »
Hi, guys, I love this script, it was what takes to do my mission but I think I found 2 minor bugs.

1st one, and more relevant, it seems that , if you use any civilian model, we receive a error mesage shown in the picture above:

http://img.photobucket.com/albums/0903/Charlis/Internet%20Host/arma2008-02-2214-36-14-48.jpg

As I'm very cuirious, I noticed that any of the words in the message doesn't match any part of the script, so like sponer said, it does'nt affect it, and besides the anouying error message, everything else works fine.I also tried, moodifing the mission.sqm and changing unit class type and grouping the civilian model to a dead higher ranking west soldier, both didn't work. seems a problemem with civilian model config or classes maybe.

Edited: Forgot to say, seems that the error message, apeares when weapon is fired next to the civilian unit.

2nd, Don't know why but the hint about the "X pow recovered, Y pow to recover" just works at the first released pow, the other recovring happens but no hint is diplayed.

That's it, thank very much for the script, and the knowledge i'm getting to fussing into missions editing.

sorry for my english and best regards.

Charlis
« Last Edit: 22 Feb 2008, 20:00:30 by Charlis »

Offline norrin

  • Tutorial Writer
  • **
Re: POW Capture/Join Group Script (TESTING)
« Reply #12 on: 23 Feb 2008, 05:11:20 »
Hi Charlis,

Thanks for your email.  The first bug you describe is very weird and I don't think it is directly caused by the POW script, as you suggest there is no code like this in the POW script.  The POW script however, maybe causing a conflict with another scipt you are using or another script maybe responsible for this error - what other scripts are you using?

Anyway I'll look into the second error and see if I can improve it.

norrin

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
Re: POW Capture/Join Group Script (TESTING)
« Reply #13 on: 25 Feb 2008, 16:27:46 »
Thank you for the reply, I'l check the terms in th messege on other scriptys i'm using and then i'll list all of them here.
The funny thing thing is that it is only happening for civilian models. But I'll check the others anyway.

Offline Charlis

  • Members
  • *
  • I'm a llama!
    • ARMABR
Re: POW Capture/Join Group Script (TESTING)
« Reply #14 on: 12 Mar 2008, 00:09:20 »
Hi all, well, finally I had some time to play a little again in editor...
I was using, Cheta Holster script, Kromsky UPS, and a script to explode mines at the back of engineers, but after removing all of them, the mesage keeps happening.
Actually, I edited your test mission, as it doen't use any other scripts and wen I change one of he pows for a civilian,  after just shoot some rounds near the civilian, here comes the message again so, probably, there must be any conflict with "native Arma scripts".
Besides that, everything works fine. its just that the message anoying all the time! I think I'm gonna have to change my missions history or get used to the error.

Well, not really a new but I hope that the reports could help you fix and make things even better.

Thanks again, best regards