major woody 12 Posted April 3, 2006 In some of my missions I've VehicleCreated some units. In order to make the scripting work I need to name these vehicles (just as you do in the editor) I once had a thread in opfec regarding this quistion, but can't remember the solution... Can anybody help me with that? Â Â Share this post Link to post Share on other sites
Metal Heart 0 Posted April 3, 2006 Command reference... Quote[/b] ]type createVehicle posOperand types: type: String pos: Array Compatibility: Version 1.34 required. Type of returned value: Object Description: Create empty vehicle of given type. Pos is in format Position. See CfgVehicles for possible type values. Example: _tank = "M1Abrams" createVehicle getmarkerpos "tankFactory" Share this post Link to post Share on other sites
[aps]gnat 28 Posted April 3, 2006 Or if creating several and you need a public name like V1, V2, V3 etc, use below in a loop; Quote[/b] ]_Vloop = 1 #ALoop UnitName = format ["V%1",_Vloop] call format ["%1 =""Jeep"" createVehicle getpos _thespot",UnitName] _Vloop = _Vloop + 1 ?(_Vloop < 4):goto "ALoop" Share this post Link to post Share on other sites
hardrock 1 Posted April 3, 2006 @Gnat: I recommend the variable UnitName to be local to the script though. (-> _UnitName) Share this post Link to post Share on other sites
[aps]gnat 28 Posted April 4, 2006 @Gnat: I recommend the variable UnitName to be local to the script though. (-> _UnitName) Sure Hardrock, but Major Woody said; Quote[/b] ]just as you do in the editor which means it a Public variable (name). i.e. that name can now be used outside the script in question. Both work, but it depends how far you want to use the "name". Share this post Link to post Share on other sites
hardrock 1 Posted April 4, 2006 Gnat @ April 04 2006,15:48)]Sure Hardrock, but Major Woody said;Quote[/b] ]just as you do in the editor which means it a Public variable (name). i.e. that name can now be used outside the script in question. Both work, but it depends how far you want to use the "name". Well, no. What he wants to use in the editor isn't UnitName, but V1, V2, V3 a.s.o. UnitName changes every loop anyway, thus it contains only the name of the last created unit, which makes it useless. Share this post Link to post Share on other sites
major woody 12 Posted April 4, 2006 Quote[/b] ]Well, no. What he wants to use in the editor isn't UnitName, but V1, V2, V3 a.s.o. True  Share this post Link to post Share on other sites
baddo 0 Posted April 4, 2006 Just to add, this could be modified to something like this (no UnitName variable at all): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Vloop = 1 #ALoop call format ["%1 =""Jeep"" createVehicle getpos _thespot",format ["V%1",_Vloop]] _Vloop = _Vloop + 1 ~1 ?(_Vloop < 4):goto "ALoop" Note the added delay which can be a good thing to do when creating lot of objects. If no delay is in the loop and there are lot of objects created, the player is very likely to experience a heavy lag peak when all the objects are created. Also if you really don't want a delay between your createVehicle commands, you could shorten this to one line: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{call format ["%1 =""Jeep"" createVehicle getpos _thespot", _x ]} forEach ["v1","v2","v3"] This is suitable for relatively small number of objects to create so you won't need to type too much into the array plus the lag peak will not be that big. Also a situation where you know in advance how many objects you will create will be better for this than a dynamically changing situation. Share this post Link to post Share on other sites
hardrock 1 Posted April 4, 2006 Yep. You can simplify it even more if you are using a numbered system. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{call format ["jeep%1 =""Jeep"" createVehicle getpos _thespot", _x ]} forEach [1,2,3] Share this post Link to post Share on other sites
[aps]gnat 28 Posted April 4, 2006 Well, no. What he wants to use in the editor isn't UnitName, but V1, V2, V3 a.s.o. UnitName changes every loop anyway, thus it contains only the name of the last created unit, which makes it useless. Yes, I understood V1 V2 etc was what was to be use, but I was pretty sure a side effect of using a private variable in name creation was that the actual name did NOT become available in any form OUTSIDE the script. nm, plenty of solutions there now Share this post Link to post Share on other sites
hardrock 1 Posted April 5, 2006 Gnat @ April 05 2006,01:42)] Yes, I understood V1 V2 etc was what was to be use, but I was pretty sure a side effect of using a private variable in name creation was that the actual name did NOT become available in any form OUTSIDE the script. nope Share this post Link to post Share on other sites
Nicolas Eymerich 0 Posted April 5, 2006 Use a GlobalArray. In the init.sqs (usually) put a global variable: CreatedVehicle = [] Then, any time you create a vehicle you have to put, at the end of the creation, this line CreatedVehicle = CreatedVehicle + [[_tank]] where "_Tank" is the unit you've just created in the local script. However, since you create some crew too I suggest you to use this line CreatedVehicle = CreatedVehicle + [[_tank, _crew]] (crew is the array storing the man) instead the first one. Than using others scripts you're able to control the unit created by using this line at the beginning of any script (it'll make life easier trust me) _tank = (CreatedVehicle select 0) select 0 _crew = (CreatedVehicle select 0) select 1 and so on... So: If you need to work with the second vehicle than you'll have to write: _tank = (CreatedVehicle select 1) select 0 _crew = (CreatedVehicle select 1) select 1 and so on... Share this post Link to post Share on other sites
major woody 12 Posted April 5, 2006 Please forgive me if I did'nt made my self clear   What I meant was in normal edition you name your tank, chopper, man etc. in the textfield 'name' in order to make it work as a part of a script... Is it possible to give a VehicleCreated vehicle a name as you normally would have done in the 'name' field?  Share this post Link to post Share on other sites
hardrock 1 Posted April 5, 2006 Is it possible to give a VehicleCreated vehicle a name as you normally would have done in the 'name' field? Of course <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">name = "Type" createVehicle [0,0,0] will do the same as putting a vehicle of type 'Type' in the editor with the name 'name'. It's just a variable. Share this post Link to post Share on other sites
major woody 12 Posted April 5, 2006 I better explain my intentions! My rocketlauncher is called Launcher1 - When I convert it from FiringMode into MovingMode I use the buildIn script for that. [launcher1] exec "\OWP_ZIL_Scripts\ToMove.sqs"; The script deletes the FiringMode and VehicleCreates a new MovingMode. THAT MovingMode is what I would like to name Launcher1 and so on I'm most greatfull you spend your time helping me solving my problems  Share this post Link to post Share on other sites