Punch/Melee option

SmokeyMeadow

Well-Known Member
Hi. I'm sharing a script I've been working on that will allow players to punch or use their rifle as a melee weapon. This is something I always felt was lacking from the Day Z experience. Now players can stealth kill, interrogate, and generally survive without weapons/ammo. It works on survivors, zeds and animals. So far, landing a punch is difficult. The zombies run around like crazy and it's hard to get a cursortarget to hit them. I did manage to kill one zombie bare handed. I have no one to help test this with, so I would appreciate anyone's input on how to make it better.

This part goes in fn_selfactions:

Code:
//PUNCH START

if(cursorTarget isKindOf "Man" and _canDo && (player distance cursorTarget < 3)) then {
    punchTimeM = true;
} else {
    punchTimeM  = false;
};
if (punchTimeM) then {
    if (s_player_punchM < 0) then {
    s_player_punchM = player addAction [("<t color=""#0096ff"">" + ("Strike!") +"</t>"),"scripts\punchM.sqs","",5,false,true,"",""];
    };
} else {
   player removeAction s_player_punchM;
    s_player_punchM = -1;
};

//PUNCH END

Then, put this in your scripts folder.

This is an adaptation of a script I found on Armaholic. Ideally I would like to have it in sqf instead of sqs, since I have no idea how to code for sqs. Luckily it just kind of works. Like I said earlier, consider it a WIP. Anyone with ideas on how to improve it, please feel free to chime in. For now, I left it so you can punch dead bodies. I suppose a next step would be to add an !_isalive or something in the init.
 
now that is a brilliant idea. Scrolling always takes so long it makes the option difficult to use.
i didnt look at the script here, the one i had used before, knocked the player down or uncinscious the first blow and killed on the second. i think just knocking down/unconscious is better for melee attack
 
now that is a brilliant idea. Scrolling always takes so long it makes the option difficult to use.
i didnt look at the script here, the one i had used before, knocked the player down or uncinscious the first blow and killed on the second. i think just knocking down/unconscious is better for melee attack

Ideally, I would have it knock them unconscious with a random chance. There are actually two damage variables in this script, one for unarmed and one for holding a primary weapon. Unarmed takes 4 hits to kill, with a weapon it takes 2. This is all unmodified code from Armaholic. Like I said, I don't know a lot about sqs or I would have changed things up a bit. I have a punch sfx, but I'm not sure how easy it would be to sync with the actual action, or even how to get it to call in sqs. I'm somewhat of a novice.

This would be a cool thing to attach to a button instead of having to scroll

I agree. That's what i'm working on, but I've not seen many scripts that assign a hotkey to the action, so I don't have a good frame of reference. Most scriptors, myself included, opt for action menu activation for nearly everything. I'm doing some research on how to proceed.
 
Ideally, I would have it knock them unconscious with a random chance. There are actually two damage variables in this script, one for unarmed and one for holding a primary weapon. Unarmed takes 4 hits to kill, with a weapon it takes 2. This is all unmodified code from Armaholic. Like I said, I don't know a lot about sqs or I would have changed things up a bit. I have a punch sfx, but I'm not sure how easy it would be to sync with the actual action, or even how to get it to call in sqs. I'm somewhat of a novice.



I agree. That's what i'm working on, but I've not seen many scripts that assign a hotkey to the action, so I don't have a good frame of reference. Most scriptors, myself included, opt for action menu activation for nearly everything. I'm doing some research on how to proceed.
It would be the same thing for toggling debug, just instead of activating or turning off the debug monitor it would knock a bitch out :p
 
Hi. I'm sharing a script I've been working on that will allow players to punch or use their rifle as a melee weapon. This is something I always felt was lacking from the Day Z experience. Now players can stealth kill, interrogate, and generally survive without weapons/ammo. It works on survivors, zeds and animals. So far, landing a punch is difficult. The zombies run around like crazy and it's hard to get a cursortarget to hit them. I did manage to kill one zombie bare handed. I have no one to help test this with, so I would appreciate anyone's input on how to make it better.

This part goes in fn_selfactions:

Code:
//PUNCH START

if(cursorTarget isKindOf "Man" and _canDo && (player distance cursorTarget < 3)) then {
    punchTimeM = true;
} else {
    punchTimeM  = false;
};
if (punchTimeM) then {
    if (s_player_punchM < 0) then {
    s_player_punchM = player addAction [("<t color=""#0096ff"">" + ("Strike!") +"</t>"),"scripts\punchM.sqs","",5,false,true,"",""];
    };
} else {
   player removeAction s_player_punchM;
    s_player_punchM = -1;
};

//PUNCH END

Then, put this in your scripts folder.

This is an adaptation of a script I found on Armaholic. Ideally I would like to have it in sqf instead of sqs, since I have no idea how to code for sqs. Luckily it just kind of works. Like I said earlier, consider it a WIP. Anyone with ideas on how to improve it, please feel free to chime in. For now, I left it so you can punch dead bodies. I suppose a next step would be to add an !_isalive or something in the init.
mind if i try converting this to SQF and making it a hot key :p ??

