Always In combat - Works well with discobot

Gorsy

Valued Member!
Ok guys so I have the anti combat log bot installed that spawns a bot in a players place when they combat log, Now the problem I had was the fact the combat timer is so buggy, You shoot from far away the player you shoot at is not in combat etc.

So after hunting around for hours and hours, someone finally gave me a clue and I found this code.

Ive written it up on here as it is not on open dayz but this is not my code, All work and credits goto Daimyo - with a few small edits of my own

Thanks to tortured for the error fix

Copy and paste the following code and save it as activeCombat.sqf

Code:
private["_dialog","_dangerNear","_dangerClosest","_cnt","_isInCombat","_playerCombat","_inVehicle"];
disableserialization;
_cnt = 0;
while {true} do {
    _playerCombat = player;
    _isInCombat = _playerCombat getVariable["startcombattimer",0];
    _inVehicle = (vehicle player != player);
    _dangerNear = (getPosATL player) nearEntities [["zZombie_Base","CAManBase"],35];
    _dialog = findDisplay 106;
if ((_inVehicle || speed player != 0) && alive player) then {
    if ((isPlayer _playerCombat) && _isInCombat == 0) then {
        _playerCombat setVariable["startcombattimer", 1, true];
        //diag_log("Now in Combat (Player): " + name _playerCombat);
    };
};
if ( !(isNull _dialog) ) then {
_playerCombat setVariable["startcombattimer", 1, true];
};
//Make sure player is not detecting self
if (player in _dangerNear) then {
_dangerNear set [0, player];
_dangerNear = _dangerNear - [player];
};
//Any zombies, players near 15 meters?
if (count _dangerNear > 0) then {
    {
    _dangerClosest = _dangerNear select _cnt;
    if (_dangerClosest distance player < 15) then {_playerCombat setVariable["startcombattimer", 1, true];};
    _cnt = _cnt + 1;
    if (_cnt >= (count _dangerNear)) then {_cnt = 0};
    } foreach _dangerNear;
};
sleep 1;
};

Add the following line to your init.sqf file
(Change tweaks to the file where you are placing the above coding)
_null = [] execVM "tweaks\activeCombat.sqf";
inside the !isDedicated area

Code:
if (!isDedicated) then {
    0 fadeSound 0;
    0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED", 60];
 
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death; _nul = [] execVM "fixes\compile\playerspawn.sqf";}];
    _playerMonitor =    [] execVM "fixes\system\player_monitor.sqf";
        waitUntil { alive Player };
        waituntil { !(IsNull (findDisplay 46)) };
_null = [] execVM "fixes\activeCombat.sqf";

Optional
You can also edit the Logout message so they have to stand still in your player_onPause.sqf
case (player getVariable["combattimeout", 30] >= time) : {
_btnAbort ctrlEnable false;
cutText ["You Must Stand Still for 30 seconds to log out!", "PLAIN DOWN"];
};
UPDATE

Fixing Zombie Proximity

_dangerNear = (getPosATL player) nearEntities [["zZombie_Base","CAManBase"],35];

find the section above and chage the 35 to 1, this will make it check for zombies within 1 meter rather than 35


Enjoy, This works really well with the Anti Combat logging bot, as players are locked in combat. So even when a sniper shoots from far away the person cannot abort
-----------
And Check out this post to get the Bot to spawn in when players try to combat log

http://opendayz.net/threads/anti-combat-logging-discobot.8777/
 
Back
Top