Retardinator 1 Posted April 5, 2013 So basically, I'm trying to spawn a unit on a trigger's exact location, and it seems to work when I use the trigger's name directly (getPos Trigger1, for example). However, I need to be able to spawn a unit at its location regardless of name and when i use anything other than the trigger's exact name I can't get the right position (the unit spawns about 200-300m away from it). This is the trigger's init line: Location=Location+ [getPos this]; [] exec "Spawn.sqs"; Location is an empty array used for storing spawn triggers' positions. And this is the code used for spawning: Picked_Spawn = random (count Location); Picked_Spawn = Picked_Spawn - (Picked_Spawn mod 1); "Civilian1" CreateUnit [Location select Picked_Spawn, group Civilian1]; Note that everything works when referencing the trigger by name, but breaks down when using anything else (getPos this and other variations). My guess is that the problem is in the trigger's init line, where "this" doesn't work as it's supposed to, and instead of returning the position of the trigger, returns something else entirely (although they are valid [x,y,z] coordinates, they're way off the original position). Any help with this is much appreciated. Share this post Link to post Share on other sites
ProfTournesol 956 Posted April 5, 2013 Replace this by thisTrigger. Share this post Link to post Share on other sites
Retardinator 1 Posted April 5, 2013 Doesn't seem to work. Either returns 'scalar bool array' thing when I just use thisTrigger, or 'array' for getPos/position thisTrigger when I try to output to a hint directly from the init line. Share this post Link to post Share on other sites
nikiller 18 Posted April 5, 2013 hi, You should use a marker or a game logic as spawn location instead of a trigger. I'm not sure to understand what you want to do. Are you trying to make a random spawn location for your civilian? cya. Nikiller. Share this post Link to post Share on other sites
Retardinator 1 Posted April 6, 2013 Pretty much. It's supposed to be a lot of triggers for random spawns and I've done something similar before by combining triggers and markers, so I'm trying to find a more "universal" way to do it with only one thing placed on the map. Since that doesn't seem to work I guess I'll have to do it the old fashioned way ;) It could also save me a lot of headaches later when saving just one entity into an array, instead of arrays of arrays of stuff so I can keep track of both markers and triggers. Share this post Link to post Share on other sites
ProfTournesol 956 Posted April 6, 2013 (edited) Doesn't seem to work. Either returns 'scalar bool array' thing when I just use thisTrigger, or 'array' for getPos/position thisTrigger when I try to output to a hint directly from the init line. Exact, i just tested it and getpos thistrigger returns "array" (???) while it returns the trigger position as expected in Arma2. I should have tested it before. Edited April 6, 2013 by ProfTournesol Share this post Link to post Share on other sites
nikiller 18 Posted April 6, 2013 (edited) hi, I think the easiest way to do what you want is to group markers and one game logic (light blue line). The game logic will begin the mission at any one of the markers it is grouped with or at it's original position, chosen at random. Then you just have to use the game logic as spawn position. Don't forget to use empty marker type if you don't want markers drawn on the mission map. init.sqs ;******************************* ;Init Script by Nikiller v0.9b ;contact: nikillerofp@hotmail.fr ;******************************* nik_host=local server [CivilianGrp1,Spawn_gl1,"Civilian"] exec "spawn.sqs" exit spawn.sqs ;**************************************************************** ;Simple Spawn Script by Nikiller v0.9b ;Spawn one unit at given position ;Note: put a game logic named server on the map ;contact: nikillerofp@hotmail.fr ;**************************************************************** if nik_host then {} else {goto "ende"} _grp = _this select 0 _gl = _this select 1 _type = _this select 2 _pos=getPos _gl _type CreateUnit [_pos,_grp] #ende exit Here's a demo to show how it works: DEMO LINK cya. Nikiller. Edited April 6, 2013 by Nikiller Share this post Link to post Share on other sites
Retardinator 1 Posted April 7, 2013 Technical question: Can you add or remove markers to/from the gamelogic's group via scripts (while the mission is already running, and I'm talking about pre-placed markers on the map, not newly created ones)? Share this post Link to post Share on other sites
nikiller 18 Posted April 8, 2013 (edited) hi, Technical question: Can you add or remove markers to/from the gamelogic's group via scripts (while the mission is already running, and I'm talking about pre-placed markers on the map, not newly created ones)? That's a very good question. I never tried to group markers and game logics on the fly, I don't know if it works. I guess the random game logic position shouldn't work after the mission start but you can give it a try. There's others solutions without game logic or markers. One of them is to use an array of objects IDs and use a random function to choose the spawning position. To check object ID's in the Mission Editor click on "Show IDs" and zoom in close. init.sqs ;******************************* ;Init Script by Nikiller v0.9b ;contact: nikillerofp@hotmail.fr ;******************************* nik_host=local server [CivilianGrp1,"Civilian",{nik_Civilian1=this},1,"SOLDIER"] exec "spawn_id.sqs" exit spawn_id.sqs ;********************************************** ;Spawn at ID Script by Nikiller v0.9b ;Spawn units at random ID ;Note: put a game logic named server on the map ;contact: nikillerofp@hotmail.fr ;********************************************** if nik_host then {} else {goto "ende"} _grp = _this select 0 _type = _this select 1 _init = _this select 2 _skil = _this select 3 _rank = _this select 4 _id="random_id.sqf" _pos=call loadFile _id _c=count _pos _r=random _c _r=_r-_r mod 1 _h=_pos select _r _o=object _h _g=getPos _o _type createUnit [_g,_grp,_init,_skil,_rank] #ende exit random_id.sqf [ 16752, 42990, 99426, 46846, 110367, 160249, 158405, 166021, 165171, 168921 ] Here's a demo to show how it wroks: DEMO LINK cya. Nikiller. Edited April 8, 2013 by Nikiller Share this post Link to post Share on other sites
Retardinator 1 Posted April 9, 2013 That's awesome. I'll try grouping markers during runtime, but if that doesn't work this'll definitely help. Thanks a lot. For some clarification - I'm trying to build a spawn system that checks if the player is within a certain range (distance) of a spawnpoint and if he is that spawn becomes 'viable' for spawning units and is added to an array. The script then uses some sort of algorithm (still working on it) to spawn units at random 'viable' spawns (but not in a completely random way, hence algorithm). If the player gets too far from the spawnpoint, it is removed from the array. This is so I can spawn lots of units that are relevant (close) to the player and both remove the units and disable the spawns when the player gets too far. This is so you don't have units spawning 2 islands away and wasting resources, while also giving the illusion of high population. Either way, this was very helpful. Share this post Link to post Share on other sites