JeyR 2 Posted October 15, 2017 Hello. I am using this script to get all the cities into an array, then make a marker on them. 95% of the time it works, and then rarely it just creates a marker at [0,0,0] and then the script is just useless. Help, please. tasknumber = ["task1","task2","task3", etc ... ]; publicVariable "tasknumber"; publicVariable "current_tasknumber"; publicVariable "current_task"; cities = nearestLocations [getPosATL officer_jeff, ["NameCity"], 25000]; publicVariable "cities"; _city = cities call BIS_fnc_selectRandom; _citypos = locationPosition _city; _citymarker = createMarker ["citymarker", _citypos]; current_taskmarker = _citymarker; current_tasknumber = tasknumber call BIS_fnc_selectRandom; [west,[current_tasknumber],["Clear out the area","Clear out",current_task],[0,0,0],true,2,true,"attack",true] call BIS_fnc_taskCreate; [current_tasknumber,current_task]call BIS_fnc_taskSetDestination; [current_tasknumber]call BIS_fnc_taskSetCurrent; ....spawn enemies etc ... Share this post Link to post Share on other sites
Belbo 462 Posted October 15, 2017 1st off: _city = selectRandom cities; //however, I don't see a reason for cities to be a global variable that's being made public, at least not in this snippet. 2nd off: Try it with a safety catch: _cityPos = locationPosition _city; _cityPos = if (_cityPos isEqualTo [0,0,0]) then { _locationPosition (cities select 0) //or any other location position } else { _cityPos }; That way you can revert to a failsafe location (that you can even manually select) if the position is [0,0,0]. But maybe you should try to find out why it sometimes returns a position of [0,0,0]. Maybe there are some entries created with nearestLocations that are not suitable or just in the wrong format. I would try to find that out first. The array format of nearestLocations is a bit curious, for example: nearestLocations [getPosATL player, ["NameCity"], 3000] = [Location NameCity at 16207, 17297,Location NameCity at 14480, 17614,Location NameCity at 18049, 15264] Maybe your array has some entries that don't make sense. Share this post Link to post Share on other sites
Muzzleflash 111 Posted October 15, 2017 When you create a marker it is recommend to always set is shape, using setMarkerShape, and if "ICON" then also setMarkerType. Using only createMarker and no other commands to configure it, means it stays invisible. But as far as I can tell, your task destination would always be [0,0,0]. When you create the task, you specify [0,0,0] as the destination. Then you set it to "current_task", but where is that defined? Also, something to beware of, there can only be one marker with the same name at any given time. So remember to delete the old marker when you change tasks. Share this post Link to post Share on other sites
JeyR 2 Posted October 15, 2017 I want it to be invisible because the bis_fnc_taskcreate creates a neat icon on top, that's all I need, nothing else. The marker is just for the function to find it. And to answer your other questions, as I said, it works 95% of the time, and then it's never at [0,0,0]. Here:https://community.bistudio.com/wiki/BIS_fnc_taskCreate In the parameters and in the example it also says [0,0,0] but it's not there. Also. it's my bad, I renamed "current_task" to "current_taskmarker" for the forums to be more understandable. I'm changing it back now. Share this post Link to post Share on other sites
Muzzleflash 111 Posted October 15, 2017 How many times do that script run? Only once or multiple times? If it runs multiple times, does it ever fail on the very first run? Share this post Link to post Share on other sites
JeyR 2 Posted October 15, 2017 It runs multiple times. And I don't think it ever fails on the first nor the second. But it could also just be my luck. Share this post Link to post Share on other sites
Muzzleflash 111 Posted October 15, 2017 Do you delete the marker before the script runs again? If you don't then the createMarker call will fail, and any attempt to get the position of _citymarker/current_taskmarker/current_task will yield [0,0,0] . Share this post Link to post Share on other sites
JeyR 2 Posted October 15, 2017 That is very interesting, I'll check. Share this post Link to post Share on other sites
JeyR 2 Posted October 15, 2017 Nope. I run it 3 times over and it was working. I managed to run it 8 times and the 9th bugged out. Share this post Link to post Share on other sites
R3vo 2654 Posted October 16, 2017 17 hours ago, JeyR said: Nope. I run it 3 times over and it was working. I managed to run it 8 times and the 9th bugged out. The reason for this is simple. taskNumber has to always be unique. So instead of predefining them in an array. Count them upwards. Also, do not use publicVariable too often, it can kill server performance. In the following script it only use private variables or missionNamespace variables. The BIS_fnc_setTask function takes care of making the task with all its properties global. if (isServer) then { private _cities = nearestLocations [getposWorld player, ["NameCity"], 25000]; private _city = selectRandom _cities; private _citypos = locationPosition _city; private _citymarker = createMarker ["citymarker", _citypos]; //Count task number up, so it's always unique private _tasknumber = (missionNamespace getVariable ["TaskNumber",-1]) + 1; missionNamespace setVariable ["TaskNumber",_tasknumber]; private _taskNumberFinal = format ["TaskNumberFinal_%1",_tasknumber]; //Using setTask instead of create task. It's newer and covers every property of a task private _id = [_taskNumberFinal ,true,["Clear out the area","Clear out",_citymarker],getMarkerPos _citymarker,"ASSIGNED",10,true,true,"attack",true] call BIS_fnc_setTask; //Debug (Can be removed later) systemChat format ["Task %1 was created",_id]; //Remove the marker deleteMarker _citymarker; }; 1 Share this post Link to post Share on other sites
JeyR 2 Posted November 2, 2017 Okay, that's cool. I just changed those that you wrote @R3vo. It still happens.Steam Image <-- code: [_taskNumberFinal ,west,["We have intel on an OPFOR base located in the marked area. You need to eliminate them","Eliminate",_citymarker],getMarkerPos _citymarker,"ASSIGNED",10,true,true,"attack",true] call BIS_fnc_setTask; First I thought It fixed everything, I was so happy, now like 2 weeks later, it happened again. It's true that your solution almost deletes this problem, but it still happened again. Share this post Link to post Share on other sites
R3vo 2654 Posted November 2, 2017 36 minutes ago, JeyR said: Okay, that's cool. I just changed those that you wrote @R3vo. It still happens.Steam Image <-- code: [_taskNumberFinal ,west,["We have intel on an OPFOR base located in the marked area. You need to eliminate them","Eliminate",_citymarker],getMarkerPos _citymarker,"ASSIGNED",10,true,true,"attack",true] call BIS_fnc_setTask; First I thought It fixed everything, I was so happy, now like 2 weeks later, it happened again. It's true that your solution almost deletes this problem, but it still happened again. That's strange. I tested it with the following code and 125 tasks were properly created. None was placed at 000 private _cities = nearestLocations [getposWorld player, ["NameCity"], 50000]; private _city = selectRandom _cities; { //private _citymarker = createMarker ["citymarker", _citypos]; private _citypos = locationPosition _x; //Count task number up, so it's always unique private _tasknumber = (missionNamespace getVariable ["TaskNumber",-1]) + 1; missionNamespace setVariable ["TaskNumber",_tasknumber]; private _taskNumberFinal = format ["TaskNumberFinal_%1",_tasknumber]; //Using setTask instead of create task. It's newer and covers every property of a task private _id = [_taskNumberFinal ,true,["Clear out the area","Clear out",""/*_citymarker*/],_cityPos/*getMarkerPos _citymarker*/,"ASSIGNED",10,true,true,"attack",true] call BIS_fnc_setTask; //Debug (Can be removed later) systemChat format ["Task %1 was created",_id]; //Remove the marker //deleteMarker _citymarker; } forEach _cities; Share this post Link to post Share on other sites
JeyR 2 Posted November 2, 2017 Exactly. for 2 weeks nothing happened. Now out of nowhere, here it is. Share this post Link to post Share on other sites
soolie 189 Posted November 2, 2017 Offtopic from your question but I'm also using locations to create "missions". I was doing it the same way as you but recently changed it and it seems to run better now, here is how I get them. _availLocTypes = ["NameCity","NameCityCapital"]; _locations = "(getText (_x>> 'type') in _availLocTypes)" configClasses (configFile >> "CfgWorlds" >> worldName >> "Names"); Share this post Link to post Share on other sites