Salty Bear 2 Posted July 19, 2017 So, I am trying to randomize the location of a hostage (named hostage) and a map marker. Here's one possibility: hostage setPosASL [7214.22,2217.43,6.52]; hostage setDir 260; "hostageLocationMarker" setMarkerPos [7214.22,2217.43]; "hostageLocationMarker" setMarkerAlpha 1; Here's another: hostage setPosASL [6905.65,2487.33,10.5]; hostage setDir 319; "hostageLocationMarker" setMarkerPos [6905.646,2487.333]; "hostageLocationMarker" setMarkerAlpha 1; I have a total of eleven of those. What I want to do is have the game randomly pick one and run it. I thought of trying to assign each possibility a variable, like this: _hostageSpawn = [hostage setPosASL [7214.22,2217.43,6.52]; hostage setDir 260; "hostageLocationMarker" setMarkerPos [7214.22,2217.43]; "hostageLocationMarker" setMarkerAlpha 1;]; and _hostageSpawn_1 = [hostage setPosASL [6905.65,2487.33,10.5]; hostage setDir 319; "hostageLocationMarker" setMarkerPos [6905.646,2487.333]; "hostageLocationMarker" setMarkerAlpha 1;]: but that doesn't work. I tried using {/*code*/} instead of [/*code*/], but to no avail. I think I even tried using ["/*code*/"]. I thought that if I could figure out how to do that, then I could call them with selectRandom like this: selectRandom [_hostageSpawn,_hostageSpawn_1]; But I'm not even sure that's the way to do it. Can anyone please help me? Thanks in advance. Share this post Link to post Share on other sites
pierremgi 4900 Posted July 19, 2017 _posHostageArray = [[[7214.22,2217.43,6.52], 260],[[6905.65,2487.33,10.5],319],.....]; _posHostage = selectRandom _posHostageArray; hostage setPos (_posHostage select 0); hostage setDir (_posHostage select 1); "hostageLocationMarker" setMarkerPos (_posHostage select 0); .... Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 19, 2017 (edited) (selectRandom [ [[7214.22,2217.43,6.52], 260, [7214.22,2217.43]], [[6905.65,2487.33,10.5], 319, [6905.646,2487.333]], [[7214.22,2217.43,6.52], 260, [7214.22,2217.43]], [[6905.65,2487.33,10.5], 319, [6905.646,2487.333]] ]) params ["_hpos", "_hdir", "_mpos"]; hostage setPosASL _hpos; hostage setDir _hdir; "hostageLocationMarker" setMarkerPos _mpos; "hostageLocationMarker" setMarkerAlpha 1; or as pierremgi stated, 2 elements should be enough if marker pos is always the same as hostage pos: (selectRandom [ [[7214.22,2217.43,6.52], 260], [[6905.65,2487.33,10.5], 319], [[7214.22,2217.43,6.52], 260], [[6905.65,2487.33,10.5], 319] ]) params ["_hpos", "_hdir"]; hostage setPosASL _hpos; hostage setDir _hdir; "hostageLocationMarker" setMarkerPos _hpos; "hostageLocationMarker" setMarkerAlpha 1; Edited July 19, 2017 by sarogahtyp Share this post Link to post Share on other sites
Nikander 123 Posted July 19, 2017 3 hours ago, Salty Bear said: So, I am trying to randomize the location of a hostage (named hostage) and a map marker. So, did you know that one possibility to Setting Random Start is by connecting entity to map markers in the Eden editor Share this post Link to post Share on other sites
Salty Bear 2 Posted July 19, 2017 Thank you all so much for your feedback! I will try your suggestions as soon as I get the chance, and let you know how it works. I'm tempted to try sarogahtyp's suggestion first, because it's easier to wrap my brain around the params function. Although I can see that pierremgi's script does the same thing, all that select business - even though I understand how it's supposed to work - is just voodoo to me. I'm not familiar with params, but it looks like params is kind of a shortcut for the select function in this case. Quote or as pierremgi stated, 2 elements should be enough if marker pos is always the same as hostage pos: This is surprising to me, because I thought that setMarkerPos required [x,y] coordinates, while setPosASL required [x,y,z]. Nothing will explode if I feed setMarkerPos [x,y,z]? Quote So, did you know that one possibility to Setting Random Start is by connecting entity to map markers in the Eden editor Yes, I know. That's what I always used to do, but I want the hostage to move to his location later in the scenario, because I want the player to have to listen in on a conversation the bad guys are having about the hostage's location before the player can go looking for the hostage, and I don't want the player to accidentally find the hostage before doing that. So when the scenario starts I'm placing the hostage someplace far, far away on the map, then trying to setPosASL him to one of several positions after activating a trigger. Also, I'm fascinated by scripting, and want to learn how to do things without the editor. Share this post Link to post Share on other sites
Salty Bear 2 Posted July 19, 2017 Haven't tried your suggestions yet, but I just came across this: http://www.armaholic.com/forums.php?m=posts&q=11845 What if I did the following: switch (random floor(2)) do { case 0: { hostage setPosASL [7214.22,2217.43,6.52]; hostage setDir 260; "hostageLocationMarker" setMarkerPos [7214.22,2217.43]; "hostageLocationMarker" setMarkerAlpha 1; }; case 1: { hostage setPosASL [6905.65,2487.33,10.5]; hostage setDir 319; "hostageLocationMarker" setMarkerPos [6905.646,2487.333]; "hostageLocationMarker" setMarkerAlpha 1; }; }; Share this post Link to post Share on other sites
pierremgi 4900 Posted July 19, 2017 At least, floor random 2 has more chance to trigger something than random floor 2 And yes you can setMarkerPos [x,y,z] without any problem. Share this post Link to post Share on other sites
engima 328 Posted July 20, 2017 For redesign possibilities and readability I would do like this: 1. Put markers on possible start positions. 2. Select a random one using this code: _startMarker = selectRandom ["marker1", "marker2", "marker3"]; 3. Use the selected marker: _startPos = getMarkerPos _startMarker; ... Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 20, 2017 Also for ease of use if you have plenty of markers and don't want to type them all out manually you could do something like this: Have the markers named in a special way, like "SB_hostagemarker1", "SB_hostagemarker2" etc. Then to grab all of your hostagemarkers from the map simply do this: _hostagemarkers = allmapmarkers select {_x find "SB_hostagemarker" >= 0}; Now _hostagemarkers contains all matching markers. Pretty handy if you place a few more markers so you don't have to type as much. Cheers 1 Share this post Link to post Share on other sites