Alexis

Disable bicycle ramming

5 posts in this topic

Add code into initPlayerLocal.sqf

 

[] spawn
{
  while {true} do 
  { 
      _obj = objectParent player; 
      if (_obj isKindOf 'Bicycle') then  
      {
          _speed = abs speed _obj; 
          _norun = nearestObjects [_obj,["Car","Tank","Plane","Air","Ship","Submarine"],7]; 
          if (count _norun > 0) then  
          { 
              if ((_obj != player) && (_speed > 3)) then  
              { 
                  _vel = velocity _obj; 
                  _obj setVelocity [0,0,0]; 
              }; 
          }; 
      };
      uiSleep 0.1;
	};
};

 

  • Like 1

Share this post


Link to post
Share on other sites
Advertisement

Nice, will try it out.. Could maybe do this as well.. Define all that can't ram and cannot be rammed.

Spoiler

[] spawn
{
  while {true} do
  _cantram       =  ["Ship","Submarine","Bicycle"];
  _cantberammed  =  ["Car","Tank","Plane","Air","Ship","Submarine","Bicycle"];
  {
      _obj = objectParent player;
      if ((typeOf _obj) in _cantram) then {
      {
          _speed = abs speed _obj;
          _norun = nearestObjects [_obj,_cantberammed,7];
          if (count _norun > 0) then 
          {
              if ((_obj != player) && (_speed > 3)) then 
              {
                  _vel = velocity _obj;
                  _obj setVelocity [0,0,0];
              };
          };
      };
      uiSleep 0.1;
    };
};

 

Edited by geekm0nkey

Share this post


Link to post
Share on other sites

@Alexis my thoughts:

 

Honestly, removing the bike completely is worth more than the FPS decrease that this code running at 0.1 seconds will cause.

_norun = nearestObjects [_obj,["Car","Tank","Plane","Air","Ship","Submarine"],7];

Arma: Get all objects near in a 7 meter radius, then sort through that all the "types", then sort through that and put the closest objects first.

objectParent can cause false behavior and can still give you the bike even though the player is not on the bike, so if someone steals your bike, you're could be running 2 loops for that bike.

Another thing to mention is that one of the checks in your if statement is completely useless, (_obj != player), the object would never be player if the object isKindOf "Bicycle".

 

I'd say if you do want to use something like this, this would better suit your needs (less FPS killing), it's also good to private your variables:

[] spawn
{
	while {true} do 
	{ 
		private _obj = vehicle player; 
		if (_obj isKindOf "Bicycle") then // Is the player on a bike
		{
			private _norun = (position _obj) nearEntities [["Car","Tank","Plane","Air","Ship","Submarine"],7]; // Only needs to get the objects we want no need to sort them.
			if (!(_norun isEqualTo []) && {(abs speed _obj) > 3}) then // Check if there are any objects, if there is then check the speed.
			{ 
				_obj setVelocity [0,0,0]; // No ramming!
			};
		};
		uiSleep 0.1;
	};
};

.........Note i have not tested this code, i just whipped it together while in the middle of a game.........

 

One thing that i do want to note is that if the bike is going 35 KM/H (i don't remember the maximum speed) it would take less than 0.01 seconds to travel the 7 meters and still be able to ram someone. and if you're running this code at 0.01 seconds then you might as well run it onEachFrame, but if you do that the FPS decrease will be even killer and at that point you might as-well just remove the bike. 

Edited by StokesMagee
  • Like 1

Share this post


Link to post
Share on other sites
18 minutes ago, geekm0nkey said:

Nice, will try it out.. Could maybe do this as well.. Define all that can't ram and cannot be rammed.

  Reveal hidden contents

[] spawn
{
  while {true} do
  _cantram       =  ["Ship","Submarine","Bicycle"];
  _cantberammed  =  ["Car","Tank","Plane","Air","Ship","Submarine","Bicycle"];
  {
      _obj = objectParent player;
      if ((typeOf _obj) in _cantram) then {
      {
          _speed = abs speed _obj;
          _norun = nearestObjects [_obj,_cantberammed,7];
          if (count _norun > 0) then 
          {
              if ((_obj != player) && (_speed > 3)) then 
              {
                  _vel = velocity _obj;
                  _obj setVelocity [0,0,0];
              };
          };
      };
      uiSleep 0.1;
    };
};

 

[] spawn
{
	private _cantRam = ["Ship","Submarine","Bicycle"]; // If a player is in these types of vehicles, check for nearby _cantBeRammed
	private _cantBeRammed = ["Car","Tank","Plane","Air","Ship","Submarine","Bicycle"]; // Vehicles that will cause the player to lose all of his speed.

	private _isValidCantRam = false;
	while {true} do 
	{
		private _obj = vehicle player;
		_isValidCantRam = false;
		{
			if (_obj isKindOf _x) exitWith { _isValidCantRam = true; };
		} forEach _cantRam; // Can't do isKindOf Array, so loop over and check if player isKindOf anything in _cantRam


		if (_isValidCantRam) then // Seems the player is in a vehicle that shouldn't ram people.
		{
			private _norun = (position _obj) nearEntities [_cantBeRammed,7]; // Only needs to get the objects we want no need to sort them.
			if (!(_norun isEqualTo []) && {(abs speed _obj) > 3}) then // Check if there are any objects, if there is then check the speed.
			{ 
				_obj setVelocity [0,0,0]; // No ramming!
			};
		};
		uiSleep 0.1;
	};
};

This what you're looking for?

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.