Jump to content
Sign in to follow this  
dreadedentity

[CODE SNIPPET] Fun with scripting - Make a gun that shoots CARS

Recommended Posts

Hello all,

I got bored again tonight and decided to mess around with Event Handlers. Turns out making a gun that shoots strider's is easy!

I wish my video didn't come out at 360p for some reason and is blurry as hell.

add to your init.sqf

player addEventHandler ["Fired",
{
_bullet = _this select 6;
_dir = _this select 0;
_velocity = velocity _bullet;
[_bullet, _velocity, _dir] spawn 
{
	sleep 0.02;
	_newPos = getPos (_this select 0);
	deleteVehicle (_this select 0);
	_newBullet = createVehicle ["I_MRAP_03_F", _newPos, [], 0, "NONE"];
	//_newBullet setDir (_this select 2); //breaks setVelocity for some reason. do not uncomment.
	_newBullet setVelocity (_this select 1);
};
}];

Share this post


Link to post
Share on other sites

Nice effort. Some of the syntax is wrong though which is why you had issues with setDir plus you don't need to spawn unless you really want to.

player addEventHandler ["Fired", {
   _bullet = _this select 6;
   _unit = _this select 0;
   _newPos = _unit modelToWorld [0,8,1];
   _veh = createVehicle ["I_MRAP_03_F",_newPos,[],0,"CAN_COLLIDE"];
   _veh setDir getDir _unit;
   _veh setVelocity velocity _bullet;
   deleteVehicle _bullet;
}];

Edited by Das Attorney
stuff

Share this post


Link to post
Share on other sites

Thanks, I still get commands wrong sometimes too! Anyway, the reason I had spawned a new thread was specifically for the sleep statement, you don't want to spawn a car right at the barrel. Maybe I should have tested that, though. I just thought it was best to avoid it so I don't inadvertently create an awesome suicide method. :p

Also, I noticed that sometimes the cars would not be spawned where they should (sometimes they'd be off to the side), is that related to the "CAN_COLLIDE" you changed?

Edited by DreadedEntity

Share this post


Link to post
Share on other sites

Yes the CAN_COLLIDE tells the engine that the object being created doesn't need to go through a "safe position" to spawn check, basically putting it where it's "supposed" to be. Now obviously if it ends up somewhere without proper space, a vehicle might just explode, but I never minded a fireworks show here and there :p.

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
Sign in to follow this  

×