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

Solved CSS Knife can't be equipped with Command ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zuczekxx
Junior Member
Join Date: Dec 2023
Location: ►Europe
Old 12-20-2023 , 08:43   CSS Knife can't be equipped with Command ?
Reply With Quote #1

Guys does anyone know why this command doesn't change the players weapon to a knife ( as it supposedly should, all it does is crash the game ):
public Action Command_KnifeEquip(int client, int args){
int knife = CS_AliasToWeaponID("weapon_knife");
EquipPlayerWeapon(client, knife);
return Plugin_Handled;
}

Last edited by Zuczekxx; 12-24-2023 at 20:20.
Zuczekxx is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 12-20-2023 , 10:13   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #2

You are passing a weapon id to EquipPlayerWeapon which requires an entity index of that weapon.
Your game crashes as it tries to equip a non weapon entity.
What you need is the return value of GetPlayerWeaponSlot(client, CS_SLOT_KNIFE) which you then can pass to EquipPlayerWeapon. Be sure to always check if GetPlayerWeaponSlot does not return -1 before attempting to use EquipPlayerWeapon.
xerox8521 is offline
Zuczekxx
Junior Member
Join Date: Dec 2023
Location: ►Europe
Old 12-20-2023 , 14:22   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #3

I dont know why but the server still crashes :
//------------------------------------------------------------------------------
public Action Command_KnifeEquip(int client, int args){
int knife = GetPlayerWeaponSlot(client, CS_SLOT_KNIFE);
EquipPlayerWeapon(client, knife);
return Plugin_Handled;
}
//------------------------------------------------------------------------------
When i swapped CS_SLOT_KNIFE with for example CS_SLOT_SECONDARY it worked as well as with any other slot but when i try it with the knife either the server crashes or nothing happens
Zuczekxx is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-21-2023 , 06:42   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #4

What if replace EquipPlayerWeapon(client, knife); with AcceptEntityInput(knife, "Use", client, client);?
__________________
Grey83 is offline
Zuczekxx
Junior Member
Join Date: Dec 2023
Location: ►Europe
Old 12-21-2023 , 08:24   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #5

Quote:
Originally Posted by Grey83 View Post
What if replace EquipPlayerWeapon(client, knife); with AcceptEntityInput(knife, "Use", client, client);?
the command does nothing now , is the css knife broken ?
Zuczekxx is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-22-2023 , 07:09   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #6

Then maybe this will help?
ClientCommand(client, "slot3");
__________________
Grey83 is offline
Zuczekxx
Junior Member
Join Date: Dec 2023
Location: ►Europe
Old 12-22-2023 , 15:32   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #7

Quote:
Originally Posted by Grey83 View Post
Then maybe this will help?
ClientCommand(client, "slot3");
Tried it just now and the server console keeps spamming : "UTIL_GetListenServerHost() called from a dedicated server or single-player game." was thinking about using ClientCommand(client, "+attack"); but apparently the sever cant execute this command since all it writes is "FCVAR_SERVER_CAN_EXECUTE prevented server running command: +attack"
Zuczekxx is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 12-24-2023 , 12:25   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #8

PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}


public 
Action test(int clientint args)
{
    
FakeClientCommandEx(client"use weapon_knife");

    return 
Plugin_Handled;

Worked fine on cs:s
__________________
Do not Private Message @me
Bacardi is offline
Zuczekxx
Junior Member
Join Date: Dec 2023
Location: ►Europe
Old 12-24-2023 , 20:19   Re: CSS Knife can't be equipped with Command ?
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
PHP Code:
public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"test);
}


public 
Action test(int clientint args)
{
    
FakeClientCommandEx(client"use weapon_knife");

    return 
Plugin_Handled;

Worked fine on cs:s
Yes it does , thanks man also Merry Christmas
Zuczekxx 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 16:09.


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