PDA

View Full Version : [Solved] [Request] Plugin that binds things without changing player cfg


minimovz
11-25-2020, 04:16
Hello, i need a plugin that executes a console command when someone presses g (drop gun)

example: I need the G key to open a deathmatch gun menu, the console command for the gun menu is sm_guns, without changing the player's configs

Marttt
11-25-2020, 07:27
If I remember well it was blocked by Valve some years ago, unless the client use some modified .dll/.so.
So, not possible. At least in L4D2, all plugins that does "bind" some key it outputs a console error

GsiX
11-25-2020, 07:37
He probably talking about OnPlayerRunCmd() without actually forcing clients to change they key bind. It mean use existing keybind like "G" key.

Marttt
11-25-2020, 07:48
In L4D2 there is no action from pressing "G" if I remember, I saw some plugins dropping pressing "R"(IN_RELOAD)

In this case, as GsiX said, you can't bind a key to the client, but you can use OnPlayerRunCmd to check some keys being pressed by the client (like reload [R], zoom [M3], flashlight [F], use [E]) and do some action based on it.

SSheriFF
11-25-2020, 09:36
Hello, i need a plugin that executes a console command when someone presses g (drop gun)

example: I need the G key to open a deathmatch gun menu, the console command for the gun menu is sm_guns, without changing the player's configs

Try that. Also you didnt mention which game.
#include <cstrike>
public Action CS_OnCSWeaponDrop(int client, int weaponIndex)
{
FakeClientCommand(client, "sm_guns");
}

minimovz
11-25-2020, 14:40
Try that. Also you didnt mention which game.
#include <cstrike>
public Action CS_OnCSWeaponDrop(int client, int weaponIndex)
{
FakeClientCommand(client, "sm_guns");
}

it's for csgo, what if i wanted it to be another key like the buyammo1 ? is there a way to change the CS_OnCSWeaponDrop to actually be a command executed by a bind i choose ?

GsiX
11-25-2020, 22:51
I don't responsible for any bug introduce during/after multiple "sm_guns" command call.
You gun plugins should check not to open menu if it already open.

#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#pragma newdecls required

/*
IN_ATTACK
IN_JUMP
IN_DUCK
IN_FORWARD
IN_BACK
IN_USE
IN_CANCEL
IN_LEFT
IN_RIGHT
IN_MOVELEFT
IN_MOVERIGHT
IN_ATTACK2
IN_RUN
IN_RELOAD
IN_ALT1
IN_ALT2
IN_SCORE
IN_SPEED
IN_WALK
IN_ZOOM
IN_WEAPON1
IN_WEAPON2
IN_BULLRUSH
IN_GRENADE1
IN_GRENADE2
IN_ATTACK3
*/

bool g_bBtnInterval[MAXPLAYERS+1];

public Plugin myinfo =
{
name = "PluginThatBindsThingsWithoutChangingPlayerCfg",
author = "minimovz",
description = "Plugin that binds things without changing player cfg or without actually make a phone call and tell player to bind they own key or you shoot them like for real.. seriously..",
version = "0.0",
url = ""
}

public void OnPluginStart()
{
// nothing
}

public void OnClientPostAdminCheck( int client )
{
g_bBtnInterval[client] = false;
}

public Action OnPlayerRunCmd( int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon )
{
if(client == 0 || IsFakeClient(client))
{
return Plugin_Continue;
}

if (( buttons & IN_RELOAD ) && !g_bBtnInterval[client] ) //<< this guy
{
g_bBtnInterval[client] = true;
FakeClientCommand(client, "sm_guns");
CreateTimer( 1.0, Timer_ButtonInterval, GetClientUserId(client));
}
return Plugin_Continue;
}

public Action Timer_ButtonInterval( Handle timer, any clref )
{
int client = GetClientOfUserId( clref );
if( client > 0 && client <= MaxClients && IsClientInGame( client ))
{
g_bBtnInterval[client] = false;
}
}

Edit: Really, this don't make any sense, it just introduce more bug. Just tell everyone bind F11"say /sm_guns" . Call they mobile phone if needed. Call they mom if you have to or just advertise it on motd or chat.

minimovz
11-26-2020, 07:25
Try that. Also you didnt mention which game.
#include <cstrike>
public Action CS_OnCSWeaponDrop(int client, int weaponIndex)
{
FakeClientCommand(client, "sm_guns");
}

didn't work, OnCSWeaponDrop only gets called when the gun is actually dropped i think, the deathmatch plugin doesn't allow the guns to be dropped

minimovz
11-26-2020, 07:39
Ok, i was messing with some things and i was looking through the Weapons & Knives plugin sourcecode that uses the buyammo1 and buyammo2 keybinds to open menus and i tried something and it worked but i don't know if it can causes problem with it triggering the menu on other clients, can someone verify this work only for the client pressing the key ?


public OnPluginStart()
{
RegConsoleCmd("drop", OpenMenu);
}

public Action OpenMenu(int client, int args)
{
FakeClientCommand(client, "sm_guns");
}

GsiX
11-26-2020, 07:41
PrintToChatAll( "%d", buttons);

Place it inside the OnPlayerRunCmd(). What the value when you press "G"..?

I shouldn't ask you to do this without me testing it myself. But it should give you some idea.

Edit:
Ok, i was messing with some things and i was looking through the Weapons & Knives plugin sourcecode that uses the buyammo1 and buyammo2 keybinds to open menus and i tried something and it worked but i don't know if it can causes problem with it triggering the menu on other clients, can someone verify this work only for the client pressing the key ?


public OnPluginStart()
{
RegConsoleCmd("drop", OpenMenu);
}

public Action OpenMenu(int client, int args)
{
FakeClientCommand(client, "sm_guns");
}


They are the same command.. you just put command on top of another command.

Edit2: stop adding post. Just edit the old one.

minimovz
11-26-2020, 07:56
They are the same command.. you just put command on top of another command.



Not really, in csgo the G key is defaulted to the command "drop", this can be triggered in console or pressing the key G, the RegConsoleCmd("drop", OpenMenu) will attach the function OpenMenu to the drop command, and the OpenMenu function fakes a client command sm_guns, effectively adding on to the drop command and without the need for the client to change any config, the only concern i have is with the client thing and the only reason i am concerned with it is that i have no experience with plugin coding other than modifying small things like this, i already tried this code alone in a server and worked for what i want, just have the lingering concern of what said in the before paragraph

GsiX
11-26-2020, 08:38
I notice that and delete my comment. I was reading it wrong as admin command. Almost forgot the console command tho.
If this works for you, it should work for everyone. My concerns is the menu being overwritten multiple times without properly closing it. If it works, it works i guess.

Edit:
when i think this thru, your solution actually is the best.
Don't worry about the menu being leaking. High likely it won't.
I suppose you will get console warning but you won't crash.
Until then enjoy your plugin.

minimovz
11-26-2020, 15:09
I notice that and delete my comment. I was reading it wrong as admin command. Almost forgot the console command tho.
If this works for you, it should work for everyone. My concerns is the menu being overwritten multiple times without properly closing it. If it works, it works i guess.

Edit:
when i think this thru, your solution actually is the best.
Don't worry about the menu being leaking. High likely it won't.
I suppose you will get console warning but you won't crash.
Until then enjoy your plugin.

thank you for the assistance nonetheless