Weapon Hud and Secondary Weapon ... an FYI.

ShootingBlanks

OpenDayZ Guru!
Someone asked for a script they saw on another server where the rifle, pistol and bandages were displayed on the bottom of the screen and could be used by pressing 1,2,3 keys. Actually there is a fourth display item for your "backpack weapon" but I didnt put the code for that yet. So you will be able to switch from rifle, pistol, second rifle with just a keypress.

Anyways ... the FYI that I just wanted to put out here was that for quite a while i could not get the player to switch to the pistol. I was using player selectweapon (primaryweapon player) to switch to rifle which works. But player selectweapon (secondaryweapon player) did not switch to players pistol. I did some debugging and FINALLY realized that the pistol is NOT the secondaryweapon ... Rocket launchers are. I didnt see anything on the wiki about that and there is apparently no direct way to switch to the pistol.
this is how I switched to the pistol. I lifted this from the Suicide script.
Code:
_handgun ="";{if((getNumber (configFile >> "CfgWeapons" >> (_x) >> "type")) == 2) then {_handgun = _x;};}foreach weapons player;player selectweapon _handgun;

I am uploading the code here as it is currently. You can change the options to whatever you want and there is an empty slot to add in something else (backpack weapon etc).

In this video, I have a shotgun, G17 and bandage. I press #3 to bandage and that fades out. then go over to case and pickup the makarov and the G17 fades out and is replaced by the makarov.

DESCRIPTION.EXT
I did not #include the defines.hpp in my file because i had rsctext already defined in description.ext. Otherwise you can #include "defines.hpp" above the rsctitles.
Code:
//*****************************WEAPONHUD******************************************

class RscTitles {
    #include "scripts\weaponHud.hpp"
    };
//*********************************************************************************
};

INIT.SQF
runs on client only.
Code:
if (!isserver) then {
    //**************************************WEAPONHUD ***********************************
    execvm "scripts\weaponHud.sqf";
    //**********************************************************************************
};

WEAPONHUD.SQF
executed from init.sqf. runs constantly and updates the display
Code:
disableserialization;
_layer = 100;
while {true} do {
sleep 2.5;
if (_layer == 100) then {_layer = 101;} else { _layer = 100;};
_layer cutrsc ["weaponHud","Plain",1];
};

WEAPONHUD.HPP
http://pastebin.com/VMN6re5P
The actual display resource. When this is "loaded" it displays the rifle, pistol and bandage. So every time the rsc is reloaded, it updates the current weapons. This gives the nice fade effect from one weapon to another.

DAYZ_SPACEINTERRUPT.SQF
Add this just below the check for all the keypresses block. Keys are 1,2,3,4
Code:
//**********************************WEAPON HUD KEYS ***********************************
if (_dikCode == 0x02) then {player selectWeapon (primaryWeapon player);};
if (_dikCode == 0x03) then { _handgun ="";{if((getNumber (configFile >> "CfgWeapons" >> (_x) >> "type")) == 2) then {_handgun = _x;};}foreach weapons player;player selectweapon _handgun;};
if (_dikCode == 0x04) then {[0,0,0,[player]] execVM "\z\addons\dayz_code\medical\bandage.sqf";
    };
if (_dikCode == 0x05) then { };
//**************************************************************************************

DEFINES.HPP
http://pastebin.com/cYAkgNBa
This is iffy. You might need this, you might not. Depends on what is already defined in your other scripts. This is just the generic defines, nothing special here. If you already have them defined .. good, ignore this
 
Last edited:
image site wont open. Try using real image hosts like sharex with dropbox/gdrive.
chrome_2016-11-19_14-06-42.png
 
Back
Top