OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: penguinman on 02 Jan 2006, 00:52:23

Title: Flare support script gives errors
Post by: penguinman on 02 Jan 2006, 00:52:23
Hello, Triggerhappy helped me make this script but he had to go on vacation so cant help fix the errors.

It is suposed to use a trigger to detect the player and the script finds out which group detected him, and then a flare shoots up over the the group that detected the player and 2 or 3 support groups from a support array come the assist in hunting down the player.

Code: [Select]
;array for grup leaders of the detecting group
_aleaders=[(agl1),(agl2),(agl3)]

;array for available supporting groups
_support=[supg1,supg2,supg3,supg4]

;finds what group detected the player
_mindis = 999999
"?_x distance player < _mindis:_mindis = _x distance player;_x = _closest" foreach _aleaders
_flarepos = getpos _closest

;sends up a flare over the detecting group
_flare="Flare"camcreate [getpos _closest select 0, getpos _closest select 2, (getpos _closest select 2)+10]
_flare setvelocity[0,0,50]

;chooses 2-3 random groups out of support and sends them over to the flare position
_r = (random 1) + 2.5
_r = _r - (_r mod 1)

#loop
_r = _r - 1
_c = (count _support)
_i = (random _c)
_i = _i - (_i mod 1)
_grp = _support select _i
_grp move flareposition
_support = _support - [_grp]
?_r = 0:exit
goto "loop"

does anybody see anything that could be causing an error.

thanks
Title: Re:Flare support script gives errors
Post by: Mandoble on 02 Jan 2006, 01:58:25
Change
_x = _closest
by
_closest = _x
Title: Re:Flare support script gives errors
Post by: penguinman on 02 Jan 2006, 05:51:05
i still get an error

Code: [Select]
_flare="Flare"camcreate [getpos _closest select 0, getpos _closest select 2, (getpos _closest select 2)+10]|#| error type any expected number
Title: Re:Flare support script gives errors
Post by: Planck on 02 Jan 2006, 06:16:00
You have a typo there:

_flare="Flare"camcreate [getpos _closest select 0, getpos _closest select 2, (getpos _closest select 2)+10]

Should be 'select 1' I think.


Planck
Title: Re:Flare support script gives errors
Post by: penguinman on 02 Jan 2006, 20:05:12
oh, your right! thank il see if that fixes it.
Title: Re:Flare support script gives errors
Post by: Igor Drukov on 02 Jan 2006, 21:43:24
The typo should not return that error message. The mistake comes from that line :

Code: [Select]
"?_x distance player < _mindis:_mindis = _x distance player;_x = _closest" foreach _aleaders

I'm not sure what you want to do here, but _closest is a "scalar bool array string 0xfcffffef".


[edit]
The same will be true with _closest=_x
[/edit]
Title: Re:Flare support script gives errors
Post by: penguinman on 03 Jan 2006, 02:28:16
so what would I do to fix it.


that part detects what group leader is closest to the player.
Title: Re:Flare support script gives errors
Post by: Igor Drukov on 03 Jan 2006, 08:01:59
No time to explain this in detail right now, but what you have to do is store the different distances into an array, and then SortBubble (http://www.ofpec.com/editors/funcref.php?letter=S#SortBubble) them.

Let me know if this sounds too much like Chinese :P
Title: Re:Flare support script gives errors
Post by: penguinman on 08 Jan 2006, 23:30:36
I dont understand this. how do you work it
Title: Re:Flare support script gives errors
Post by: Triggerhappy on 09 Jan 2006, 05:24:21
Code: [Select]
_mindis = 999999
_i = (count _aleaders)
#loop
_i = _i - 1
_m = _aleaders select _i
?(_m distance player) < _mindis:_mindis = (_m distance player);_closest = _m
?_i > 0:goto "loop"

i thought it would work in a foreach, but i guess not
this will find it (just tested the code) its the same thing as the foreach, just in a loop
Title: Re:Flare support script gives errors
Post by: Fragorl on 09 Jan 2006, 07:39:36
i thought it would work in a foreach, but i guess not
this will find it (just tested the code) its the same thing as the foreach, just in a loop
Code: [Select]
_minDist = -1;
_closest = objNull;
{
    _distance = _x distance player;
    if ((_distance < _minDist) || (_minDist < 0)) then {
        _minDist = _distance;
        _closest = _x;
    };
} foreach _aleaders;
If this is for use in a script then collapse the contents of the foreach to one single line.

A value of _closest = null results if _aleaders was empty.
Title: Re:Flare support script gives errors
Post by: Triggerhappy on 09 Jan 2006, 22:35:57
if _mindist is -1 then nobody will ever be found because they have to be a closer distance than _mindist

but looking at your code, it seems as though the only thing you're doing different is defining _closest as a null obj before assigning it to the person in a loop, correct? if so, is that a bug in the foreach command? (normally you can define variable without initializing them (i.e. _unit = _this as opposed to _unit = objnull;_unit = _this) )
Title: Re:Flare support script gives errors
Post by: penguinman on 14 Jan 2006, 02:34:45
ok, so, what would I need to do to make it work.
Title: Re:Flare support script gives errors
Post by: Triggerhappy on 14 Jan 2006, 03:35:53
my respone should work (post 9)
knowing frag his will probably work too but he hasn't answered about my questions so use mine for now
Title: Re:Flare support script gives errors
Post by: penguinman on 21 Jan 2006, 02:04:39
Get another error.

Code: [Select]
_m = _aleaders select _i

it says, error, zero divisor
Title: Re:Flare support script gives errors
Post by: Triggerhappy on 21 Jan 2006, 02:48:27
you can actually do this in a foreach i found out.
Code: [Select]
_mindis = 999999
_closest = objnull
"?_x distance player < _mindis:_mindis = _x distance player;_closest = _x" foreach _aleaders

not sure why the other thing didn't work unless _aleaders was undefined....
Title: Re:Flare support script gives errors
Post by: penguinman on 21 Jan 2006, 04:36:07
Code: [Select]
"#:?_x distance player < _mindis:_mindis = _x distance player;_closest = _x" foreach _aleaders
error, invalid number in expression

note position of #: