OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started 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.
;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
-
Change
_x = _closest
by
_closest = _x
-
i still get an error
_flare="Flare"camcreate [getpos _closest select 0, getpos _closest select 2, (getpos _closest select 2)+10]|#| error type any expected number
-
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
-
oh, your right! thank il see if that fixes it.
-
The typo should not return that error message. The mistake comes from that line :
"?_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]
-
so what would I do to fix it.
that part detects what group leader is closest to the player.
-
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
-
I dont understand this. how do you work it
-
_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
-
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
_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.
-
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) )
-
ok, so, what would I need to do to make it work.
-
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
-
Get another error.
_m = _aleaders select _i
it says, error, zero divisor
-
you can actually do this in a foreach i found out.
_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....
-
"#:?_x distance player < _mindis:_mindis = _x distance player;_closest = _x" foreach _aleaders
error, invalid number in expression
note position of #: