swillis12931 13 Posted May 1, 2015 Hi, Not sure if anyone still messes around with OFPR but any tips and suggestions would be appreciated :) I am trying to create a dynamic mission with respawning empty vehicles that players can use if they want. I have been able to get the vehicles to spawn but the original vehicle is only deleted during the first time a respawn is initiated. I have looked everywhere and the answers I have found are not for OFPR but I speculate that the problem I am having is that I am not naming my respawned vehicles. I looked at the list of Script Commands on the Community Wiki but I am not sure which one to use. Here is my test script: deletevehicle hel1 ~0.1 _hel1 = "VTE_uh1a" createvehicle getpos he1 _hel1 setdir 90 ~0.1 exit Thanks, Swillis Share this post Link to post Share on other sites
kenoxite 156 Posted May 1, 2015 (edited) You're using both a global and a local variable to refer to the spawned vehicle. Local variables will work only in the scope of that script. Once the vehicle has spawned and the script ended, the _hel1 variable is deleted. As you seem to want to delete the spawned vehicle the next time the script is called you should change the scope of the _hel1 variable to global by removing the preceding underscore, so it turns "hel1". So, a working version of your script would look like: deletevehicle hel1 ~0.1 hel1 = "VTE_uh1a" createvehicle getpos he1 hel1 setdir 90 ~0.1 exit The main visual cue to detect the scope of a variable is to check if it has an underscore or not. Global variables don't have a preceding one, local ones do. More info here: https://community.bistudio.com/wiki/Variables#Namespace Edited May 1, 2015 by kenoxite Share this post Link to post Share on other sites
swillis12931 13 Posted May 1, 2015 I've removed the underscore but I'm getting an error message whenever I select the action to respawn: 'hel1 |#| "vte_uh1a" createvehicle getpos he1':Error Reserved Variable In Expression I've read several posts regarding this issue on ARMA and they seem to suggest that I need to add a count 0. To be honest, this is my first time trying to make a mission and I really don't know what I am doing unfortunately:( I've been looking at downloaded missions and trying to "reverse engineer" in a way and it has been successful for the most part. Share this post Link to post Share on other sites
kenoxite 156 Posted May 1, 2015 I've removed the underscore but I'm getting an error message whenever I select the action to respawn: That error just means that you have already assigned the hel1 global variable to another unit or object, most likely one manualy placed in the mission editor. Change hel1 to another name (say, hel2 or helo1) or delete the name of the other one. As a general rule, global variables must be unique and unit/object names count as global variables. Share this post Link to post Share on other sites
swillis12931 13 Posted May 1, 2015 Oh wow, I understand what I was doing wrong now. I had placed an empty vehicle in the spot where I wanted the vehicle to spawn at and named it hel1. Regarding respawning vehicles, I should just put a marker at that location and not an empty object, right? Thanks Share this post Link to post Share on other sites
kenoxite 156 Posted May 1, 2015 Regarding respawning vehicles, I should just put a marker at that location and not an empty object, right? I haven't dealt with multiplayer code for a good while. I know that a properly named marker does work for infantry units, but I don't remember if it worked also for vehicles in OFP. I assume it would work for vehicles manned by players. You should also create and edit the description.ext file for this to work. See: https://community.bistudio.com/wiki/Description.ext#respawn For singleplayer you can use a marker as the spawning location (just set it's type to "Empty", so it's hidden on the map) or a unit, object or game logic. Something that returns getPos or getMarkerPos properly. You still need to create a script for the spawning itself, though, something similar to what you have already. Like: "jeep" createVehicle (getMarkerPos "westVehRespawn") Share this post Link to post Share on other sites
swillis12931 13 Posted May 1, 2015 Okay, thanks! I got all the vehicles to spawn and delete whenever the spawn script is activated. I'm trying to do the same with my squad through "createunit" but the units won't delete :eek: I've used the same approach as you've suggested for my vehicle spawn script except with one gamelogic spawnpoint: deletevehicle troop2 deletevehicle troop3 deletevehicle troop4 deletevehicle troop5 ~0.1 troop2 = "VTE_armywrto" createunit [getpos squad,troop1] troop3 = "VTE_armywmedic" createunit [getpos squad,troop1] troop4 = "VTE_armyw" createunit [getpos squad,troop1] troop5 = "VTE_armywmg" createunit [getpos squad,troop1] ~0.1 exit Am I doing something wrong? Share this post Link to post Share on other sites
zulu1 145 Posted May 2, 2015 (edited) Okay, thanks! I got all the vehicles to spawn and delete whenever the spawn script is activated.I'm trying to do the same with my squad through "createunit" but the units won't delete :eek: I've used the same approach as you've suggested for my vehicle spawn script except with one gamelogic spawnpoint: deletevehicle troop2 deletevehicle troop3 deletevehicle troop4 deletevehicle troop5 ~0.1 troop2 = "VTE_armywrto" createunit [getpos squad,troop1] troop3 = "VTE_armywmedic" createunit [getpos squad,troop1] troop4 = "VTE_armyw" createunit [getpos squad,troop1] troop5 = "VTE_armywmg" createunit [getpos squad,troop1] ~0.1 exit Am I doing something wrong? Most spawning script packages use a "dummy unit" to perform actions. The dummy is located usually way off on a small island out of harms way. The name is totally optional, some people use gravedigger. The example script below uses the _this variable. You need to adapt it for your use. When activated it will make dead bodies sink into the ground, then deletes them. #deadloop ~1 ?(alive _this):goto "deadloop" ~(10 + random 6) (leader eastdummygroup) action ["hidebody",_this] ~4 deleteVehicle _this EXIT Here is another slight variation by Nikiller: ;[unitName] exec "Del_Unit.sqs" ? !(local server): exit _b = _this select 0 ~300 ? alive gravedigger: gravedigger action ["hidebody",_b] ~10 deleteVehicle _b exit Edited May 2, 2015 by Zulu1 Share this post Link to post Share on other sites
swillis12931 13 Posted May 2, 2015 Hi Zulu1, I guess I wasn't too clear with my problem. With the current script I am using, I start off with a four men in my little squad. However, when I initiate the script again through an action, I get four extra guys added to my squad which makes a total of 8 men under my command. It seems like "deletevehicle" is not deleting the men that are spawned. The scripts you provided are still helpful though. I think I'll use them for my "REST" command when out in the field to mimic KIA's being put in body bags. Thanks again! Share this post Link to post Share on other sites
zulu1 145 Posted May 2, 2015 (edited) Looking at what you did it wont really accomplish what you want I think. It is deleting units before they are created. You should use two different scripts, one to create and one to delete. In the delete script you need to perform an alivecheck routine on the units. Then you can use the deleteunit code for the dead ones. A killed eventhandler could be another option. The big problem here is most spawn scripts use a variable to be able to endlessly spawn new units or groups. Using specific names as you are is problematic. I don't think you can reuse the same names (troop2, 3, 4, 5) over and over. In other words you run the script once and if you want more to spawn then a new script needs to run with (troop6, 7, 8, etc.) I've had a lot of fun using this spawn package, it is very versatile. It may do what you want. http://www.ofpec.com/editors-depot/index.php?action=details&id=314&game=OFP Edited May 2, 2015 by Zulu1 Share this post Link to post Share on other sites
kenoxite 156 Posted May 2, 2015 (edited) I'm trying to do the same with my squad through "createunit" but the units won't delete Assigning global variables to dynamically spawned infantry isn't as straightforward as it is for vehicles. In this case, you need to assign the global variable for the given unit in the init parameter of the createUnit function. Such as: "soldierWB" createUnit [getPos player, group player, {troop2=this;<any other code to be executed on init>}]. See the third example found here: https://community.bistudio.com/wiki/createUnit But, if all you want is to rebuild your squad with fresh units every time you run this script and it's for single player all you'd need to do is something like: ; Delete current units {deleteVehicle _x}count ((units player)-[player]); ; Spawn new units "VTE_armywrto" createunit [getPos player, group player]; "VTE_armywmedic" createunit [getPos player, group player]; "VTE_armyw" createunit [getPos player, group player]; "VTE_armywmg" createunit [getPos player, group player]; exit; There's really no need to use as many global variables as you're currently using. While global variables are extremely handy they have some memory cost (as its value must be stored through the whole mission) and there's also a limit in OFP for the total amount you can have before a saved game gets corrupted (about 40 IIRC). Alternatively, you could try implementing the spawning system Zulu1 suggested. It might save you some time and, if you check its code, offer you futher insight about spawning and scripting in general in OFP. Edited May 2, 2015 by kenoxite Share this post Link to post Share on other sites
akvadakar 21 Posted May 3, 2015 troop2 = "VTE_armywrto" createunit [getpos squad,troop1] troop2= does not work for createunit - you can use "troop2=" only with createvehicle. To give a newly created unit a name, put "newUnit = this" in the init field. e.g.: "VTE_armywmg" createUnit [getpos squad, troop1, "troop2=this",1,"COLONEL"]; https://community.bistudio.com/wiki/createUnit Share this post Link to post Share on other sites