rainbow 0 Posted February 7, 2007 I want to place the object in one of three places, each time in other place (random). I searched everywhere but I didn't found. Can somebody help? Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 7, 2007 Write into init-line of your object: [this] exec "randompos.sqs" ..and save this textfile into your missionfolder: randompos.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _object = _this select 0; _allpos = [pos1,pos2,pos3]; _pos = _allpos select (random (count _allpos - 1)); _object setpos _pos; Replace pos1,pos2,pos3 with the coords of your choice Not tested  Share this post Link to post Share on other sites
rainbow 0 Posted February 7, 2007 How can i check coords ?? Share this post Link to post Share on other sites
moricky 211 Posted February 7, 2007 If you need the object placed randomly right after mission start and not during mission, just link it with some markers (to group; F2) and it will be placed on one of them (or it will remain on default pos). Share this post Link to post Share on other sites
Lolsav 0 Posted February 7, 2007 In the editor using triggers: - Needs a gamelogic named "Server" - object to be placed somewhere - 3 empty markers "Marker1", etc - all triggers have 0 as radius, activation type set to none. trigger 1 Condition: true AND local Server // To make sure the value it will be the same on all clients Activation: value = Random 3; Publicvariable "value"; trigger 2 Condition: value < 1 Activation: objectname setpos [(getmarkerpos "Marker1" select 0), (getmarkerpos "Marker1" select 1)]; For trigger 3 and 4 Condition for trig3: value >=1 AND value < 2 Condition for trig4: value > 2 On the activation field you just need to change the markername, eg. "Marker2", "Marker3" Theres a ton of stuff we can do with triggers Share this post Link to post Share on other sites
Guest Posted February 7, 2007 _allpos = [pos1,pos2,pos3]; if u just threw in 3 markers at the positions u wanted,then named them, then this could be: _allpos = [getMarkerPos "MarkerName1",getMarkerPos "MarkerName2",getMarkerPos "MarkerName3"]; If this was the desired approach anyhow Share this post Link to post Share on other sites
Big Dawg KS 6 Posted February 7, 2007 If you need the object placed randomly right after mission start and not during mission, just link it with some markers (to group; F2) and it will be placed on one of them (or it will remain on default pos). Unfortunately for Lolsav, this does the exact same thing as his triggers with less than half the work. Share this post Link to post Share on other sites
Lolsav 0 Posted February 7, 2007 M8 be, but wheres the fun if you dont do nothing? Share this post Link to post Share on other sites
december 0 Posted February 8, 2007 Quote (Gaia @ Feb. 07 2007,12:38) If you need the object placed randomly right after mission start and not during mission, just link it with some markers (to group; F2) and it will be placed on one of them (or it will remain on default pos). That is fine if you want to use an object but it won't work with a trigger @])rStrangelove Not working Share this post Link to post Share on other sites
Big Dawg KS 6 Posted February 8, 2007 )rStrangelove @ Feb. 07 2007,12:02)]_pos = _allpos select (random (count _allpos - 1)); Random doesn't return whole numbers, at least it's very very unlikely (practically; impossible, I don't think anyone has ever seen it), and array indexes are whole numbers. You can round decimals to whole numbers though: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pos = _allpos select (floor (random (count _allpos - 1))); Share this post Link to post Share on other sites
UNN 0 Posted February 8, 2007 Quote[/b] ]_pos = _allpos select (floor (random (count _allpos - 1))); While we are on the topic. According to the wiki: Quote[/b] ]Random real value from 0 (inclusive) to x (not inclusive). I take thats as saying: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Random 5 Will never return a value of 5? So you don't need to subtract one from the array count. Random combined with floor will to that automaticaly. In fact if you do, you will never select the last element in the array. Share this post Link to post Share on other sites
rainbow 0 Posted February 8, 2007 I thank everyone for help. I used this idea with pos1,pos2 as markers. By the way, I have another problem. When distance between P1 and P2 will be smaller than 3m then script will be started. Which script/commend should I use? Share this post Link to post Share on other sites
Lolsav 0 Posted February 8, 2007 Trigger set to activation none, 0 radius size. Condition: (P1 distance p2) < 3 Activation : [] exec "Scriptname.sqs" --> if its SQS or Activation: [] execVM "Scriptname.sqf" --> if its SQF Share this post Link to post Share on other sites
rainbow 0 Posted February 8, 2007 Damn, another problem. Random position for object (by using markers) doesn't work in Multiplayer. Is it possible to works in MP? EDIT: I tried Lolsav's idea and it works. Thx Share this post Link to post Share on other sites
Lolsav 0 Posted February 8, 2007 Well.. what can i say, my way it does, because triggers are only activated after mission started, even if that "after" is only 0.5 seconds, the default trigger checking time. I have currently 2 multiplayer missions that use the method i described and it does work. Share this post Link to post Share on other sites
sickboy 13 Posted February 8, 2007 What has been posted before should work: Method 1 (Gaia): Create 3 markers, then link them to the object by pressing F2 (groups) and then click and hold your mouse button on the unit and 'link' it to the marker, do that for all 3 markers... You can set the markers to Empty, to make them invisible.. Method 2 (StrangeLove & Special Ed): Create 3 markers (and name them): marker1, marker2, marker3 (put them empty if you dont want them to show on the map) Put this in the init field of the object you wish to randomly place:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this] execVM "randompos.sqf"; Create a file named randompos.sqf and put this in:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_object","_allpos"]; _object = _this select 0; _allpos = [getMarkerPos "marker1",getMarkerPos "marker2",getMarkerPos "marker3"]; _object setpos (_allpos select (random (count _allpos - 1)));You dont have to round the numbers because the select will handle the round when its not a whole number... Both methods should work in MP and SP. Or if you want to use the script on many objects and many different markers/locations: Create and name as many markers as you need. Put this in the init field of the objects you wish to randomly place:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this,["marker1","marker2","marker3"]] execVM "randompos.sqf"; Create a file named randompos.sqf and put this in:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_object","_allpos","_mark"]; _object = _this select 0; _allpos=[]; {_allpos=_allpos+[getMarkerPos _x];} forEach (_this select 1); _object setpos (_allpos select (random (count _allpos - 1)));use the marker names of the markers you created of coarse Share this post Link to post Share on other sites
Lolsav 0 Posted February 8, 2007 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">[this,["marker1","marker2","marker3"]] execVM "randompos.sqf"; Remember sqf is picky, it needs something else: null = [this,["marker1","marker2","marker3"]] execVM "randompos.sqf"; All sqf scripts need to be alike, ie, null = [] execVM "script.sqf"; Share this post Link to post Share on other sites
Big Dawg KS 6 Posted February 8, 2007 Quote[/b] ]_pos = _allpos select (floor (random (count _allpos - 1))); While we are on the topic. According to the wiki: Quote[/b] ]Random real value from 0 (inclusive) to x (not inclusive). I take thats as saying: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Random 5 Will never return a value of 5? So you don't need to subtract one from the array count. Random combined with floor will to that automaticaly. In fact if you do, you will never select the last element in the array. Yes I realized that shortly afterwards but never got a chance to edit my post, you can do it both ways though: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pos = _allpos select (floor (random (count _allpos))); <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_pos = _allpos select (round (random (count _allpos - 1))); That is, if round rounds both ways (ex. 4.9 becoming 5), the wiki doesn't make this clear. Share this post Link to post Share on other sites
sickboy 13 Posted February 8, 2007 All sqf scripts need to be alike, ie,null = [] execVM "script.sqf"; That might be true for within triggers and other ingame object fields, but not for inside scripts Share this post Link to post Share on other sites
-)rStrangelove 0 Posted February 12, 2007 Hehe, nice discussion (for such a small feature). If i put a name into the name line of an object, can i get the name 'back' in a script, like _name = name _this ? If that's possible then missiondesignerwise i'd say it would be cool to have a sqs/sqf that works like this: - Name an object in the editor (example: soldier1) - Put the sqs/sqf into its init-line (this exec *sqs/sqf) - make an empty marker with the name "rndpos_soldier1" - copy it as many times as you want random positions for the object (resulting markers named "rndpos_soldier1_1", "rndpos_soldier1_2", "rndpos_soldier1_xxx", etc etc etc - make the script like: a.) get name of object b.) loop: make templatestring via _marker = format["rndpos_%1_%2",<name>,<loopcounter>] c.) see if a marker of that name exists via ?((getmarkerpos _marker) select 0 == 0): d.) put all found markers into the _allpos array (+ the 1st marker) e.) select 1 randomly & setpos object there Hope you guys catch my drift  Basically you'd see how many positions you have for an object in the editor. Share this post Link to post Share on other sites