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

DeathRun Knife Menu help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ghostery
Junior Member
Join Date: Apr 2019
Old 04-11-2019 , 17:28   DeathRun Knife Menu help
Reply With Quote #1

Hello, i am new to SM and i tried to create a DeathRun Knife Menu plugin. The plugin si working perfectly but... i don't know one thing. The plugin gives you powers (speed, low graity, etc) by the knife. My question is... how can i make it to use the powers ONLY WITH KNIFE IN HAND?

that's the code:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>
#include <cstrike>
#include <sdkhooks>
#include <clientprefs>

#pragma semicolon 1

#define VERSION "1.0"

public Plugin:myinfo =
{
    
name "Deathrun Knife",
    
author "",
    
description "Deathrun Knife menu",
    
version VERSION,
    
url ""
};

public 
OnPluginStart()
{
    
LoadTranslations("common.phrases");

    
RegConsoleCmd("sm_knife"KnifeMenu);
    
RegConsoleCmd("buy"KnifeMenu);
    
RegConsoleCmd("buymenu"KnifeMenu);
    
RegConsoleCmd("autobuy"KnifeMenu);
    
RegConsoleCmd("rebuy"KnifeMenu);

    
// ======================================================================

    
HookEvent"player_spawn"OnPlayerSpawn );

}

public 
Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserIdGetEventIntevent"userid" ));
    if ( 
IsValidPlayerclient ))
    {
        if(
GetClientTeam(client) == CS_TEAM_CT)
        {
            new 
iWeapon GetPlayerWeaponSlot(client2);
            
PrintToChat(client"\x05[Knife]\x01You spawned with the Default Knife.");
            
SetEntityGravity(client1.0);
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
            
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);
            new 
knife GivePlayerItem(client"weapon_knife");
            
EquipPlayerWeapon(clientknife);
            
KCM(client);
        }
    }
}

public 
Action:KnifeMenu(client,args)
{
    if(
client == 0)
    {
        
PrintToServer("%t","Command is in-game only");
        return 
Plugin_Handled;
    }
    else if ( 
IsPlayerAliveclient ))
    {
        if(
GetClientTeam(client) == CS_TEAM_CT)
        {
            
KCM(client);
        }
    }
    else
    {
        
PrintToChat(client"\x05[Knife]\x01You can't choose Knife.");
    }
    return 
Plugin_Handled;
}

public 
Action:KCM(clientId
{
    new 
Handle:menu CreateMenu(KCMenuHandler);
    
SetMenuTitle(menu"Deathrun - Knife Menu");
    
AddMenuItem(menu"option1""Default [Normal]");
    
AddMenuItem(menu"option2""Butcher [Low Gravity]");
    
AddMenuItem(menu"option3""Pocket [High Speed]");
    
AddMenuItem(menu"option4""VIP [Only vips]");
    
SetMenuExitButton(menutrue);
    
DisplayMenu(menuclientIdMENU_TIME_FOREVER);

    return 
Plugin_Handled;
}

public 
KCMenuHandler(Handle:menuMenuAction:actionclientitemNum
{
    if ( 
action == MenuAction_Select 
    {
        new 
String:info[32];
        new 
iWeapon GetPlayerWeaponSlot(client2);
        
GetMenuItem(menuitemNuminfosizeof(info));

        if ( 
strcmp(info,"option1") == 
        {
            {
              
PrintToChat(client"\x05[Knife]\x01You now have Default Knife.");
              
SetEntityGravity(client1.0);
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);
              new 
knife GivePlayerItem(client"weapon_knife");
              
EquipPlayerWeapon(clientknife);
            }
        }
        else if ( 
strcmp(info,"option2") == 
        {
            {
              
PrintToChat(client"\x05[Knife]\x01You now have Butcher Knife.");
              
SetEntityGravity(client0.6);
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);
              new 
knife GivePlayerItem(client"weapon_knife");
              
EquipPlayerWeapon(clientknife);
            }
        }
        else if ( 
strcmp(info,"option3") == 
        {
            {
              
PrintToChat(client"\x05[Knife]\x01You now have Pocket Knife.");
              
SetEntityGravity(client1.0);
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.3);
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);
              new 
knife GivePlayerItem(client"weapon_knife");
              
EquipPlayerWeapon(clientknife);
            }
        }
        else if ( 
strcmp(info,"option4") == 
        {
            {
              if (
IsPlayerVip(client))
              {
               
PrintToChat(client"\x05[Knife]\x01You now have VIP Knife.");
               
SetEntityGravity(client0.8);
               
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.1);
               
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);
               new 
knife GivePlayerItem(client"weapon_knife");
               
EquipPlayerWeapon(clientknife);
              }
              else
              {
               
PrintToChat(client"\x05[Knife]\x01 You are not VIP.");
               
KCM(client);
              }
            }
        }
    }
}

public 
Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
  new 
client GetClientOfUserId(GetEventInt(event"userid"));

  if (
GetClientTeam(client) == && !IsPlayerAlive(client))
  {
         return;
  }
}

bool:IsPlayerVip(client)
{
    return 
CheckCommandAccess(client"flag_vip"ADMFLAG_CUSTOM6false);
}

bool:IsValidPlayerclient )
{
    if ( 
client || client MaxClients )  return false;
    if ( !
IsClientConnectedclient ))  return false;
    if ( !
IsClientInGameclient ))  return false;
    if ( 
IsFakeClientclient ))  return false;
    return 
true;

Ghostery is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 04-11-2019 , 18:54   Re: DeathRun Knife Menu help
Reply With Quote #2

Use SDKHook_WeaponSwitch
Vaggelis is offline
Ghostery
Junior Member
Join Date: Apr 2019
Old 04-12-2019 , 03:19   Re: DeathRun Knife Menu help
Reply With Quote #3

Quote:
Originally Posted by Vaggelis View Post
Use SDKHook_WeaponSwitch
i know that's a dumb question... but how?
Ghostery is offline
CliptonHeist
Senior Member
Join Date: Feb 2016
Old 04-12-2019 , 21:01   Re: DeathRun Knife Menu help
Reply With Quote #4

Ask whoever made the plugin for you, since it's pretty obvious you didn't if you don't know what a SDKHook is.
CliptonHeist is offline
Ghostery
Junior Member
Join Date: Apr 2019
Old 04-13-2019 , 03:24   Re: DeathRun Knife Menu help
Reply With Quote #5

Quote:
Originally Posted by CliptonHeist View Post
Ask whoever made the plugin for you, since it's pretty obvious you didn't if you don't know what a SDKHook is.
the problem is that the author is unknown
Ghostery is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 04-13-2019 , 05:01   Re: [CSGO] DeathRun Knife Menu
Reply With Quote #6

You could check if the player has a knife in hand & the power. Example:

PHP Code:

...
//anywhere in plugin
SDKHook(clientSDKHook_WeaponEquipOnWeaponEquip);

