Jump to content
silente13

Spawn car with script

Recommended Posts

Hello! I have a problem i'm trying to spawn a car with a script. I think that the script is right cause is too easy, so my problem is: How can i spawn a vehicle with that script? I thought I'd press 'space' on a soldier and the car on a spawn point. Is it possible? Someone can help me?

Share this post


Link to post
Share on other sites

Add this in your player's init box :

this addaction ["Spawn  vehicle", "spawn.sqf"];

And create a sqf file named spawn.sqf in the mission folder. Put this in it :

hint "Spawning a vehicle ...";
sleep 2;

"B_G_Offroad_01_F" createVehicle position player; // creates the vehicle on player's location

hint "Vehicle spawned near you";
sleep 2;
hint "";

Share this post


Link to post
Share on other sites

Last two lines are kinda useless. Hint will anyway disappear after few seconds.

Share this post


Link to post
Share on other sites

Last two lines are kinda useless. Hint will anyway disappear after few seconds.

Yeah you're right ;)

Share this post


Link to post
Share on other sites

Last two lines are kinda useless. Hint will anyway disappear after few seconds.

 

Correct, but for some, like myself at times, I don't like to have a hint on my screen for an extended period of time, so I do clear the screen as exampled above.

Share this post


Link to post
Share on other sites

Correct, but for some, like myself at times, I don't like to have a hint on my screen for an extended period of time, so I do clear the screen as exampled above.

Plus, that doesn't do anything bad to the code, might as well leave it...

Share this post


Link to post
Share on other sites

Plus, that doesn't do anything bad to the code, might as well leave it...

 

Only change I would make to it, as with most of my old projects and such, I couldn't have the suspension, or it needed to move onto the next piece of code after the hint without waiting for the hint to complete, so I would spawn it in:

_fnc_timedHint =
{
	params ["_hint","_time"];
	hint _hint;
	sleep _time;
	hint "";
};

["Spawning a vehicle ...",2] spawn _fnc_timedHint;

"B_G_Offroad_01_F" createVehicle position player;

["Vehicle spawned near you",2] spawn _fnc_timedHint;
  • Like 1

Share this post


Link to post
Share on other sites

 

Only change I would make to it, as with most of my old projects and such, I couldn't have the suspension, or it needed to move onto the next piece of code after the hint without waiting for the hint to complete, so I would spawn it in:

_fnc_timedHint =
{
	params ["_hint","_time"];
	hint _hint;
	sleep _time;
	hint "";
};

["Spawning a vehicle ...",2] spawn _fnc_timedHint;

"B_G_Offroad_01_F" createVehicle position player;

["Vehicle spawned near you",2] spawn _fnc_timedHint;

Thanks for the trick ;)

Share this post


Link to post
Share on other sites

Correct, but for some, like myself at times, I don't like to have a hint on my screen for an extended period of time, so I do clear the screen as exampled above.

 

Yeh I know, I've always wondered why hint and hintSilent don't accept a parameter which defines the time it's showed. Time for a ticket ;)

Share this post


Link to post
Share on other sites

Thank you guys! And if want spawn a care in a marker? I will not write 'position player', but ' createVehicle in 'name marker' right? And if i want load some weapon or other? Thanks!

Share this post


Link to post
Share on other sites

I will not write 'position player', but ' createVehicle in 'name marker' right? A

 

 

markerPos "markerName" or getMarkerPos "markerName" both the same

  • Like 1

Share this post


Link to post
Share on other sites

markerPos "markerName" or getMarkerPos "markerName" both the same

 

Ok thank you very much, and if i want load in car some weapon or else?

Share this post


Link to post
Share on other sites

Ok thank you very much, and if i want load in car some weapon or else?

 

Not tested, might as well not work ...

_veh = createVehicle ["B_G_Offroad_01_F", getMarkerPos "markerName"]; 
_veh call compile format ["%1=_this select 0","vehicle1"];

clearWeaponCargoGlobal vehicle1; // clears all weapons
clearMagazineCargoGlobal vehicle1; // clears all mags
vehicle1 addWeaponCargoGlobal ["hgun_Rook40_F", 1]; // adds a gun

-EDITED-

Share this post


Link to post
Share on other sites
_veh = createVehicle ["B_G_Offroad_01_F", getMarkerPos "markerName"] 
_veh call compile format ["%1=_this select 0","vehicle1"];

clearWeaponCargoGlobal vehicle1; // clears all weapons
clearMagazineCargoGlobal vehicle1; // clears all mags
vehicle1 addWeaponCargoGlobal "hgun_Rook40_F"; // adds a gun

 

From what I can tell, that looks like it should work. Just don't forget a ';' after the first line :)

 

EDIT: Actually you may have to define the amount to add as well. Like this:

vehicle1 addWeaponCargoGlobal ["hgun_Rook40_F", 1];

Haven't tested either so i'm not sure.

Share this post


Link to post
Share on other sites

missing ; at end of first line. It also won't work as it needs five elements  and only two provided.

If it did work I'm not sure _this is correct shouldn't it be _veh  but that isn't an array so no need for select 0.

 

I think there is some confusion between the two methods of spawning.

 

 

first there is this.

_veh = "B_G_Offroad_01_F" createVehicle (getMarkerPos "markerName");
_veh setVehicleVarName "vehicle1";// this is what may show on the screen it does not have to be the actual name of the vehicle.
missionNamespace setVariable ["vehicle1", _veh, true];// this would be the actual physical name of the vehicle and can be use directly (vehicle1 setdamage 1)

Second method

_veh = createVehicle ["B_G_Offroad_01_F",getMarkerPos "markerName",[], 0, "none"];
_veh setVehicleVarName "vehicle1";
missionNamespace setVariable ["vehicle1", _veh, true];

If you want to create multiple vehicles using the same name as the base you will need to increment the name.

   for "_i" from 1 to 4 step 1 do {
    _name = format["vehicle%1", _i];// increments the vehicle name by 1 so vehicles will be named vehicle1,vehicle2 ect.
    _veh = createVehicle ["B_G_Offroad_01_F",getMarkerPos "markerName",[], 0, "none"];
    _veh setVehicleVarName _name;
    missionNamespace setVariable [_name, _veh, true];
};  

Share this post


Link to post
Share on other sites

And unless you need to reference each vehicle globally after creation there is no need to name it, just use the local variable "_veh" as your reference to the vehicle.

_veh = createVehicle ["B_G_Offroad_01_F", getMarkerPos "markerName"];
clearWeaponCargoGlobal _veh;
clearMagazineCargoGlobal _veh;
_veh addWeaponCargoGlobal "hgun_Rook40_F";
  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×