Raised This Month: $51 Target: $400
 12% 

Solved How do I set a client's buttons?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: This Realm of Existence
Old 07-02-2021 , 00:51   How do I set a client's buttons?
Reply With Quote #1

So I did some looking around on this topic, and I eventually found this helpful thread. I followed Powerlord's suggestion, and I wound up with the following code:

If you're curious, IsValidMulti is a custom stock that checks if a client is valid, as well as if they meet various conditions depending on what's passed to it. In this case, I use it to make sure the possessed player is alive, and to make sure the possessor is both alive and a boss (this is meant as part of a Freak Fortress ability pack).
Code:
public Action:possessed(client) //PreThink hook, used to set the client's buttons each frame.
{
	if (IsValidMulti(client, true, true, false) && IsValidMulti(possession_Possessor[client]) && FF2_HasAbility(FF2_GetBossIndex(possession_Possessor[client]), SPOOK, POSSESSION))
	{
		new buttons = GetClientButtons(possession_Possessor[client]); //Grab the buttons of whoever is controlling this player
		SetClientButtons(client, buttons); //Set the possessed player's buttons in accordance with the above
	}
}

public void SetClientButtons(int client, int buttons) //Borrowed from entity_prop_stocks and modified
{
	if (IsValidClient(client))
	{
		char datamap[32];
		GameData gc = new GameData("core.games");
		bool exists = gc.GetKeyValue("m_nButtons", datamap, sizeof(datamap));
		delete gc;

		if (!exists)
		{
			strcopy(datamap, sizeof(datamap), "m_nButtons");
		}

		SetEntProp(client, Prop_Data, datamap, buttons);
	}
}
The code is successful in letting me control when the possessed player shoots or uses alt-fire, but it doesn't do anything else. Does anyone have any ideas?
__________________
Professional retard. I might borrow some code, but I always try to give credit when I do! If you've noticed I've borrowed some of your code, and you have a problem with that, please add me on Steam and let me know so I can correct the problem as soon as possible!

Last edited by LordHotPocketHomicide; 07-07-2021 at 23:17.
LordHotPocketHomicide is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 07-02-2021 , 01:27   Re: How do I set a client's buttons?
Reply With Quote #2

Would suggest doing "static GameData gc" and checking if "gc != null" before reading the gamedata, especially if this stock is being used over and over.

Anyway, have a look at "OnPlayerRunCmd" and set client buttons there? That should give full control I think.
__________________
Silvers is offline
LordHotPocketHomicide
Member
Join Date: Aug 2016
Location: This Realm of Existence
Old 07-02-2021 , 23:31   Re: How do I set a client's buttons?
Reply With Quote #3

Quote:
Originally Posted by Silvers View Post
Would suggest doing "static GameData gc" and checking if "gc != null" before reading the gamedata, especially if this stock is being used over and over.

Anyway, have a look at "OnPlayerRunCmd" and set client buttons there? That should give full control I think.
Thanks, man! Turns out I was already using OnPlayerRunCmd, I just thought it wasn't working; turns out my validity checks were wrong, so it wasn't doing anything. Anyway, I fixed up the validity checks and added the following:

Code:
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3])
{	
	if (IsValidMulti(client, true, true, false) && IsValidMulti(possession_Possessor[client])) //If the client running the command is possessed, replace their buttons with the possessor's.
	{
		buttons = GetClientButtons(possession_Possessor[client]);
		CPrintToChatAll("{purple}Attempting to set %N's buttons to that of %N...", client, possession_Possessor[client]);
		return Plugin_Changed;
	}
	else if (IsValidMulti(client) && IsValidMulti(possession_Host[client], true, true, false)) //If the client running the command is a boss using this ability, force their inputs on their "host" (player they are possessing).
	{
		CPrintToChatAll("{purple}Attempting to force %N's buttons on %N...", client, possession_Host[client]);
		SetClientButtons(possession_Host[client], buttons);
	}
}
I also went ahead and removed the PreThink hook, then fixed up SetClientButtons as you suggested. The result was an improvement: in addition to controlling when the host fires or uses alt-fire, it now allows the possessor to control when their host jumps, crouches, or uses their special attack, though there is a small delay. However, it doesn't allow the possessor to control the victim's movement or control when the victim switches weapons, which sort of renders the whole thing useless. I was thinking I could probably do some manual movement control using velocity, then mess around with m_hActiveWeapon to fix the weapon swap issue, but I feel like this would be somewhat hacky and would look/feel weird in-game. Any ideas?
__________________
Professional retard. I might borrow some code, but I always try to give credit when I do! If you've noticed I've borrowed some of your code, and you have a problem with that, please add me on Steam and let me know so I can correct the problem as soon as possible!
LordHotPocketHomicide is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 07-03-2021 , 07:23   Re: How do I set a client's buttons?
Reply With Quote #4

AFAIK you can't detect some buttons with these fuctions, like pressing 1 2 3 4 or Q to swap weapons
In this case, you would have to check the active weapon and its slot and force it on the "possessed" client
__________________
Marttt is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:59.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode