Kolmain 6 Posted May 15, 2011 I created a script to chose a random building and create a target in the building (east man). If I set him to a random building pos, nothing happens, if I run crb_HousePos he dies and if I run the house patrol script on him nothing happens? This is one of the most bazare things I've seen in arma, but I just need this high-value target to be in a random room in the building so hes not standing on the roof? Im not worried about patroling, actually he can just hide in the room but I cant get him to be anywhere but the roof! Any ideas? Note: Im testing on Lingor, meaning there are some custom buildings, perhaps theyre not indexed? But it still does not work with A2/OA buildings either :( Share this post Link to post Share on other sites
twirly 11 Posted May 15, 2011 Something along these lines maybe... _house = position leader wsqd1 nearestObject "Building"; _posarray = []; _rndpos = []; _pos = []; _cnt = 0; while {format ["%1", _house buildingPos _cnt] != "[0,0,0]" } do { _pos = _house buildingPos _cnt; _posarray = _posarray + [_pos]; _cnt = _cnt + 1; sleep 0.01; }; _rndpos = _posarray select (floor (random (count (_posarray)))); targetdude setpos _rndpos; Share this post Link to post Share on other sites
Kolmain 6 Posted May 15, 2011 How can I create fnc_pick_housepos with that code so I can use fnc_pick_housepos later in the script to do that? Share this post Link to post Share on other sites
demonized 20 Posted May 15, 2011 // execute with _null = unitname call fnc_pick_housepos; // will place unitname in a random house position in nearest building to him at the point script is run. // remove last line "_this" and use spawn instead of no need for wait until completed. fnc_pick_housepos = { _house = getPos _this nearestObject "Building"; _posarray = []; _rndpos = []; _pos = []; _cnt = 0; while {format ["%1", _house buildingPos _cnt] != "[0,0,0]" } do { _pos = _house buildingPos _cnt; _posarray = _posarray + [_pos]; _cnt = _cnt + 1; sleep 0.01; }; _rndpos = _posarray select (floor (random (count (_posarray)))); _this setpos _rndpos; _this }; not checking any coommands, only changed unitname to refer to called from call or spawn command. This is how you set up a function, functions can be local or global (global, _local) Share this post Link to post Share on other sites
Kolmain 6 Posted May 15, 2011 the only thing I dont understand is A) Is this local or global? Global right? and B) why does it in end with _this? Share this post Link to post Share on other sites
demonized 20 Posted May 15, 2011 (edited) A: it is a local function, so if you run it from within a isServer check it will be local to server. Im still a little fuzzy on the whole locality issues, it seems kindof everything i "local" but the execution is determining the locality. Also there is local/global commands so that must be counted in as well. Edit: yeah its a global function, can be called from anywhere, inside or outside of script. functions can be local or global (global, _local) B: call requires a return value without ; at end, spawn does not, read more in link, useful to know that the function has completed its task. Edited May 15, 2011 by Demonized Share this post Link to post Share on other sites
Kolmain 6 Posted May 15, 2011 The link you gave me links to ArmA actions? :P And so how could true/false returns work? Share this post Link to post Share on other sites
demonized 20 Posted May 15, 2011 any returned variable works. Share this post Link to post Share on other sites
Kolmain 6 Posted May 15, 2011 This code still wont position him... fnc_pick_housepos = { [size=2][color=#808080][size=2][color=#808080]_house[/color][/size][/color][/size][size=2] = [/size][size=2][color=#ff0000][size=2][color=#ff0000]getPos[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]_this[/color][/size][/color][/size][size=2] [/size][size=2][color=#ff0000][size=2][color=#ff0000]nearestObject[/color][/size][/color][/size][size=2] "Building"; [/size][size=2][color=#808080][size=2][color=#808080]_posarray[/color][/size][/color][/size][size=2] = []; [/size][size=2][color=#808080][size=2][color=#808080]_rndpos[/color][/size][/color][/size][size=2] = []; [/size][size=2][color=#808080][size=2][color=#808080]_pos[/color][/size][/color][/size][size=2] = []; [/size][size=2][color=#808080][size=2][color=#808080]_cnt[/color][/size][/color][/size][size=2] = 0; [/size][size=2][color=#0000ff][size=2][color=#0000ff]while[/color][/size][/color][/size][size=2] {[/size][size=2][color=#ff0000][size=2][color=#ff0000]format[/color][/size][/color][/size][size=2] ["[/size][size=2][color=#0000ff][size=2][color=#0000ff]%[/color][/size][/color][/size][size=2]1", [/size][size=2][color=#808080][size=2][color=#808080]_house[/color][/size][/color][/size][size=2] [/size][size=2][color=#ff0000][size=2][color=#ff0000]buildingPos[/color][/size][/color][/size][size=2] [/size][size=2][color=#808080][size=2][color=#808080]_cnt[/color][/size][/color][/size][size=2]] [/size][size=2][color=#0000ff][size=2][color=#0000ff]![/color][/size][/color][/size][size=2]= "[0,0,0]" } [/size][size=2][color=#0000ff][size=2][color=#0000ff]do[/color][/size][/color][/size][size=2] { [/size][size=2][color=#808080][size=2][color=#808080]_pos[/color][/size][/color][/size][size=2] = [/size][size=2][color=#808080][size=2][color=#808080]_house[/color][/size][/color][/size][size=2] [/size][size=2][color=#ff0000][size=2][color=#ff0000]buildingPos[/color][/size][/color][/size][size=2] [/size][size=2][color=#808080][size=2][color=#808080]_cnt[/color][/size][/color][/size][size=2]; [/size][size=2][color=#808080][size=2][color=#808080]_posarray[/color][/size][/color][/size][size=2] = [/size][size=2][color=#808080][size=2][color=#808080]_posarray[/color][/size][/color][/size][size=2] + [[/size][size=2][color=#808080][size=2][color=#808080]_pos[/color][/size][/color][/size][size=2]]; [/size][size=2][color=#808080][size=2][color=#808080]_cnt[/color][/size][/color][/size][size=2] = [/size][size=2][color=#808080][size=2][color=#808080]_cnt[/color][/size][/color][/size][size=2] + 1; [/size][size=2][color=#ff0000][size=2][color=#ff0000]sleep[/color][/size][/color][/size][size=2] 0.01; }; [/size][size=2][color=#808080][size=2][color=#808080]_rndpos[/color][/size][/color][/size][size=2] = [/size][size=2][color=#808080][size=2][color=#808080]_posarray[/color][/size][/color][/size][size=2] [/size][size=2][color=#ff0000][size=2][color=#ff0000]select[/color][/size][/color][/size][size=2] ([/size][size=2][color=#ff0000][size=2][color=#ff0000]floor[/color][/size][/color][/size][size=2] ([/size][size=2][color=#ff0000][size=2][color=#ff0000]random[/color][/size][/color][/size][size=2] ([/size][size=2][color=#ff0000][size=2][color=#ff0000]count[/color][/size][/color][/size][size=2] ([/size][size=2][color=#808080][size=2][color=#808080]_posarray[/color][/size][/color][/size][size=2])))); [/size][size=2][color=#0000ff][size=2][color=#0000ff]_this[/color][/size][/color][/size][size=2] [/size][size=2][color=#ff0000][size=2][color=#ff0000]setpos[/color][/size][/color][/size][size=2] [/size][size=2][color=#808080][size=2][color=#808080]_rndpos[/color][/size][/color][/size][size=2]; [/size][size=2][color=#008000][size=2][color=#008000]//_this [/color][/size][/color][/size][size=2]}; [/size][size=2][color=#808080][size=2][color=#808080]_hvtposition[/color][/size][/color][/size][size=2][color=#000000] = mso_hvt_locations [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]call[/color][/size][/color][/size][size=2][color=#000000] BIS_fnc_selectRandom;[/color] [/size][size=2][color=#808080][size=2][color=#808080]_hvtclasses[/color][/size][/color][/size][size=2][color=#000000] = ["Ins_Commander","Ins_Lopotev","TK_Soldier_Officer_EP1","TK_INS_Warlord_EP1","TK_GUE_Warlord_EP1"];[/color] [/size][size=2][color=#808080][size=2][color=#808080]_hvtclass[/color][/size][/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#808080][size=2][color=#808080]_hvtclasses[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]call[/color][/size][/color][/size][size=2][color=#000000] BIS_fnc_selectRandom;[/color] [/size][size=2][color=#808080][size=2][color=#808080]_grp[/color][/size][/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]createGroup[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]EAST[/color][/size][/color][/size][size=2][color=#000000]; [/color] [/size][size=2][color=#808080][size=2][color=#808080]_hvt[/color][/size][/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#808080][size=2][color=#808080]_hvtclass[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]createUnit[/color][/size][/color][/size][size=2][color=#000000] [[/color][/size][size=2][color=#808080][size=2][color=#808080]_hvtposition[/color][/size][/color][/size][size=2][color=#000000], [/color][/size][size=2][color=#808080][size=2][color=#808080]_grp[/color][/size][/color][/size][size=2][color=#000000]];[/color] [/size][size=2][color=#808080][size=2][color=#808080]_hvt[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]allowDamage[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]false[/color][/size][/color][/size][size=2][color=#000000];[/color] [/size][size=2][color=#ff0000][size=2][color=#ff0000]sleep[/color][/size][/color][/size][size=2][color=#000000] 1;[/color] [/size][size=2][color=#808080][size=2][color=#808080]_null[/color][/size][/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#808080][size=2][color=#808080]_hvt[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]spawn[/color][/size][/color][/size][size=2][color=#000000] fnc_pick_housepos;[/color] [/size][size=2][color=#ff0000][size=2][color=#ff0000]sleep[/color][/size][/color][/size][size=2][color=#000000] 1;[/color] [/size][size=2][color=#808080][size=2][color=#808080]_hvt[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#ff0000][size=2][color=#ff0000]allowDamage[/color][/size][/color][/size][size=2][color=#000000] [/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]true[/color][/size][/color][/size][size=2][color=#000000];[/color][/size] [size=2][color=#000000] [/color] [/size] Share this post Link to post Share on other sites
demonized 20 Posted May 15, 2011 (edited) getPos_thisnearestObject :j: there is no command called that, or any of the other things in the above scirpt, you need to keep spaces, as they were. And you use call with no return value, for that use spawn instead, but then no pause or wait will be done. My eyes was crossed. No wonder it does not work... :j: Edited May 15, 2011 by Demonized Share this post Link to post Share on other sites
Kolmain 6 Posted May 15, 2011 No, the copy paste took out all of the spaces... odd, I found the problem, createUnit doesnt have a handler. Share this post Link to post Share on other sites
demonized 20 Posted May 15, 2011 use createUnit array instead. Share this post Link to post Share on other sites