KoffeinFlummi / AGM

Authentic Gameplay Modification for A3 | THIS PROJECT IS NO LONGER BEING WORKED ON. ALL ISSUES AND PULL REQUESTS WILL BE IGNORED.
Other
125 stars 84 forks source link

Able to break windows without weapons #1605

Open JinougaF opened 9 years ago

JinougaF commented 9 years ago

I feel it was very necessary for us to break a window without waste the ammo of our weapons.Like in real life we could use the stock of our rifles to break a window.

PabstMirror commented 9 years ago

Based on AGM_Interaction_fnc_getDoor, seemed to be working on stratis, but more testing needed.

+/*
Name: AGM_Interaction_fnc_breakWindowGlass

Author: Pabst Mirror

Description:
  Breaks the window the player is looking at.
  Compatible with A3 and custom buildings that have Class HitPoints for each window.

Parameters:
  NONE

Returns:
  NONE
*/

private ["_player", "_theHouse", "_theHitPointName", "_position0", "_position1", "_intersections", "_iFireIntersections", "_visualName", "_hitPointCount", "_index", "_config", "_position", "_glassSoundEffect", "_weapon"];

_player = AGM_player;
_theHouse = objNull;
_theHitPointName = "";

//Player is usualy looking through a window and won't tirgger an intersection, so look up down left right as well
{
  _position0 = positionCameraToWorld [0, 0, 0];
  _position1 = positionCameraToWorld _x;
  _intersections = lineIntersectsWith [(ATLToASL _position0), (ATLToASL _position1), objNull, objNull, true];
  if ((count _intersections) > 0) exitWith {_theHouse = _intersections select (count _intersections - 1)};
} forEach [[0,0,2], [0,2,2], [0,-2,2] ,[-2,0,2], [2,0,2]];

if (isNull _theHouse || {(typeOf _theHouse) == ""}) exitWith {//couldn't find house, or it doesn't have a class
  systemChat "Debug: Couldn't Find House";
  false
};

if (!((typeOf _theHouse) isKindOf "HouseBase")) exitWith {//Only break house windows
  systemChat "Debug: Not A House";
  false
};

_position0 = positionCameraToWorld [0, 0, 0];
_position1 = positionCameraToWorld [0, 0, 2];
_iFireIntersections = [_theHouse, "FIRE"] intersect [_position0, _position1];

if (((count _iFireIntersections) < 1) || {(count (_iFireIntersections select 0)) < 1}) exitWith {  //couldn't find Fire intersection (windows)
  systemChat "Debug: couldn't find Fire intersection";
  false
};
_visualName = (_iFireIntersections select 0) select 0;
_hitPointCount = count (configFile >> "CfgVehicles" >> (typeOf _theHouse) >> "HitPoints");
_index = 0;

while {_index < _hitPointCount} do {
  _config = (configFile >> "CfgVehicles" >> (typeOf _theHouse) >> "HitPoints") select _index;
  if (([_config, "visual", ""] call BIS_fnc_returnConfigEntry) == _visualName) exitWith {
    _theHitPointName = configName _config;
  };
  _index = _index + 1;
};
if (_theHitPointName == "") exitWith {  //couldn't find window hitpoint (will happen on old A2 buildings without proper configs)
  systemChat "Debug: Couldn't Find Hitpoint";
  false
};

_position = _player modelToWorld (_player selectionPosition "LeftHand");
_position set [2, (_position select 2) + ((getPosASLW _player select 2) - (getPosATL _player select 2) max 0)];

_glassSoundEffect = ["A3\sounds_f\weapons\hits\glass_5.wss", "A3\sounds_f\weapons\hits\glass_6.wss", "A3\sounds_f\weapons\hits\glass_7.wss", "A3\sounds_f\weapons\hits\glass_8.wss"] call BIS_fnc_selectRandom;

playSound3d [_glassSoundEffect, _player, false, _position, 1.41254, 1, 100];

_weapon = currentWeapon _player;
if ((_weapon == (primaryWeapon _player)) && {_weapon != ""}) then {

  //WIP - TODO: Aquire decent animation gesture

  //Animation isn't great: "push with left hand"
  [_player, "AmovPercMstpSrasWrflDnon_AinvPercMstpSrasWrflDnon_Putdown", 0] call AGM_Core_fnc_doAnimation;
};

// _theHouse setHitPointDamage [_theHitPointName, 1];
// [[_theHouse, [_theHitPointName, 1]], "setHitPointDamage", true, true] call BIS_fnc_MP;
[[_theHouse, _theHitPointName], "AGM_Interaction_fnc_breakWindowGlassSetHit", -1] call AGM_Core_fnc_execPersistentFnc;

