PDA

View Full Version : [CS GO] AddCommandListener does not work.


kondzixd
03-24-2015, 17:36
Hi.
I have a problem with AddCommandListener. It does not work at all.
I try to catch when player push "slot1"
public OnPluginStart()
{
AddCommandListener(ChangeWeapon_1, "slot1");
}

public Action:ChangeWeapon_1(client, const String:command[], argc)
{

if(aktualna_liczba_broni_dlugich[client])
{
ZapiszAmmo(client);
new slot = ZwrocSlot(client)
new weaponIndex = -1
weaponIndex = GetPlayerWeaponSlot(client, 0);
if(weaponIndex != -1)
{
RemovePlayerItem(client, weaponIndex);
RemoveEdict(weaponIndex);
}
switch(slot)
{
case BRON_DLUGA:
{
if(++aktualna_bron_dluga[client] >= aktualna_liczba_broni_dlugich[client])
aktualna_bron_dluga[client] = 0;

GivePlayerItem(client, player_weapons[client][aktualna_bron_dluga[client]][0]);
DajAmmo(client, 0);
}
case BRON_KROTKA:
{
GivePlayerItem(client, player_weapons[client][aktualna_bron_dluga[client]][0]);
DajAmmo(client, 0);
}
case NOZ:
{
GivePlayerItem(client, player_weapons[client][aktualna_bron_dluga[client]][0]);
DajAmmo(client, 0);
}
case GRANATY:
{
GivePlayerItem(client, player_weapons[client][aktualna_bron_dluga[client]][0]);
DajAmmo(client, 0);
}
case C4:
{
GivePlayerItem(client, player_weapons[client][aktualna_bron_dluga[client]][0]);
DajAmmo(client, 1);
}
}
}
return Plugin_Continue;
}

What I doing wrong?

psychonic
03-24-2015, 20:39
AddCommandListener only works for commands that are sent to the server.

The "slot#" commands are intercepted on the client. The client then sets the weapon param in the next usercmd that it sends to the server. You can see this in the OnPlayerRunCmd (https://sm.alliedmods.net/new-api/sdktools_hooks/OnPlayerRunCmd) forward when the weapon param is non-zero.

If you want to know when the player actually switched weapons, rather than just when they attempted to, use SDKHooks with a Weapon_Switch hook.

kondzixd
03-25-2015, 03:31
I am writing a plugin "more weapons" for cs go and i need to hook when player push button 1 when he have or not primary weapon in hands. You said runcmd is helpfull, will be? If yes can u give me example how to check it?

apocalyptic
03-26-2015, 04:24
AddCommandListener cannot work on "slot*", you can try this:
enum Slots
{
SlotPrimary,
SlotSecondary,
SlotKnife,
SlotGrenade,
SlotC4,
SlotNone
}

public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost)
}

public OnWeaponSwitchPost(client, weapon)
{
new WpnId = GetPlayerWeaponSlot(client,_:SlotPrimary)
if (WpnId!=-1)
//client has a primary weapon
else
//client has no primary weapons
}

public OnClientDisconnect(client)
{
SDKUnhook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost)
}