Jump to content
Sign in to follow this  
fildred13

Why isn't this script working? (setPos to one of several markers randomly)

Recommended Posts

I am learning the arma scripting language and I am trying my hand at setting the position of a unit to any one of several random markers.

So, on a unit I have the following initialization:

rpos = compile loadFile "fil_scripts\randomMarkerPos.sqf";

pos = ["pow_pos_1","pow_pos_2","pow_pos_3","pow_pos_4"] call rpos;

this setPos pos;

The idea being that I load up an external script which I feed 4 arguments to: pow_pos_1, pow_pos_2, etc. Those "pow_pos_1" and all the others are invisible markers on the map. Finally, I call setPos on the unit itself, targetting the randomly selected positon.

randomMarkerPos.sqf, meanwhile, processes the array and returns the position of one of those markers at random, like so:

//grab one of the markers at random
_random = _this select floor random count _this;

//grab the position of the marker
_random_pos = getMarkerPosition _random;

//return the position value
_random_pos

When I run the mission, it seems that the whole thing fails silently somewhere. The unit is standing where I placed him on the map, instead of at one of the four random positions.

I'm sure I done goofed, but I don't know where. can anyone nudge me in the right direction?

Share this post


Link to post
Share on other sites

you do not use setPos you use setMarkerPos

You'll usually find that the markers have their own commands for positioning and such.

actually I think you need to use getMarkerPos

this setPos getMarkerPos pos;

Share this post


Link to post
Share on other sites

I didnt necessarily read entire thing but I'm not sure you can setpos from a marker to a marker?

At least thats not what I've heard, I'm likely 70% wrong.

But, if you want to try it, use an invisible helipad instead of invisible markers.

:S

Share this post


Link to post
Share on other sites
actually I think you need to use getMarkerPos

Sorry if I'm misunderstanding, but I don't THINK I'm setting the position of a marker anywhere. The setPos call is on a unit, not a marker. If we pretend that the unit I'm calling this on was a player for a moment, then another way I could call that line would be:

player setPos pos

Buh, I just called getMarkerPos wrong, you're right! I'm dumb, thanks for the proofreading of my code =P

Edited by fildred13

Share this post


Link to post
Share on other sites
I didnt necessarily read entire thing but I'm not sure you can setpos from a marker to a marker?

At least thats not what I've heard, I'm likely 70% wrong.

But, if you want to try it, use an invisible helipad instead of invisible markers.

:S

Your info is wrong and the solution is not script based and therefore useless to the author of the thread who is doing this in SQF and not the editor.

Not saying the info you posted about the invisible helipad is wrong but it just isn't a clean solution to the issue like SQF is

Share this post


Link to post
Share on other sites

I'm not sure if I fully understood what you were asking for, but the following code would at least set your unit's pos randomly to one of the marker positions.

[color="#FF8040"][color="#000000"]_pos[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"marker1"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker2"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker3"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker4"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]    [color="#1874CD"]_unit[/color] [color="#191970"][b]setPos[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]getMarkerPos[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_pos[/color] [color="#191970"][b]call[/b][/color] BIS_fnc_selectRandom[color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Is there a special reason your are precompiling that small script ? This would only make sense if you're calling it very often in a short period of time (so far I understand, correct me if I'm wrong)

Also, this line _random = _this select floor random count _this; will very rarely return the last array entry, since the random value has to be exactly 4.0000 or 3.9999999 I take this back. I tested it with a script and all 4 array entries get select nearly equally often. Thank Killzone_Kid

for the heads-up.

Edited by R3vo

Share this post


Link to post
Share on other sites
Your info is wrong and the solution is not script based and therefore useless to the author of the thread who is doing this in SQF and not the editor.

Not saying the info you posted about the invisible helipad is wrong but it just isn't a clean solution to the issue like SQF is

Sure, but I've literally had missions where people have used attachto marker and helipad. Which, was weird, but it worked :S

Share this post


Link to post
Share on other sites
I'm not sure if I fully understood what you were asking for, but the following code would at least set your unit's pos randomly to one of the marker positions.

[color="#FF8040"][color="#000000"]_pos[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#7A7A7A"]"marker1"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker2"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker3"[/color][color="#8B3E2F"][b],[/b][/color][color="#7A7A7A"]"marker4"[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]    [color="#1874CD"]_unit[/color] [color="#191970"][b]setPos[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#191970"][b]getMarkerPos[/b][/color] [color="#8B3E2F"][b]([/b][/color][color="#000000"]_pos[/color] [color="#191970"][b]call[/b][/color] BIS_fnc_selectRandom[color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b])[/b][/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

Is there a special reason your are precompiling that small script ? This would only make sense if you're calling it very often in a short period of time (so far I understand, correct me if I'm wrong)

Also, this line _random = _this select floor random count _this; will very rarely return the last array entry, since the random value has to be exactly 4.0000 or 3.9999999

Nope, this is just a much more succinct way to do this! I'll use it :) Thanks for the help!

Share this post


Link to post
Share on other sites

Also, this line _random = _this select floor random count _this; will very rarely return the last array entry, since the random value has to be exactly 4.0000 or 3.9999999

Incorrect. It will never return 4, and that is what needed 0, 1, 2 and 3. 4 will be out of range if it returned.

Share this post


Link to post
Share on other sites
Incorrect. It will never return 4, and that is what needed 0, 1, 2 and 3. 4 will be out of range if it returned.

Yeah that was a stupid mistake, but my idea should be correct anyway. It would then need to be 2.9999999 and 3 to select he last array entry. (Correct me, if that is also wrong)

Nevermind, seems I'm completely wrong.

Edited by R3vo

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×