Jem777 5 Posted July 28, 2019 Hi All This is first post here, first off, im new to Arma 3. Ive been playing around with the editor and it just blows me away with how much content is available. Im sure it would take years to learn how to use it to its full potential. Im been playing around trying to create a Sniper vs Sniper Senario. Ive added one Blufor player and one Opfor AI, i added a Spawn AI module. I then synced the module to the Opfor AI. The idea that I have is that when the Opfor AI is killed, one Opfor AI will spawn. What is happening is that the AI spawns but so does a few Blufor AI which is not what i need. What is the best way to do this? Also when the AI spawns, i would like it to be at a random location within X meters from where he was killed. any advice would be appreciated. Thanks 1 Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted July 28, 2019 1 hour ago, Jem777 said: Hi All This is first post here, first off, im new to Arma 3. Ive been playing around with the editor and it just blows me away with how much content is available. Im sure it would take years to learn how to use it to its full potential. Im been playing around trying to create a Sniper vs Sniper Senario. Ive added one Blufor player and one Opfor AI, i added a Spawn AI module. I then synced the module to the Opfor AI. The idea that I have is that when the Opfor AI is killed, one Opfor AI will spawn. What is happening is that the AI spawns but so does a few Blufor AI which is not what i need. What is the best way to do this? Also when the AI spawns, i would like it to be at a random location within X meters from where he was killed. any advice would be appreciated. Thanks Could be something like this: //init.sqf TAG_fnc_respawnAIEnabled = true;//set this to false any time mid mission and the respawn will be stopped TAG_fnc_respawnAI = { params ["_unit"]; _unit addEventHandler ["Killed",{ params ["_unit"]; if (!TAG_fnc_respawnAIEnabled) exitWith {false}; _newUnit = (creategroup side group _unit) createUnit [typeof _unit, (_unit getPos [15 + random 35,random 360]), [], 0, "NONE"]; _respawn = [_newUnit] call TAG_fnc_respawnAI; true }]; }; //add to multiple units or only one, as needed { _respawn = [_x] call TAG_fnc_respawnAI } forEach [YourAI1,YourAI2,YourAI3]; Will respawn the unit within at least 15m and most 50 in a random direction from the killed unit. Cheers 2 Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 28, 2019 @Jem777 Welcome to Bis forums! In the future as a reference for anything AI related check out my AI Compilation list which is pinned in this section of the forum, see the thread here: https://forums.bohemia.net/forums/topic/165560-ai-compilation-list-of-addonsmodsscripts-threads-for-arma3/ 3 Share this post Link to post Share on other sites
Jem777 5 Posted July 28, 2019 Thanks for the link i had a quick look and saw a topic on respawning. with the code above, how do i use that but more importantly, how do i find out about the functions and key words used in the script? thanks for both of your input. 1 Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 28, 2019 6 hours ago, Jem777 said: with the code above, how do i use that but more importantly, how do i find out about the functions and key words used in the script? How to use is: 1. You need a mission to put the script in, so locate your mission's folder via here ---> C:\Users\username\Documents\Arma 3\missions 2. Create a notepad doc and name it init.sqf 3. Take the code, and copy n paste it into the script, save and move it to the inside of your mission's folder where the mission.sqm is. Note: sometimes code from the forum here has a different format or coding structure vs the game, hard to explain, so if its not to much for you, actually type the code into the script itself. 4. At the bottom of the script you see this code: } forEach [YourAI1,YourAI2,YourAI3]; in the brackets you have yourai,yourai2,Yourai3 You want to change those names with your own, and name the ai you want to spawn, so for example if the ai is A1 then in the Ai's variable name box in the editor name him A1 and same for the others, that is A2, A3, etc,. or more A4 ect, can be any name you want, just make sure that the name you give the AI is the same in the init.sqf As for functions -----> https://community.bistudio.com/wiki/Category:Arma_3:_Functions 2 1 Share this post Link to post Share on other sites
wogz187 1086 Posted July 28, 2019 @Jem777,@Gunter Severloh Quote Note: sometimes code from the forum here has a different format or coding structure vs the game, hard to explain, so if its not to much for you, actually type the code into the script itself. Here are two specific and common things to watch out for when copying code from online sources, 1) The code you copied isn't compatible with your game version 2) When saving your new script file you get a warning about "Special Characters". This usually means the original code was written in a coding program and contains a macro that notepad doesn't recognize. If you choose to save anyway, watch out for extra characters in the resulting file. For example, if (!TAG_fnc_respawnAIEnabled) exitWith {false}; May become, if (!TAG_fnc_respawnAIEnabled) exitWith {false};? Is that about right, Gunter? 3 Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 28, 2019 55 minutes ago, wogz187 said: Is that about right, Gunter? Yup! I learned this the hard way when working on code and projects with @Rydygier as he had pointed that out to me, we/i discovered that when copying and pasting code from the forum it does change how the game responds to it if you will, so i been learning to type the code out. Whats funny and frustrating too is when for a person who knows little about code or at all, and tries something that they know should work but doesn't, no matter what they try, then one must reflect on this point and advice of (copying) from the forum to script, and add that into the equation that, that may influence or be a cause for the code/script to not work as it should. Its a learning process. In Arma with its high learning curve, if you cannot take the time to find out whats wrong be it mods, code, scripts, ect,. then maybe this isn't the game you should be playing, this is legitimately a simulator, there isn't really a 1 button lets play aspect of the game even tho there is, the best aspects which the new folk dont see at the beginning is when you are building your own missions, and are relying on scripts and code to make the mission play or have functions you want, the cherry at the top of the cake is here and not so much in mods. 3 Share this post Link to post Share on other sites
wogz187 1086 Posted July 28, 2019 @Gunter Severloh, Quote "... then maybe this isn't the game you should be playing..." And definitely not designing for others to play. But we are digressing. AI spawn topics are the most common topic on the forum. We need a sticky. Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 28, 2019 2 hours ago, wogz187 said: AI spawn topics are the most common topic on the forum. We need a sticky. Already have you covered and its in the top of this forum section and pinned 😉 https://forums.bohemia.net/forums/topic/165560-ai-compilation-list-of-addonsmodsscripts-threads-for-arma3/ 1 1 Share this post Link to post Share on other sites
Jem777 5 Posted July 29, 2019 Thanks guys, i already encountered the unicode issue, i resolved that one. I take it that when i call the script its done in the AI’s init within the AI’s property box? Instead of asking dumb questions which im sure they have been asked many times before, i have downloaded Fockers arma 3 guide to scripting. Hopfully then no more dumb questions. Thanks again 1 Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 29, 2019 4 hours ago, Jem777 said: I take it that when i call the script its done in the AI’s init within the AI’s property box? The init.sqf will load on mission start, and read the names you have given the AI which will be in the AI's or units variable box. 4 hours ago, Jem777 said: Instead of asking dumb questions which im sure they have been asked many times before, i have downloaded Fockers arma 3 guide to scripting. Hopfully then no more dumb questions. Nice, in this game with scripting/coding there are no dumb questions, seriously, im a noob myself, i know some things only from my own work in building missions, and mods over the years, and am still learning about new various things. My interest is more geared in learning code based on what im doing mission or mod wise, so overall its not a priority if you will or main interest to really learn it, to each their own in Arma whatever floats your boat, and theres lots to learn in this game no matter what your into, thats the beauty of the game. Share this post Link to post Share on other sites
Jem777 5 Posted July 29, 2019 How do i add an attachment? I get a message saying I don't have any existing attachments. I'm trying to upload the mission as it not working. Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 29, 2019 1 hour ago, Jem777 said: How do i add an attachment? Attachments can be added to a unit by right click them, and then go down to where it says edit loadout, then from there choose his gun at the top left, and then on the otherside to the right, are attachments for that particular gun, assuming this is what your referring too but i dont understand why you would have an issue, or error message saying you dont have any attachments, new to me, more details would clear this up. Are you running any mods or is your mission all the vanilla game? Whats the message can you post it here, type it or show a screenshot? And upload the mission as publishing to workshop? Share this post Link to post Share on other sites
wogz187 1086 Posted July 29, 2019 @Gunter Severloh, Quote Already have you covered and its in the top of this forum section and pinned 😉 I must have some kind of cognitive disassociation because, not only is that the top pinned topic, I've used it like a hundred times. So thanks for that. I'll try to be more astute in the future. 1 Share this post Link to post Share on other sites
Gunter Severloh 4070 Posted July 29, 2019 Hey no worries, your welcome, link is also in my signature along with other compilations. 1 Share this post Link to post Share on other sites
Jem777 5 Posted July 30, 2019 lol, i meant how do i upload a mission so someone can have a look at it because its not working. AI is not spawning. it says i have no attachments. Share this post Link to post Share on other sites
wogz187 1086 Posted July 30, 2019 @Jem777, Quote "... how do i upload a mission so someone can have a look..." Zip it. Put it in your Google Drive. Share the link in this topic. Share this post Link to post Share on other sites
Jem777 5 Posted July 30, 2019 here is a dropbox link, i don't have a google drive account. hoping someone can have a look at the mission and workout why its not spawning. thanks https://www.dropbox.com/s/wrdhxs9e2wgcuzp/Test%20Respawn.VR.zip?dl=0 1 Share this post Link to post Share on other sites
wogz187 1086 Posted July 30, 2019 @Jem777, Hey. I couldn't get it to work the way it was either. That's not saying much because @Grumpy Old Man, scripts on a level way above us. That said, this works: Put this EH on your unit (opforAI) init field: this addEventHandler ["killed", {params ["_unit"]; execVM "respawn.sqf"; {((_this select 0) select 0) RemoveEventHandler ["killed",0]}}]; and call this "respawn.sqf", _unit = opforAI; _newUnit = (creategroup side group _unit) createUnit [typeof _unit, (_unit getPos [15 + random 35,random 360]), [], 0, "NONE"]; _newUNIT addEventHandler ["killed", {params ["_unit"]; execVM "respawn.sqf"; {((_this select 0) select 0) RemoveEventHandler ["killed",0]}}]; It's kind of an ugly Frankenstein version of GOM's but whatever works. edit: I got GOM's script to work as intended. I'm not sure what the problem was. It seems like some kind of macro/unicode thing but it's inexplicable. Make init.sqf as instructed, TAG_fnc_respawnAIEnabled = true;//set this to false any time mid mission and the respawn will be stopped TAG_fnc_respawnAI = { params ["_unit"]; _unit addEventHandler ["Killed",{ params ["_unit"]; if (!TAG_fnc_respawnAIEnabled) exitWith {false}; _newUnit = (creategroup side group _unit) createUnit [typeof _unit, (_unit getPos [15 + random 35,random 360]), [], 0, "NONE"]; _respawn = [_newUnit] call TAG_fnc_respawnAI; true }]; }; //add to multiple units or only one, as needed { _respawn = [_x] call TAG_fnc_respawnAI } forEach [opforAI]; This exactly. But copy paste might not work for the same reason I had a problem. When I added "opforAI" to the array as copied, it failed "missing variable". When I retyped the array from "foreach" on, it worked as intended. I checked for extra symbols but nothing. So, if it doesn't work, try re-typing the array in the last line. Or, here, I repacked your upload with the init file included. Have fun. 1 Share this post Link to post Share on other sites
Jem777 5 Posted July 30, 2019 very stange, thanks so much for your help ill try it out hopefully later today. thanks again. 1 Share this post Link to post Share on other sites
Jem777 5 Posted August 1, 2019 wogz187 i retyped the last line like you suggested and it still didn't work so I've just downloaded your repack and ill try it in the morning, thanks Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted August 1, 2019 On 7/30/2019 at 4:15 PM, wogz187 said: edit: I got GOM's script to work as intended. I'm not sure what the problem was. It seems like some kind of macro/unicode thing but it's inexplicable. This exactly. But copy paste might not work for the same reason I had a problem. When I added "opforAI" to the array as copied, it failed "missing variable". When I retyped the array from "foreach" on, it worked as intended. I checked for extra symbols but nothing. So, if it doesn't work, try re-typing the array in the last line. Might be the forum software adding zero width characters, have seen it in other peoples script snippets, can be confusing as heck, not really sure what's causing it. Sometimes it's also impossible quote or edit posts, the respective links are simply non responsive. Cheers 1 Share this post Link to post Share on other sites
zagor64bz 1225 Posted August 1, 2019 1 hour ago, Grumpy Old Man said: Might be the forum software adding zero width characters, have seen it in other peoples script snippets, can be confusing as heck, not really sure what's causing it. Sometimes it's also impossible quote or edit posts, the respective links are simply non responsive. Cheers Yes..it happened to me also..many times. Also, when copying/pasting blocks of scripts from the forum, I came across often to the "ghost-character-bug", which will add some weird "invisible red dots" in the coding, making it trowing all sort of errors when used. I dill with this by pasting the script into the <> code windows..it will reveal any unwanted bug. Hope I explained myself..😋 1 Share this post Link to post Share on other sites
wogz187 1086 Posted August 1, 2019 @Grumpy Old Man, @zagor64bz, Thanks guys. Do we all use "No syntax Highlighting"? I always do but yesterday, after this debacle, I started editing out the little red dots before switching to "No syntax Hightlighting". This made me realize I might actually be a tiny bit better at scripting than I thought because when I get a code snippet from this forum, and it fails, I often try to edit out the parts I don't understand and just "simplify" the function. Now I realize that the script was not necessarily failing because I, or the code snippet author, did anything wrong, but because of this hidden character issue. I mean most of the time it's probably me making mistakes but sometimes-- sometimes it's the forum error! Share this post Link to post Share on other sites
zagor64bz 1225 Posted August 1, 2019 32 minutes ago, wogz187 said: Now I realize that the script was not necessarily failing because I, or the code snippet author, did anything wrong, but because of this hidden character issue. I mean most of the time it's probably me making mistakes but sometimes-- sometimes it's the forum error! I learned that the hard way bro... I spent so many hours trying to make scripts work, banging my head left and right asking why it was working for everybody else but me...and BAM..the "little red dot bug" revealed himself..HAHAHAHAHA... 1 Share this post Link to post Share on other sites