public 
Action:OnWeaponEquip(clientweapon

    
decl String:sWeapon[32]; 
    
GetEdictClassname(weaponsWeaponsizeof(sWeapon)); 
     
    if( 
StrEqual(sWeapon"weapon_knife") && power1[client]) 
    { 
        
//do your stuff
    

     
    return 
Plugin_Continue

__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545
cristian20042 is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 04-13-2019 , 06:23   Re: [CSGO] DeathRun Knife Menu
Reply With Quote #7

the function "SDKHook_WeaponEquip" will be called if the player pick up the weapon.
if the player change the slot, the abilities will work on that weapon.
So you need to put "SDKHook_WeaponSwitchPost" and check if the weapon classname equal "weapon_knife".

upd. I think it would be better if you create an knife entity, change the classname to for example "weapon_knifebutcher" so that the abilities can only work if entity name equal "weapon_knifebutcher", for not all knives.

Last edited by farawayf; 04-13-2019 at 06:24.
farawayf is offline
cristian20042
AlliedModders Donor
Join Date: Jun 2016
Location: Romania
Old 04-13-2019 , 07:42   Re: [CSGO] DeathRun Knife Menu
Reply With Quote #8

Ok, so I think he can do something like this:

Spoiler


The easiest way for you, could be to check if player has a knife, then if also has a power, and whenever the player selects a power from the menu, you will disable all other powers, and enable only 1.

EDIT: I made an example for you (NOT TESTED). This should work. BTW, you should work on your indentation

PHP Code:
#include <sourcemod>  
#include <sdktools>  
#include <sdktools_sound>  
#include <cstrike>  
#include <sdkhooks>  
#include <clientprefs>  

#pragma semicolon 1  

#define VERSION "1.0"  

bool option1[MAXPLAYERS+1] = false;
bool option2[MAXPLAYERS+1] = false;
bool option3[MAXPLAYERS+1] = false;
bool option4[MAXPLAYERS+1] = false;

public 
Plugin:myinfo =  
{  
    
name "Deathrun Knife",  
    
author "Ghostery + SniperHero",  
    
description "Deathrun Knife menu",  
    
version VERSION,  
    
url ""  
};  

public 
OnPluginStart()  
{  
    
LoadTranslations("common.phrases");  

    
RegConsoleCmd("sm_knife"KnifeMenu);  
    
RegConsoleCmd("buy"KnifeMenu);  
    
RegConsoleCmd("buymenu"KnifeMenu);  
    
RegConsoleCmd("autobuy"KnifeMenu);  
    
RegConsoleCmd("rebuy"KnifeMenu);  

    
// ======================================================================  

    
HookEvent"player_spawn"OnPlayerSpawn );  

}  

public 
Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)  
{  
    new 
client GetClientOfUserIdGetEventIntevent"userid" ));  
    if ( 
IsValidPlayerclient ))  
    {  
        if(
GetClientTeam(client) == CS_TEAM_CT)  
        {  
            new 
iWeapon GetPlayerWeaponSlot(client2);  
            
PrintToChat(client"\x05[Knife]\x01You spawned with the Default Knife.");  
            
SetEntityGravity(client1.0);  
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);  
            
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);  
            new 
knife GivePlayerItem(client"weapon_knife");  
            
EquipPlayerWeapon(clientknife);
            
option1[client] = true;
            
option2[client] = false;
            
option3[client] = false;
            
option4[client] = false;
            
SDKHook(clientSDKHook_WeaponSwitchPostOnWeaponSwitched);
            
KCM(client);  
        }  
    }  
}  

public 
Action:KnifeMenu(client,args)  
{  
    if(
client == 0)  
    {  
        
PrintToServer("%t","Command is in-game only");  
        return 
Plugin_Handled;  
    }  
    else if ( 
IsPlayerAliveclient ))  
    {  
        if(
GetClientTeam(client) == CS_TEAM_CT)  
        {  
            
KCM(client);  
        }  
    }  
    else  
    {  
        
PrintToChat(client"\x05[Knife]\x01You can't choose Knife.");  
    }  
    return 
Plugin_Handled;  
}  

public 
Action:KCM(clientId)   
{  
    new 
Handle:menu CreateMenu(KCMenuHandler);  
    
SetMenuTitle(menu"Deathrun - Knife Menu");  
    
AddMenuItem(menu"option1""Default [Normal]");  
    
AddMenuItem(menu"option2""Butcher [Low Gravity]");  
    
AddMenuItem(menu"option3""Pocket [High Speed]");  
    
AddMenuItem(menu"option4""VIP [Only vips]");  
    
SetMenuExitButton(menutrue);  
    
DisplayMenu(menuclientIdMENU_TIME_FOREVER);  

    return 
Plugin_Handled;  
}  

public 
KCMenuHandler(Handle:menuMenuAction:actionclientitemNum)   
{  
    if ( 
action == MenuAction_Select )   
    {  
        new 
String:info[32];  
        new 
iWeapon GetPlayerWeaponSlot(client2);  
        
GetMenuItem(menuitemNuminfosizeof(info));  

        if ( 
strcmp(info,"option1") == )   
        {  
            {  
              
PrintToChat(client"\x05[Knife]\x01You now have Default Knife.");  
              
SetEntityGravity(client1.0);  
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);  
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);  
              new 
knife GivePlayerItem(client"weapon_knife");  
              
EquipPlayerWeapon(clientknife);
              
option1[client] = true;
              
option2[client] = false;
              
option3[client] = false;
              
option4[client] = false;
            }  
        }  
        else if ( 
strcmp(info,"option2") == )   
        {  
            {  
              
PrintToChat(client"\x05[Knife]\x01You now have Butcher Knife.");  
              
SetEntityGravity(client0.6);  
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);  
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);  
              new 
knife GivePlayerItem(client"weapon_knife");  
              
EquipPlayerWeapon(clientknife);
              
option1[client] = false;
              
option2[client] = true;
              
option3[client] = false;
              
option4[client] = false;
            }  
        }  
        else if ( 
strcmp(info,"option3") == )   
        {  
            {  
              
PrintToChat(client"\x05[Knife]\x01You now have Pocket Knife.");  
              
SetEntityGravity(client1.0);  
              
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.3);  
              
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);  
              new 
knife GivePlayerItem(client"weapon_knife");  
              
EquipPlayerWeapon(clientknife);  
              
option1[client] = false;
              
option2[client] = false;
              
option3[client] = true;
              
option4[client] = false;
            }  
        }  
        else if ( 
strcmp(info,"option4") == )   
        {  
            {  
              if (
IsPlayerVip(client))  
              {  
                
PrintToChat(client"\x05[Knife]\x01You now have VIP Knife.");  
                
SetEntityGravity(client0.8);  
                
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.1);  
                
RemovePlayerItem(clientiWeapon), RemoveEdict(iWeapon);  
                new 
knife GivePlayerItem(client"weapon_knife");  
                
EquipPlayerWeapon(clientknife);  
                
option1[client] = false;
                
option2[client] = false;
                
option3[client] = false;
                
option4[client] = true;
              }  
              else  
              {  
               
PrintToChat(client"\x05[Knife]\x01 You are not VIP.");  
               
KCM(client);  
              }  
            }  
        }  
    }  
}  

public 
Action:OnWeaponSwitched(clientweapon)  
{  
    
decl String:sWeapon[32];  
    
GetEdictClassname(weaponsWeaponsizeof(sWeapon));  
      
    if( 
StrEqual(sWeapon"weapon_knife"))  
    {  
        if(
option1[client])
        {
            
SetEntityGravity(client1.0);  
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
        }
        if(
option2[client])
        {
            
SetEntityGravity(client0.6);  
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
        }
        if(
option3[client])
        {
            
SetEntityGravity(client1.0);  
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.3);
        }
        if(
option4[client])
        {
            
SetEntityGravity(client0.8);  
            
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.1);
        }
    }  
    else
    {
        
SetEntityGravity(client1.0);  
        
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"1.0);
    }
      
    return 
Plugin_Continue;  
}  

public 
Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)  
{  
  new 
client GetClientOfUserId(GetEventInt(event"userid"));  

  if (
GetClientTeam(client) == && !IsPlayerAlive(client))  
  {  
         return;  
  }  
}  

bool:IsPlayerVip(client)  
{  
    return 
CheckCommandAccess(client"flag_vip"ADMFLAG_CUSTOM6false);  
}  

bool:IsValidPlayerclient )  
{  
    if ( 
client || client MaxClients )  return false;  
    if ( !
IsClientConnectedclient ))  return false;  
    if ( !
IsClientInGameclient ))  return false;  
    if ( 
IsFakeClientclient ))  return false;  
    return 
true;  

__________________
Steam - https://steamcommunity.com/id/sniperheroofficialu/
Discord - SniperHero#8545

Last edited by cristian20042; 04-13-2019 at 07:58.
cristian20042 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 04:25.


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