true
commy2 commented 9 years ago

Duplicate of https://github.com/KoffeinFlummi/AGM/issues/309

bux commented 9 years ago

Don't forget AiA buildings ... if applicable

PabstMirror commented 9 years ago

Updated above code to fix a few bugs.

I think everything in Stratis, Altis will be fine, but some buildings in AiA just aren't going to work. They need entries in (class HitPoints) to work. And I don't think most A2 stuff has them (although a lot of A2 buildings avoid glass by either being pre-shattered or just have windows without glass.

Sahrani seems to be fine, I think SMD guys have put a lot of love into redoing all the buildings to proper A3 configs.

PabstMirror commented 9 years ago

Demo: https://www.youtube.com/watch?v=hQf1SIpA0E0

Is this something AGM wants?

commy2 commented 9 years ago

Pretty cool, but the animation makes it look weird. I wouldn't break glass with my hands...

commy2 commented 9 years ago

I like this. v0.95?

JinougaF commented 9 years ago

I don't know anything about modding,but if someone have already made a function to break the glass without fire weapons,would it be easy to just change the animation?

jonpas commented 9 years ago

Yes, if a suitable animation is found.

JinougaF commented 9 years ago

How about this animation?Use the stock to break windows. http://i1371.photobucket.com/albums/ag307/FrontJinouga/arma3_2014_11_05_14_32_28_764_zpsb44b3843.jpg

KoffeinFlummi commented 9 years ago

Is that animation in the game already? If so, what is it called?

JinougaF commented 9 years ago

It's an animation from MOCAP melee mod,here's the link:http://makearmanotwar.com/entry/aZDNVtbCpA

commy2 commented 9 years ago

I'll add this functionality once we have an animation for it.

Dorak commented 9 years ago

This feature was already requested in the said MOCAP mod.

http://109.120.135.75:8080/redmine/issues/4

Maybe you can ask the author to use his animation, since you already have the script.

Cheers.

PabstMirror commented 9 years ago

Code above updated again.

Testing in MP revealed some weird behavior, houses on the map (from the wrp) are local to everyone apparently. Houses manually placed (from the sqm) are local just to the server.

Doing setHitPointDamage only had local effects on map houses. It also wasn't syncing up with JIPs. Both fixed with AGM_Core_fnc_execPersistentFnc.

MOCAP is APA-Share Alike. I'll try and get a hold of the author and see if he would be ok with trading code for animation.

commy2 commented 9 years ago

https://community.bistudio.com/wiki/setHitPointDamage

setHitPointDamage requires the object to be local, but you can't use: [any ,"any", _house] call AGM_Core_fnc_execRemote; , because all map objects are streamed. That means they exist seperately on every machine that has an nearby unit (inside the view distance) and the server.

Every time you use AGM_Core_fnc_execPersistentFnc you'll pile up functions that will be executed upon JIP. Maybe you can avoid that by changing the paramters of AGM_Core_fnc_execRemote.

What happens if you use: [any ,"any", 1] call AGM_Core_fnc_execRemote; or [any ,"any", 2] call AGM_Core_fnc_execRemote; instead?

1 should execute it on the server, while 2 should execute it on every machine (including the server and the caller). Maybe one of those is enough.

PabstMirror commented 9 years ago

With AGM_Core_fnc_execRemote: 1 - only the server sees the glass break 2- works fine initially, but when someone JIPs in they don't see any glass broken

So I think we need persistent calls for JIPs. I see this as being lighly used, but theresn't nothing stopping someone from punching 100 windows and the persistent publicVariable will grow large.

Had an Idea to use physx to break the windows:

class CfgAmmo {
    class BulletBase ;
    class WindowPopper: BulletBase  {
        hit = 50;
        timeToLive = 0.05;  //40 M/S * 0.05 sec should be about 2 meters max
    };
};
xx = "WindowPopper" createVehicle (getpos player);
_position0 = positionCameraToWorld [0, 0, 0.25];
_position1 = positionCameraToWorld [0, 0, 1.25];

xx setPos _position0;
_vel = _position1 vectorDiff _position0;
_vel = _vel vectorMultiply 40;

xx setVelocity _vel;

But it looks like BIS doesn't synchronize windows very will for jips. Only about half of the shot up windows were broken when reconnecting. Even when shooting 'normal' bullets from a gun.

nicolasbadano commented 9 years ago

But it looks like BIS doesn't synchronize windows very will for jips

If that's the case, I think there's no reason to take the trouble ourselves. I would suggest using [any ,"any", 2] call AGM_Core_fnc_execRemote; and calling it a day.

commy2 commented 9 years ago

^ I agree