this is what i use to convert (takes practice and time :)
https://community.bistudio.com/wiki/SQS_to_SQF_conversion
 
ok had acrack at converting to SQF heres what i came up with so far, gonna test it soon
(not even sure syntax is all correct yet :p )
Code:
private ["_onLadder","_canDo","_cursorTarget","_typeOfCursorTarget","_isTarget","_isTrader","_man","_pos","_pos2","_angle","_man_damag"];

_onLadder =        (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_canDo = (!r_drag_sqf && !r_player_unconscious && !_onLadder);
_cursorTarget = cursorTarget;
    // get typeof cursortarget once
_typeOfCursorTarget = typeOf _cursorTarget;
_isTarget = (_cursorTarget isKindOf "Man" || _cursorTarget isKindOf "Animal" || _cursorTarget isKindOf "zZombie_base");
_isTrader = _typeOfCursorTarget in ["Hooker1","Hooker2","RU_Functionary1","RU_Citizen3","Rocker4","Profiteer4","Rita_Ensler_EP1","CIV_EuroMan01_EP1","CIV_EuroMan02_EP1","TK_GUE_Soldier_5_EP1","GUE_Soldier_MG","Worker2","Worker3","Woodlander1","UN_CDF_Soldier_Pilot_EP1","RU_WorkWoman1","Dr_Annie_Baker_EP1","RU_Citizen4","RU_WorkWoman5","RU_Citizen1","RU_Villager3","TK_CIV_Takistani04_EP1","Pilot_EP1","RU_Profiteer4","Woodlander3","Dr_Hladik_EP1","Doctor","HouseWife1","GUE_Woodlander2"];


_man = nearestObjects [ player , ["Man"], 2];

_pos = getpos player;
_pos2 = getpos _man;
_angle =(((_pos2 select 0) - (_pos select 0)) atan2 ((_pos2 select 1)-(_pos select 1)));
player setdir _angle;

sleep 0.001;
if ( _isTarget && _canDo && !_isTrader && (player distance cursorTarget < 3)) then {
    if (primaryWeapon player == "" && secondaryWeapon player == "") then {
        player switchmove "AmelPercMstpSnonWnonDnon_amaterUder3";
        sleep 1;
        _man_damag = getdammage _man;
        _man_damag = _man_damag + 0.6;
            if (getdammage _man < 0.5) then {
                _man switchmove "AmelPercMstpSnonWnonDnon_zasah6hlava";
                // playSound "Sound1" //play punch sound
                _man setdamage _man_damag;
                _man dotarget player;
                _man dofire player;
                sleep 2.2;
                exitwith{};
            };
    }else{
        player switchmove "AmelPercMstpSlowWrflDnon_StrokeGun";
        sleep 1;
        _man_damag = getdammage _man;
        _man_damag = _man_damag + 0.6;
            if (getdammage _man < 0.5) then {
                _man switchmove "AmelPercMstpSnonWnonDnon_zasah6hlava";
                // playSound "Sound1" //play punch sound
                _man setdamage _man_damag;
                _man dotarget player;
                _man dofire player;
                sleep 2.2;
                exitwith{};
            };
    };
};

EDIT: change script some more
added check to stop punching traders :)
still all untested :p

EDIT 2: i bound the script to the Tkey in dayz_spaceInterrupt using this
Code:
if (_dikCode == 0x14) then {
    execVM "scripts\punch\punch.sqf";
};
firinig up server now to test this all out :)
 
Last edited:
ok had acrack at converting to SQF heres what i came up with so far, gonna test it soon
(not even sure syntax is all correct yet :p )
Code:
private ["_onLadder","_canDo","_cursorTarget","_typeOfCursorTarget","_isTarget","_isTrader","_man","_pos","_pos2","_angle","_man_damag"];

