Named Game of the Year by over 50 publications, Valve's d├ębut title blends action and adventure with award-winning technology to create a frighteningly realistic world where players must think to survive. Also includes an exciting multiplayer mode that allows you to play against friends and enemies around the world.

Post tutorial Report RSS Half-life1 Coding: 4digits on HUD and 9999 ammo on clip

Second part of the tutorial, that includes the modification of the HUD to show 4 digits on ammo, and the modificacion on the client-server message for the weapon magazine.

Posted by on - Intermediate Client Side Coding

first read the first tutorial, as the half of this is the same as the other but over SelAmmo data, is very recomendable to implement it


Start using the "find" function and look for "SelAmmo" in the Entire Solution
in player.cpp we need to edit the info inside the function LinkUserMessages

curweapon1

we need to change that 3 to a -1

curweapon2

then the message information inside CBasePlayer::RemoveAllItems

curweapon3

we change that bye by a short

curweapon4

and at last the message information inside CBasePlayer::Killed

curweapon5

and again

curweapon6

next in the list you should have weapon.cpp
we need to go inside the function CBasePlayerWeapon::UpdateClientData and find

curweapon7

we change that again for a short

curweapon8

and at last we open ammo.cpp
and inside CHudAmmo::MsgFunc_CurWeapon
we find

curweapon9

we change the read_byte to read_short

curweapon91

we that we can have 999 of ammo in the clip of the gun

now lets add more digits to the HUD

first lets opend hud.h and at the top find that constant definition

hud1 1

then we add our new one for the new 4digits HUD

hud2

now open hud_redraw.cpp and go to the very bottom of the file and find
inside the CHud::GetNumWidth and we add this if statment

hud3

in the same function go down find this

hud4

and edit it to look like this

hud5

now open hud_redraw.cpp and find the function CHud :: DrawHudNumber
this function is the one that arrange the numbers in positions in the hud
we need to change this line, this line trys to take the third digit of the number and put the correct HUD number, but as we are going to
add a 4th digit for the numbers we need to change this line

hud6

now this will make the third digit to not have a problem when we add the 4th digit

hud7

now we add the fourth digit on top

hud8

inside the same function in the bottom we find this chunk of code for the spacing of the digits

hud9

we need to ADD another one for our 4th digit(WE DO NOT REMOVE ANYTHING HERE)

hud91

done with hud_redraw.cpp now we can use 4th digits on hud(for health,armor, ammo, and weapona ammo)

at this point I recommend you again to have implemented the first tutorial for increasing the AMMO type capacity

so we open ammo.cpp, find the function int CHudAmmo::Draw(float flTime)
inside of it we need to find all the x = gHUD.DrawHudNumber() and change one of the variable inside of this

hud92

we need to change the old DHN_3DIGITS to out new DHN_4DIGITS

hud93

we do the same with this 2 more inside the function (look for the valve comment "GL Seems to need this" if you are confuse)

hud94

we change those to this

hud95

and one more inside if ((pw->iAmmo2Type != 0) && (gWR.CountAmmo(pw->iAmmo2Type) > 0)) {

hud96

now with that change you can have up to 9999 of ammo in the weapon magazine and be displayed on HUD + all the HUD stuff that use numbers
(armor,health) can be modified to use 4digits

one more thing if you did the first tutorial and now this you should change from player.cpp a line from the first tutorial
inside CBasePlayer::SendAmmoUpdate
the line WRITE_SHORT ( max( min( m_rgAmmo[i], 999 ), 0 ) );
should be even extended to have 9999 as max number of ammo sent to the client

hud97

then you can go to weapon.h and modify the capacity of ammo and magazine

hud98

and if everything goes well you can have this

20160417083009 1

I dont think we need that much ammo to end half-life1

Comments
Gunship_Mark_II Online
Gunship_Mark_II

Beautiful tutorial, very well written and nicely illustrated. I'm sure that a lot of people find it very useful, thank you for your work!

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

well thanks!, I felt that the other tutorial was kind of incomplete without the hud

Reply Good karma+1 vote
FanProgrammer
FanProgrammer

Very nice

Reply Good karma Bad karma+1 vote
zenav
zenav

waht this program to open this file

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

visual studio 2008

Reply Good karma+1 vote
ghostboyed
ghostboyed

You can also use Notepad++

Reply Good karma Bad karma+1 vote
ghostboyed
ghostboyed

When im compiling client dll it gives me error : Could not load library */valve/client.dll Help plz

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

first of all you shouldnt have in your proyect the load of .dll because thats what you are trying to compile, so it could be that the directory of the sdk is wrong for some reason, be sure that your sdk is compatible with your compiling program, before following any tutorial you should try to compile a clean SDK without modifications

Reply Good karma+1 vote
ghostboyed
ghostboyed

Error: User Msg AmmoX 4 bytes written, expected 2
and when im changing ammox event from 2 to -1 still no work (then ammo is 0 but u can reload)

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

did you implement the first tutorial? Moddb.com
Look in the code for "ammox"
in player.cpp you need to change the reg_user_msg("ammox",2) to a (ammox,-1)
then in function SendAmmoUpdate, you need to change
WRITE_BYTE( i );
WRITE_BYTE( max( min( m_rgAmmo[i], 254 ), 0 ) );
to
WRITE_SHORT ( i );
WRITE_SHORT ( max( min( m_rgAmmo[i], 9999 ), 0 ) );
and then in the client side, on ammo.cpp fin this function
int CHudAmmo::MsgFunc_AmmoX(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ( pbuf, iSize );

int iIndex = READ_BYTE();
int iCount = READ_BYTE();

gWR.SetAmmo( iIndex, abs(iCount) );

return 1;
}
and change
int iIndex = READ_SHORT();
int iCount = READ_SHORT();

It should work I build it up on a clean SDK

Reply Good karma+1 vote
Guest
Guest

hi sir do you know where can i change the weapon firing speed i know it's possible i found a mod that had the mp5 and some other weapons fire stupidly fast

Reply Good karma Bad karma0 votes
Foxtrop Author
Foxtrop

weapons use diferent methods but the majority as the mp5 uses

m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.1;

where +0.1 is the time between shots, a smaller number a faster shoot a bigger number a slower

Reply Good karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

ghostboyed
ghostboyed

Is There Difference about setting MESSAGE Size To Exact one or -1 ?
Will It Affect Performance ?

REG_USER_MSG( szMessage , Size )

Reply Good karma Bad karma+1 vote
Foxtrop Author
Foxtrop

as far I understand -1 means that the size is variable, it would be better to know how much data you want to send to know the right size, in the case of the message "curweapon" we changed the size from 3 to -1, but if we use size of 4 it should work too!
as the message sends 3 data package
write_byte=size 1
write_byte=size 1
write_short= size 2
I dont test it, but it should work
these message would definitly had some impact on online games as this are data between client and servers, how much will affect performance I dont know

Reply Good karma+1 vote
Guest
Guest

This comment is currently awaiting admin approval, join now to view.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Half-Life
Platforms
Windows, Mac, Linux, PS2
Developer
Valve
Engine
GoldSource
Contact
Send Message
Release date
Game watch
Follow
Purchase
Tutorial
Browse
Tutorials
Report
Report
Share
Related Games
Half-Life
Half-Life First Person Shooter
Related Engines
GoldSource
GoldSource Commercial
Related Groups
Sierra Entertainment
Sierra Entertainment Developer & Publisher
Valve
Valve Developer & Publisher