Binding new Keys that run clientside functions. Created 7 months ago2020-01-21 15:36:53 UTC by abbadon abbadon

Created 7 months ago2020-01-21 15:36:53 UTC by abbadon abbadon

Posted 7 months ago2020-01-21 15:36:53 UTC Post #343665
I am studying this tutorial trying to understand how to make that, when a impulse command is activated a function that is in the clientside part (cl.dll) runs.

Binding New keys TUT

But I cannot find a good solution for it, although I know that the weapon code is shared between client and server projects, overall if I try to use the function I want into the "impulse" cases part in the server side.

I DON´T know how to do it.
If there are any examples of that, please tell me where they are to study them so I can implement the method.
Posted 7 months ago2020-01-22 16:47:03 UTC Post #343672
So you want to make a new key, which will basically do something completely clientside, right?
That tutorial shows you how to do things on the serverside. It is using client commands to do the job.

When you bind a key, like "firemode", e.g. bind x firemode, and then you press that key, it will send a client command, which will go from the client to the serverside.

The serverside handles it all in ClientCommand()
User posted image
You should know that pcmd is the string, which you are gonna compare, for example if pcmd's contents are equal to "firemode".
However, you're looking at the wrong place.

If you want to do things ENTIRELY on the clientside, you can easily do everything there. Just look at input.cpp :D
User posted image
Inside InitInput(), you can connect commands to an existing function on the clientside.
Here are several examples:
User posted image
However, in order to make any use of this, I gotta ask you, what are you exactly trying to do with a new keybind? Is it toggling a weapon fire mode, or is it meant to do something else?
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-22 20:50:09 UTC Post #343674
It is supposed to use this two functions:

ShowScope ();
HideScope();

That is, the HUD overlay shown OVER the player HUD.
caption textcaption text
Is the frame rectangle with the letters, the space for the radar, etc. When I hide the HUD (HIDEHUD_ALL) the frame persists, and the two functions that create and erase the frame are those two.
Posted 7 months ago2020-01-22 21:22:14 UTC Post #343675
Hmm. This might be a bit more complicated since we gotta toggle a button. I'll see a bit more about this tomorrow.

But either way, input.cpp is the right place for this stuff and that's what I know for sure.
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-22 21:28:34 UTC Post #343676
I did the duck part for the SIEGE position!!, the problem is that it was applied to IN_ keys, so I can´t figure how to do it for commands like "ShowScope" or "HideScope" as the impulse commnads do in the server side part:
	case 102:
       CLIENT_PRINTF( ENT(pev), print_console, "Radar System OFF \n" );
       EMIT_SOUND(ENT(pev), CHAN_VOICE, "player/radaroff.wav", 1, ATTN_NORM);
       radar_on = 0;
       MESSAGE_BEGIN( MSG_ONE, gmsgRadar, NULL, pev );
       WRITE_BYTE(0);
       MESSAGE_END();
       break;
Any material you´ll need just ask. Thank you so much Admer. :)
Posted 7 months ago2020-01-23 10:11:11 UTC Post #343680
Done!! I have do some testings and discovered that I don´t need the IN_ whatever part, just create the command inside the client part and call the "showhud" part inside the code that handles the toggle mechanism. Now it works very well!!, pity that I don´t know how to put it in the kb_act.lst file so I can execute the impulse command that disables the HUD (HIDEHUD_ALL) and the command "showhud" at the same time... I mean, bind ONE key for two commands, of course. :crowbar:
Posted 7 months ago2020-01-23 10:30:09 UTC Post #343681
You don't have to bind one key to call both showhud and impulse 102.
Instead, on the clientside, inside showhud's function, you can do something like EngineClientCmd( "impulse 102" ). Dunno if it's gonna exactly work, but it could be worth a try.

Alternatively, you can do the CLIENT_PRINTF part and the sound emitting part both on the clientside, unless you really need it on the serverside.

If the EngineClientCmd part doesn't work, we can hack it.
Call EngineClientCmd( "showhudsrv" ), and in the ClientCommands function in client.cpp, add an else if line where you'll compare pcmd to "showhudsrv", and inside of that, you're gonna change the player's pev->impulse to 102. ;)
It's a bit ugly, but, there's always a workaround for everything.
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-23 10:41:30 UTC Post #343682
HOW I DO IT

AKA: the absolute dummies method!! :nya:

NOTE: All credit must go to Sluggo the author of the original tutorial of which I commit the heresy of modifying it in the authentic Abbadon´s Clumsy Coding style!! :crowbar:

In your CLIENT workspace just do this for creating toggle keys:

In hud.cpp

Under
#include "vgui_scorepanel.h"
Put
bool g_bShowHudToggle;// Or whatever key you want
Inside
//DECLARE_MESSAGE(m_Logo, Logo)
int __MsgFunc_ResetHUD(const char *pszName, int iSize, void *pbuf)
{
return gHUD.MsgFunc_ResetHUD(pszName, iSize, pbuf );
Put
g_bShowHudToggle = false;
Inside
// This is called every time the DLL is loaded
void CHud :: Init( void )
{
Put
g_bShowHudToggle = false; 
Now in input.cpp

Under
extern int g_iAlive;
Put
extern bool g_bShowHudToggle;
Under
kbutton_t	in_graph;  // Display the netgraph
Put
kbutton_t   in_showhud;
Under
void IN_DuckUp(void) {KeyUp(&in_duck);}
Put
void IN_ShowHudToggle( void ) {g_bShowHudToggle = !g_bShowHudToggle;}
Now into
int CL_ButtonBits( int bResetState )
{
Put
//=============================
	if ( g_bShowHudToggle )
	{
	 Yourstuff here...
	}
//==============================
And into
void InitInput (void)
{
Put
gEngfuncs.pfnAddCommand ( "showhud", IN_ShowHudToggle);
Probably into both input.cpp and hud.cpp you must put...
#include "vgui_TeamFortressViewport.h"
...because I cannot remember if, because I add the "showhud" stuff there (the function that shows and hides the Combat HUD), the compiler needs it to build the client.dll.

Now in your kb_act.lst file into the yourmod\gfx\shell folder of your mod just add (I am using my code here as an example):
"showhud"				"Combat Screen Reticle CSR ON"
I hope that it works for you too. :glad:
Posted 7 months ago2020-01-23 15:14:24 UTC Post #343686
I will try your method for the bind keys!. Thanks Admer! :P
Done...with some issues, but it works!!, BTW: How can I do the emitting sound in the client part? (and, BTW, the "monster following another monster" thingy forgotten ages ago, I swear I tried all but with no luck, haha!!!)

thread here...
Posted 7 months ago2020-01-24 00:01:40 UTC Post #343688
Sound emitting is done via PlaySound(), if I remember correctly, you can find examples of its usage in ev_hldm.cpp
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-24 00:29:47 UTC Post #343689
Oh. I found tons of errors when I try to use sounds...my bad coding again.
Posted 7 months ago2020-01-25 10:46:41 UTC Post #343690
Compile time error or game crashes?

If the game crashes when playing the sound, you gotta precache the sound in ClientPrecache(). :P
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-25 15:26:32 UTC Post #343692
Oh nothing of that, just that I use the:
EMIT_SOUND(ENT(pev), CHAN_VOICE, "player/hudon.wav", 1, ATTN_NORM);
I obtain:
E:\DevZWC20\Elementos Basicos MAYO 2017\Single-Player Source\cl_dll\input.cpp(902) : error C2065: 'EMIT_SOUND' : undeclared identifier
BTW: i need spoonfeeding with the gunners following the trolleys. I have added the Nebuchadnezzar ship to the map, the Ganesha and Caduceus are ready too, I´m rewriting the manual, the mod is finished except for that part. I really can left that undone, I did it with the trolley code ages ago in 2008, but it could be cool if that part could be added before I can consider dinished the mod finally. :lol:
Posted 7 months ago2020-01-26 11:48:10 UTC Post #343694
EMIT_SOUND is for the serverside.

On the clientside, you can use something like this:
gEngfuncs.pEventAPI->EV_PlaySound( idx, origin, CHAN_WEAPON, "weapons/pl_gun3.wav", gEngfuncs.pfnRandomFloat(0.92, 1.0), ATTN_NORM, 0, 98 + gEngfuncs.pfnRandomLong( 0, 3 ) );
Or a much simpler version, which can be found in `cl_util.h`:
inline void PlaySound( char *szSound, float vol ) { gEngfuncs.pfnPlaySoundByName( szSound, vol ); }
Example usage:
PlaySound("common/wpn_moveselect.wav", 1);
As for the gunners following the trolleys, I dunno, how do you exactly mean following them?
Are they in-air, on-ground, or?
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-26 12:16:19 UTC Post #343695
They must get close to the trolley guys, as a bodyguard.
I will try your sound method!!. Thanks for helping me in this last steps!

BTW:
	//======================================
	// Mostrar-Esconder HUD HUD
	//======================================

	if ( g_bShowHudToggle )
	   	{

			gHUD.m_iHideHUDDisplay &= ~ HIDEHUD_WEAPONS;
            gHUD.m_iHideHUDDisplay &= ~ HIDEHUD_HEALTH;
			gHUD.m_iHideHUDDisplay &= ~ HIDEHUD_ALL;
			gHUD.m_iHideHUDDisplay &= ~HIDEHUD_FLASHLIGHT;
			if ( CL_IsThirdPerson ()) { gViewPort->ShowHud1(); gViewPort->HideHud();}
			if ( !CL_IsThirdPerson ()) { gViewPort->ShowHud(); gViewPort->HideHud1();}

			PlaySound("player/hudon.wav", 1);//(c)Admer


		}

		if ( g_bHideHudToggle )
		{
			gHUD.m_iHideHUDDisplay |=  HIDEHUD_WEAPONS;
			gHUD.m_iHideHUDDisplay |=  HIDEHUD_HEALTH;
			gHUD.m_iHideHUDDisplay |=  HIDEHUD_FLASHLIGHT;
			gViewPort->HideHud();//HUD reticle Firstperson
			gViewPort->HideHud1();//HUD reticle Thirdperson

			PlaySound("player/hudoff.wav", 1);//(c)Admer

		}


//=============================
It compiled fine this way!!
Posted 7 months ago2020-01-26 14:07:11 UTC Post #343697
"They must get close to the trolley guys, as a bodyguard."
Still doesn't tell me what exactly the movement is supposed to be.
Is it aerial?
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-26 15:14:44 UTC Post #343698
No. The Gunner guys walk and run, and the trolleys do the same. What I want is that the gunners follow the movement of the trolley guys that also walks and run. Once they spawn, the trolley guys run to "attack" (give ammo) the player, or the bot that has no ammo loaded, and I want the gunners (that spawn at the same time) follow the trolley guy at a given distance, instead of running or standing still engaging combat, I want them to engage combat BUT always keeping distance with the trolley guys, as if they are tied with a beam that has a fixed lenght.
Posted 7 months ago2020-01-26 16:56:43 UTC Post #343699
Hmm.
TBH I don't do HL AI programming just yet, so I can't really help you on that one.
Admer456 Admer456If it ain't broken, don't fox it!
Posted 7 months ago2020-01-26 17:58:54 UTC Post #343700
Don´t you worry. I repeat, that´s s feature that can wait, or maybe it will not be added once I finish this v2.0 of the mod. I have played this morning a full match and find that it is almost done, some little polishment in the health and damage of certain npcs and that´s all the code left I can do. I think it´s time to led Zion Warcry sourcecode have a rest. :)
You must be logged in to post a response.