_onLadder =        (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;
_canDo = (!r_drag_sqf && !r_player_unconscious && !_onLadder);
_cursorTarget = cursorTarget;
    // get typeof cursortarget once
_typeOfCursorTarget = typeOf _cursorTarget;
_isTarget = (_cursorTarget isKindOf "Man" || _cursorTarget isKindOf "Animal" || _cursorTarget isKindOf "zZombie_base");
_isTrader = _typeOfCursorTarget in ["Hooker1","Hooker2","RU_Functionary1","RU_Citizen3","Rocker4","Profiteer4","Rita_Ensler_EP1","CIV_EuroMan01_EP1","CIV_EuroMan02_EP1","TK_GUE_Soldier_5_EP1","GUE_Soldier_MG","Worker2","Worker3","Woodlander1","UN_CDF_Soldier_Pilot_EP1","RU_WorkWoman1","Dr_Annie_Baker_EP1","RU_Citizen4","RU_WorkWoman5","RU_Citizen1","RU_Villager3","TK_CIV_Takistani04_EP1","Pilot_EP1","RU_Profiteer4","Woodlander3","Dr_Hladik_EP1","Doctor","HouseWife1","GUE_Woodlander2"];


_man = nearestObjects [ player , ["Man"], 2];

_pos = getpos player;
_pos2 = getpos _man;
_angle =(((_pos2 select 0) - (_pos select 0)) atan2 ((_pos2 select 1)-(_pos select 1)));
player setdir _angle;

sleep 0.001;
if ( _isTarget && _canDo && !_isTrader && (player distance cursorTarget < 3) then {
    if (primaryWeapon player == "" && secondaryWeapon player == "") then {
        player switchmove "AmelPercMstpSnonWnonDnon_amaterUder3";
        sleep 1;
        _man_damag = getdammage _man;
        _man_damag = _man_damag + 0.6;
            if (getdammage _man < 0.5) then {
                _man switchmove "AmelPercMstpSnonWnonDnon_zasah6hlava";
                // playSound "Sound1" //play punch sound
                _man setdamage _man_damag;
                _man dotarget player;
                _man dofire player;
                sleep 2.2;
                exitwith{};
            };
    }else{
        player switchmove "AmelPercMstpSlowWrflDnon_StrokeGun";
        sleep 1;
        _man_damag = getdammage _man;
        _man_damag = _man_damag + 0.6;
            if (getdammage _man < 0.5) then {
                _man switchmove "AmelPercMstpSnonWnonDnon_zasah6hlava";
                // playSound "Sound1" //play punch sound
                _man setdamage _man_damag;
                _man dotarget player;
                _man dofire player;
                sleep 2.2;
                exitwith{};
            };
    };
};

EDIT: change script some more
added check to stop punching traders :)
still all untested :p

EDIT 2: i bound the script to the Tkey in dayz_spaceInterrupt using this
Code:
if (_dikCode == 0x14) then {
    execVM "scripts\punch\punch.sqf";
};
firinig up server now to test this all out :)
Code:
( _isTarget && _canDo && !_isTrader && (player distance cursorTarget < 3)
cmon man you're better than a silly error like that
 
ok had acrack at converting to SQF heres what i came up with so far, gonna test it soon
(not even sure syntax is all correct yet :p )
Thanks for looking into this. I tried your code, but couldn't get it to work on my vanilla 1.8.3 server.
I'll mess around with it more and see if I can get it to initialize.

EDIT 2: i bound the script to the Tkey in dayz_spaceInterrupt using this
Code:
if (_dikCode == 0x14) then {
    execVM "scripts\punch\punch.sqf";
};
I'm not quite clear on where I'm supposed to put this part. Is there a compiles, or fn_selfactions or something? Like I said before, I'm just on the vanilla Day Z.
 
Almost got it!
Thanks for looking into this. I tried your code, but couldn't get it to work on my vanilla 1.8.3 server.
I'll mess around with it more and see if I can get it to initialize.


I'm not quite clear on where I'm supposed to put this part. Is there a compiles, or fn_selfactions or something? Like I said before, I'm just on the vanilla Day Z.

you need to overwrite dayz_spaceInterrupt.sqf ill post how to later tonight
 
Thanks for looking into this. I tried your code, but couldn't get it to work on my vanilla 1.8.3 server.
I'll mess around with it more and see if I can get it to initialize.

I'm not quite clear on where I'm supposed to put this part. Is there a compiles, or fn_selfactions or something? Like I said before, I'm just on the vanilla DayZ.
The 'dayz_spaecInterrupt.sqf' is called in your compiles.sqf.
Code:
    dayz_spaceInterrupt =            compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\dayz_spaceInterrupt.sqf";
In the dayz_spaceInterrupt you want to obviously make it local to your mission file but navigate to the bottom of the file and above '_handled' (Line #192) add
Code:
if (_dikCode == 0x14) then {
    execVM "scripts\punch\punch.sqf";
};
 
Looking at this, it could cause you to punch instead of shoot at close range. I'm going to mess with it tongiht and add the ability to turn off punching from scroll menu
 
Looking at this, it could cause you to punch instead of shoot at close range. I'm going to mess with it tongiht and add the ability to turn off punching from scroll menu
to punch you press T key not sure how you could punch instead of shoot as punch script is only called when you press T , also its buggy and dosnt seem to work right, i dont have time to fix it
 
I misunderstood. Thought it was by just clicking the mouse.

I'll play with it and see if i can make it less buggy. If so, i'll post back.
 
I misunderstood. Thought it was by just clicking the mouse.

I'll play with it and see if i can make it less buggy. If so, i'll post back.
If anything, the player SHOULD be able to click the mouse if he does not have a primary or sidearm out
 
Yeh, I just need to dig around for the dikCode for left mouse click.

Automatically deciding to use the butt of the gun could be a bit tricky. Not sure if there is a command to check if the gun is loaded.
 
Back
Top