Nemorz 11 Posted August 7, 2009 Hi... I have another problem that despite having spent hours on it already, I am unable to fix. First off, I'm using a Trigger to check for a specific vehicle name using clist = [AA1,AA2,AA3,AA4] in my init.sqsVehicle being named AA1 BlueFor-Detected-Repeatedly On Act: []exec "aa1.sqf" which has the following KAGroup = CreateGroup East;KA52B = createVehicle ["Ka52Black", [(getMarkerPos "AAStart1") select 0,(getMarkerPos "AAStart1") select 1,100], [], 0, "FLY"]; KA52BPilot1 = KAGroup createUnit ["RU_Soldier_Pilot", [0,0,1], [], 0, "CAN_COLLIDE"]; KA52BPilot1 getInDriver KA52B; KA52BPilot2 = KAGroup createUnit ["RU_Soldier_Pilot", [0,0,1], [], 0, "CAN_COLLIDE"]; KA52BPilot2 getInGunner KA52B; wp1 = KAGroup addwaypoint [position AAEnd1, 0]; wp1 setwaypointtype "SAD"; I have a Marker named AAStart1 (to define where it spawns) and an Invisible H Object named AAEnd1 (to define it's destination) Everything works swell, until the Chopper spawns, then instead of following it's path, it simply drops out of the sky, engine still on, but it drops. This all worked before the patch so I'm wondering if anyone can maybe shed some light on whats happening? Some things I have tried: -Changed setwaypointtype to various other formats -Changed getInDriver to assignedDriver / assignAsDriver etc. -Removed gunner spawning -Tried several types of units spawning as Driver Share this post Link to post Share on other sites
kylania 568 Posted August 7, 2009 Use moveInDriver instead of the non-existent getInDriver. Or use Functions and the BIS_fnc_spawnvehicle function. 1 line of code vs 5. :) Share this post Link to post Share on other sites
Nemorz 11 Posted August 7, 2009 Cool, I'll give it a shot ;) How do I set a spawned units waypoint though when using BIS_fnc_spawnvehicle? Thanks. Edit: I had moveInDriver originally (the script above was one of the many changes I tried, it still just drops to the ground) Share this post Link to post Share on other sites
kylania 568 Posted August 7, 2009 Are there already Russian units on the map? If not you'll need to create a "Center" for them. Either via createCenter or simply place an OPFOR Rifleman on the map anywhere and make him "Probability of Presence" = 0%. To test this spawn the helo right next to your player on the ground so you can see if the crew is created or not. Share this post Link to post Share on other sites
BlackAlpha 10 Posted August 7, 2009 (edited) Here's some BIS code I stole to spawn vehicles. I've also included a waypoint example. _grp = createGroup west; _type = "AH1Z"; //10 meters from the ground from the player position. _startpos = [(getpos player select 0), (getpos player select 1), 10]; //Create vehicle using above start position; set a random direction (360); use above type; use above group. _data = [_startpos, random 360, _type, _grp] call BIS_fnc_spawnVehicle; _chopper = _data select 0; _wp = _grp addWaypoint [(getpos player), 0]; _wp setWaypointType "MOVE"; _wp setWaypointTimeout [5, 5, 5]; _wp = _grp addWaypoint [(getpos player), 0]; _wp setWaypointType "GETOUT"; If your air vehicle is crashing after spawn, it's most likely because there is no crew inside. Edited August 7, 2009 by BlackAlpha Share this post Link to post Share on other sites
Nemorz 11 Posted August 7, 2009 (edited) Ok well I have this script in various Missions to spawn Tanks/UAZ etc and the Driver/Gunner positions are sure as hell there, I also placed my character within range with a Sniper rifle to spot the crew, they are indeed there. But it crashes anyway. Thanks for that BlackAlpha although I'm not quite sure how to use it :/ Edit: Ok well BlackAlpha was right, crew isn't spawning, which is odd coz I use the same script for vehicles as stated before and they work just fine. Not entirely sure how to use _blah commands though? I apologize but I'm still a rookie in this game ;) Edited August 7, 2009 by Nemorz Share this post Link to post Share on other sites
kylania 568 Posted August 7, 2009 A variable with an underscore ahead of it is a "local" variable (ie: _input or _myLocalVariable) and is only valid within it's specific "code block". So in these scripts you can refer to something as _thing but outside (globally) other scripts won't know what you're talking about. In short, use _variableName for variables you only need within the single script, anything you'll be referring to elsewhere you'll want to use variableName which would be a global variable everything can see. In BlackAlpha's example this code creates the chopper: //Create vehicle using above start position; set a random direction (360); use above type; use above group. _data = [_startpos, random 360, _type, _grp] call BIS_fnc_spawnVehicle; _chopper = _data select 0; _chopper will be the chopper's object only for that script. If he'd used chopper = _data select 0; then he'd be able to refer to the object "chopper" (the helo) elsewhere in the mission. Share this post Link to post Share on other sites
Nemorz 11 Posted August 7, 2009 Ok I think I understand that now. So _blah code can go into a script and only gets called from there and use say, an external trigger to simply execute said script and it'll do it's business. Thanks, although that code also is not working too well for me, it still just crashes :x But I think it's more me being an idiot than the code Share this post Link to post Share on other sites
BlackAlpha 10 Posted August 7, 2009 (edited) Ok well I have this script in various Missions to spawn Tanks/UAZ etc and the Driver/Gunner positions are sure as hell there, I also placed my character within range with a Sniper rifle to spot the crew, they are indeed there. But it crashes anyway.Thanks for that BlackAlpha although I'm not quite sure how to use it :/ Edit: Ok well BlackAlpha was right, crew isn't spawning, which is odd coz I use the same script for vehicles as stated before and they work just fine. Not entirely sure how to use _blah commands though? I apologize but I'm still a rookie in this game ;) Just put the code in a new .sqf file and call the file using: _handle = execVM "filename.sqf"; For example put it in the trigger activation field or inside another script file. You can put the code itself in another script file if you want and change it to suit your own needs. Basically the _ means that it's a local variable which only exists inside the file you create it in. You don't always need all variables to be available from everywhere because it takes up more computer resources, so you make them local to the script. If you want, you can just remove the underscores, though. By the way, you might need the Functions module to be able to use the function that spawns the stuff for you. So, create a functions module using the editor and that's it. No need to synch it or anything, it just needs to exist in the mission. _grp = createGroup west; _type = "AH1Z"; //10 meters from the ground from the player position. _startpos = [(getpos player select 0), (getpos player select 1), 10]; //Create vehicle using above start position; set a random direction (360); use above type; use above group. _data = [_startpos, random 360, _type, _grp] call BIS_fnc_spawnVehicle; _chopper = _data select 0; _wp = _grp addWaypoint [(getpos player), 0]; _wp setWaypointType "MOVE"; _wp setWaypointTimeout [5, 5, 5]; _wp = _grp addWaypoint [(getpos player), 0]; _wp setWaypointType "GETOUT"; Here's an explanation of the example script: It starts off by creating a new (empty) group of the side west and stores this group in the variable _grp. After that it stores the string (which is simple text with quotation marks around it) "AH1Z" in the variable _type. This variable is like a shortcut to the text, you won't need to type it again. Just type in _type and it will mean exactly the same as "AH1Z" (quotation marks included). Then it stores a position in the array _startpos. I guess I might have made this a bit too hard to understand. You can put something else in there if you want, like this: _startpos = getpos player. Problem is that the chopper will spawn ON TOP of the player. With my above code, it will take the same coordinates as the player position but spawn it 10 meters above those coordinates An array that stores a position looks like this [ number, number, number ]. The brackets around the numbers mean that they all belong to the same array, which stores 3 different numbers. A normal variable can generally only contain one value but an array can contain multiple values. In this example it contains 3 values. First number is the X coordinate, second number is the Y coordinate and third number is the Z (height) coordinate. Let's say that the array actually looks like this: [ 5, 12, 0 ]. X position is 5, Y position is 12 and height is 0 because the player is on the ground. If you want to select something from an array, you can do it like this: arrayname select 0, arrayname select 1, arrayname select 2, etc. It starts counting from 0, not from 1! My code looks like this: [(getpos player select 0), (getpos player select 1), 10]; There are brackets around it, which means this is an array. Notice that there are two commas which seperate 3 different values. (getpos player select 0) means get the array with the position of the player and select the first value (x coordinate). (getpos player select 1) means get the array with the position of the player and select the second value (y coordinate). The number 10 simply means that the Z coordinate is 10, so it's 10 meters above the ground (not on top of the player). That would make the array result look like this: [ 5, 12, 10]. The third value is not 0 anymore and thus the chopper won't spawn on top of you. That was the hard part. Next it will call a function made by the developers. This function actually spawns the vehicle with crew. _data = [_startpos, random 360, _type, _grp] call BIS_fnc_spawnVehicle; You send [_startpos, random 360, _type, _grp] to BIS_fnc_spawnVehicle. Note that you are sending an array that contains multiple values that you have created earlier. The spawnvehicle function will take those values, run them through some coding and spawn the vehicles + crew for you and it will return an array with some data that you might want to store. The data this specific function returns is the vehicle object itself, an array with all crew objects and a variable with the group of the crew. So for example it might look like: [thenewchopper,[crew1, crew2],groupname]. This array is returned from the function back into your own script and you save this in _data, so that you can manipulate it using this array name _data. You might be wondering, what exactly am I sending to the function that spawns the vehicle + crew for me? [(array with a position), (number representing a heading),(string representing name of vehicle), (group)] call BIS_fnc_spawnVehicle The position you already have stored in _startpos, so you just put _startpos in there. For the heading you can put any number in there from 0 to 360. I decided to let the script put a random number in there from 0 to 360. I do that by putting random 360 (from 0 to 360) in there. The type you want is already stored in _type. The group is already created and stored in _grp, so you just put that in there. You want to select the chopper object, so you add this line: _chopper = _data select 0. Select first value in the array _data, which would be thenewchopper. Now thenewchopper value is stored in the variable _chopper or in other words, you now have it selected in the variable _chopper. If you want to select the group of the crew, just use the variable _grp. The waypoints are kind of easy, no? _wp = _grp addWaypoint [(getpos player), 0]; Create new waypoints for the group that is stored in the variable _grp (that should be your chopper crew in this script). Store the waypoint in the variable _wp so that we can manipulate it later on. _wp setWaypointType "MOVE"; Set the type of the waypoint stored in _wp to the type of "move". _wp = _grp addWaypoint [(getpos player), 0]; Now theres a SECOND waypoint created for the group stored in _grp. And this NEW waypoint is stored in in the variable _wp, the old value is deleted. So now the variable _wp stores a new waypoint of which you want to change the type to: _wp setWaypointType "GETOUT"; Edited August 7, 2009 by BlackAlpha Share this post Link to post Share on other sites
Nemorz 11 Posted August 11, 2009 Awesome stuff BlackAlpha. Thanks alot for this. Will take me a while to read through and put into practice but I appreciate the long and more importantly detailed post. Share this post Link to post Share on other sites