Home   Help Search Login Register  

Author Topic: Converting script from OFP to ArmA  (Read 2066 times)

0 Members and 1 Guest are viewing this topic.

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Converting script from OFP to ArmA
« on: 16 Sep 2007, 20:34:52 »
I'm trying to convert General Barron's info share script from OFP to ArmA... (I hope it's OK). I put the scripts in a test mission and did everything as he suggested, but it doesn't seem to work. I don't get any errors or anything. Here are the scripts:

infoShare.sqs
Code: [Select]
;=================================================================================
;=================================================================================
;infoShare.sqs
;by General Barron
;aw_barron@hotmail.com
;12/20/03

;This script makes friendly units that are near each other share information on enemy locations (i.e. they reveal the enemies to each other).
;It prevents the common problem of one group shooting at some enemies while another group 5 meters away dumbly faces the other direction,
;doing nothing. With this script, the other group would turn around and also shoot at the enemy.

; To use the script, put the script and the function "knownEnemies.sqf" in your mission folder. Put this line in your init.sqs:
;      knownEnemies = preprocessFile "knownEnemies.sqf"

; To call the script:
;      [unit, [array of friends], [array of enemies] ] exec "infoShare.sqs"

;Unit = leader of the group to be sharing the information. If the unit is not the leader of his group, the script will exit.
;[array of friends] = an array of units that the group will reveal the enemies to.
;[array of enemies] = an array of units that will be considered the enemy, and revealed to the friendly units

; The easiest way to call the script:
;Make a trigger, covering the entire mission area. Activation = once, "west present". In the "on activation" field, put: "west_units = thisList"
;Make another trigger, same as above only for east. (activation = once, "east present", on activation = "east_units = thisList")
;In init.sqs, put the following lines:
;      knownEnemies = preprocessFile "knownEnemies.sqf"
;      {[_x, west_units, east_units] exec "infoShare.sqs"} foreach west_units
;      {[_x, east_units, west_units] exec "infoShare.sqs"} foreach east_units

;This will make all the west units share information with each other on all the east units, and vice versa.
;The script will run on each group until all the units in that group are killed.
;=================================================================================
;=================================================================================


_unit = _this select 0
_friends = _this select 1
_enemies = _this select 2

_maxRange = 50
     ;//Maximum distance (in meters) units can be from each other and still share enemy locations
     ;//If you want all units to share information, regardless of distance, set this to 9999
_delay = 5
     ;//Delay (in seconds) between loops. E.g. a delay of 5 means the groups will share info every 5 seconds.
     ;//Lower values mean shorter delays, but can slightly increase lag with large numbers of units.

?_unit != leader group _unit : exit
_group = group _unit
~random _delay

#Loop
_knownEnemies = [leader _group, _enemies] call knownUnits
_i = 0
   #InnerLoop
     _unit = _friends select _i
     if ({(_unit distance _x) <= _maxRange} count (units _group) > 0) then { {_unit reveal _x} foreach _knownEnemies}
     _i = _i + 1
  ? _i < count _friends : goto "InnerLoop"
~_delay
?count units _group > 0 : goto "Loop"
exit

knownEnemies.sqf
Code: [Select]
/*knownUnits.sqf
By General Barron
aw_barron@hotmail.com
11/15/03

This returns a list of units detected by the passed unit. List is sorted in order of closest to farthest. To call:
[detector, [units to detect from]] call knownUnits

Usage example: make a trigger, covering entire map, activation = once, "east present". On activation = "east_units = thisList"
Make another trigger. Condition = "count ([player, east_units] call knownUnits) > 0". On activation = "hint "enemy spotted" "
The hint will appear once the player detects one or more east units.
*/

private ["_unit", "_list", "_return", "_numArray","_j","_k","_tempVal","_tempNum","_element"];

_unit = _this select 0;
_list = _this select 1;
_return = [];

{if ((_unit knowsabout _x) > 0.105) then {_return = _return + [_x]}} foreach _list;

/*-----------------------------------------------------------------------------------
Start bubble sort (sort units from closest to farthest)
Code taken from sortBubble.sqf
By bn880 2/24/2003
(slightly modified to fit in this function)
-----------------------------------------------------------------------------------*/

_count = count _return;
_numArray = [];
_numArray resize _count;

// ACQUIRE NUMERIC VALUES FROM EVALUATION
_j = 0;
while {_j < _count} do
{
_element = _return select _j;
_numArray set [_j,_element distance _unit];
_j = _j + 1;
};

_j = 0;
// SORT
while {_j < _count -1} do
{
_k = _j + 1;
while {_k < _count} do
{
if (_numArray select _j > _numArray select _k) then
{
_tempNum = _numArray select _j;
_numArray set [_j,(_numArray select _k)];
_numArray set [_k,_tempNum];

_tempVal = _return select _j;
_return set [_j,(_return select _k)];
_return set [_k,_tempVal];
};
_k = _k + 1;
};
_j = _j + 1;
};

_return

Do I need to change anything on either of the scripts to make it compatible with ArmA?

Sorry for the long post, by the way.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Converting script from OFP to ArmA
« Reply #1 on: 16 Sep 2007, 21:57:09 »
yes, you need first to compile the file to call it.

in your infobase add:
Code: [Select]
knownUnits = compile (preprocessFileLineNumbers "knownUnits.sqf");

This way you can later call knownUnits.

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Converting script from OFP to ArmA
« Reply #2 on: 16 Sep 2007, 22:46:38 »
Hmm, ok, I added that, but it still doesn't seem to work. Anything else I need to do?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Converting script from OFP to ArmA
« Reply #3 on: 16 Sep 2007, 23:22:11 »
Everything else seems quite ArmA compatible.

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Converting script from OFP to ArmA
« Reply #4 on: 17 Sep 2007, 00:19:11 »
I found the problem - The script shouldn't be executed from the init.sqs script, but in a trigger or other script, after the start of the mission.
Thanks for your help though making it ArmA compatible! :clap: