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

Deathrun Knife MOD [CSGO]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mario1x
Junior Member
Join Date: Jul 2023
Location: Romania
Old 07-08-2023 , 10:34   Deathrun Knife MOD [CSGO]
Reply With Quote #1

I have this Deathrun Knife MOD plugin like the one in AmxModX
Code:
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>

#define MOD_TAG "\x01\x0B★ \x07[Knife Mod]\x04 "
public Plugin myinfo = 
{
	name = "[DR] Knife Mod", 
	description = "Knife Mod import from cs1.6", 
	author = "spunko && Brum Brum", 
	version = "1.0", 
	url = "https://forums.alliedmods.net/showthread.php?p=378952"
};

ConVar CVAR_HIGHSPEED, CVAR_LOWSPEED, CVAR_LOWGRAV, CVAR_HEALTH_ADD, CVAR_HEALTH_MAX, CVAR_DAMAGE;

Handle g_selectedknife;

int Knife[MAXPLAYERS + 1];

bool MoreDamageLowSpeed[MAXPLAYERS + 1], NoFootSteps[MAXPLAYERS + 1], HighSpeed[MAXPLAYERS + 1], MoreLowGravity[MAXPLAYERS + 1], HealthRegeneration[MAXPLAYERS + 1];

public void OnPluginStart()
{
	HookEvent("player_spawn", Event_PlayerSpawn);
	
	g_selectedknife = RegClientCookie("sm_knifeselected", "Selected knife skills", CookieAccess_Protected);
	RegConsoleCmd("sm_knifes", Display_Knife);
	RegConsoleCmd("sm_cutit", Display_Knife);
	
	CVAR_HIGHSPEED = CreateConVar("km_highspeed", "1.3")
	CVAR_LOWSPEED = CreateConVar("km_lowspeed", "0.7")
	CVAR_HEALTH_ADD = CreateConVar("km_addhealth", "3")
	CVAR_HEALTH_MAX = CreateConVar("km_maxhealth", "75")
	CVAR_DAMAGE = CreateConVar("km_damage", "2.0")
	CVAR_LOWGRAV = CreateConVar("km_lowgravity", "0.6")
	AutoExecConfig(true, "Knife_Mod");
	AddNormalSoundHook(Sound);
	CreateTimer(480.0, kmodmsg, _, TIMER_REPEAT);
	CreateTimer(4.0, Healing, _, TIMER_REPEAT);
}

public void OnClientDisconnect(int client)
{
	if (AreClientCookiesCached(client))
	{
		char value[11];
		Format(value, sizeof(value), "%d", Knife[client]);
		SetClientCookie(client, g_selectedknife, value);
	}
	Knife[client] = 0;
	SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public void OnClientCookiesCached(int client)
{
	char value[11];
	GetClientCookie(client, g_selectedknife, value, sizeof(value));
	Knife[client] = StringToInt(value);
}

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));
	float lowspeed = CVAR_LOWSPEED.FloatValue;
	float highspeed = CVAR_HIGHSPEED.FloatValue;
	float gravity = CVAR_LOWGRAV.FloatValue;
	if (MoreDamageLowSpeed[client]) {
		SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", lowspeed);
	}
	else if (HighSpeed[client]) {
		SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", highspeed);
	}
	else if (MoreLowGravity[client]) {
		SetEntityGravity(client, gravity);
	}
}

public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
{
	float lowspeed = CVAR_LOWSPEED.FloatValue;
	float highspeed = CVAR_HIGHSPEED.FloatValue;
	float gravity = CVAR_LOWGRAV.FloatValue;
	if (MoreDamageLowSpeed[client]) {
		if (GetClientSpeed(client) != lowspeed) {
			SetClientSpeed(client, lowspeed);
		}
	}
	else if (HighSpeed[client]) {
		if (GetClientSpeed(client) != highspeed) {
			SetClientSpeed(client, highspeed);
		}
	}
	else if (MoreLowGravity[client]) {
		if (GetEntityGravity(client) != gravity) {
			SetEntityGravity(client, gravity);
		}
	}
}

public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
	if (MoreDamageLowSpeed[attacker])
	{
		char weapons[64];
		float dmg = CVAR_DAMAGE.FloatValue;
		GetClientWeapon(attacker, weapons, sizeof(weapons));
		if ((StrContains(weapons, "knife", false) != -1) || (StrContains(weapons, "bayonet", false) != -1))
		{
			damage *= dmg;
			return Plugin_Changed;
		}
	}
	return Plugin_Continue;
}

public Action Display_Knife(int client, int args)
{
	Menu menu = new Menu(Menu_Handler);
	menu.SetTitle("Knife Mod");
	menu.AddItem("", "Machete (More Damage/Low Speed)");
	menu.AddItem("", "Bak Knife (No Footsteps)");
	menu.AddItem("", "Pocket Knife (High Speed)");
	menu.AddItem("", "Butcher Knife (More Low Gravity)");
	menu.AddItem("", "Default Knife (Health Regeneration)");
	menu.ExitButton = false;
	menu.Display(client, 60);
}

public int Menu_Handler(Menu menu, MenuAction action, int client, int item)
{
	if (action == MenuAction_Select)
	{
		switch (item)
		{
			case 0:SetKnife(client, 0)
			case 1:SetKnife(client, 1)
			case 2:SetKnife(client, 2)
			case 3:SetKnife(client, 3)
			case 4:SetKnife(client, 4)
		}
	}
	if (action == MenuAction_End)delete menu;
}

public SetKnife(int client, int knife) {
	switch (knife)
	{
		case 0:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = true;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			RestartStats(client);
			Knife[client] = 1;
		}
		case 1:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = true;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			Knife[client] = 2;
		}
		case 2:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = true;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			Knife[client] = 3;
		}
		case 3:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = true;
			Knife[client] = 4;
		}
		case 4:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = true;
			Knife[client] = 5;
		}
	}
}

public Action Healing(Handle timer)
{
	int maxhp = CVAR_HEALTH_MAX.IntValue;
	int addhp = CVAR_HEALTH_ADD.IntValue;
	for (int i = 1; i < MaxClients; i++)
	{
		if (IsValidClient(i))
		{
			if (HealthRegeneration[i] && IsPlayerAlive(i))
			{
				if (GetClientHealth(i) < maxhp)
				{
					SetEntityHealth(i, GetClientHealth(i) + addhp);
				}
			}
		}
	}
}

public Action Sound(int clients[MAXPLAYERS], int &numClients, char sample[PLATFORM_MAX_PATH], int &entity, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed)
{
	if (!IsValidClient(entity) || IsFakeClient(entity))
		return Plugin_Continue;
	
	if ((StrContains(sample, "physics") != -1 || StrContains(sample, "footsteps") != -1) && StrContains(sample, "suit") == -1)
	{
		if (!NoFootSteps[entity])
			EmitSoundToAll(sample, entity);
		
		return Plugin_Handled;
	}
	
	return Plugin_Continue;
}

public Action kmodmsg(Handle timer) {
	PrintToChatAll("%s Type /knife to change your knife skills", MOD_TAG);
}

void RestartStats(int client)
{
	SetClientSpeed(client, 1.0);
	SetEntityGravity(client, 1.0);
}

void SetClientSpeed(int client, float speed)
{
	SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", speed);
}
float GetClientSpeed(int client)
{
	return GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
}

public bool IsValidClient(int client)
{
	if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || !IsClientConnected(client) || IsFakeClient(client) || IsClientSourceTV(client))
		return false;
	
	return true;
}
and I want to make that I dont have the ability when using other weapons than the knife. Please help I am new to Source and I try to understand !
mario1x is offline
mario1x
Junior Member
Join Date: Jul 2023
Location: Romania
Old 07-12-2023 , 18:30   Re: Deathrun Knife MOD [CSGO]
Reply With Quote #2

up
mario1x is offline
azalty
AlliedModders Donor
Join Date: Feb 2020
Location: France
Old 07-14-2023 , 21:58   Re: Deathrun Knife MOD [CSGO]
Reply With Quote #3

You should be able to check if they're holding a knife or not with that.
PHP Code:
char sWeaponName[64];
GetClientWeapon(clientsWeaponNamesizeof(sWeaponName));
if ((
StrContains(sWeaponName"knife"false) == -1) && !StrEqual(sWeaponName"weapon_bayonet"false))
{
    
// The player isn't holding a knife

There are many other ways to do it but I find this one to be simple enough

Don't forget to use RestartStats() ;)
__________________
GitHub | Discord: @azalty | Steam

Last edited by azalty; 07-15-2023 at 10:11. Reason: Fixed a variable name
azalty is offline
mario1x
Junior Member
Join Date: Jul 2023
Location: Romania
Old 07-15-2023 , 09:27   Re: Deathrun Knife MOD [CSGO]
Reply With Quote #4

Solved :
Code:
#include <sdktools>
#include <sdkhooks>
#include <clientprefs>
#include <colors>

#define MOD_TAG "{blue}[DR]{default} "
public Plugin myinfo = 
{
	name = "[DR] Knife Mod", 
	description = "Knife Mod import from cs1.6", 
	author = "spunko && Brum Brum, azalty", 
	version = "1.2", 
	url = "https://forums.alliedmods.net/showthread.php?p=378952"
};

ConVar CVAR_HIGHSPEED, CVAR_LOWSPEED, CVAR_LOWGRAV, CVAR_HEALTH_ADD, CVAR_HEALTH_MAX, CVAR_DAMAGE;

Handle g_selectedknife;

int Knife[MAXPLAYERS + 1];

bool MoreDamageLowSpeed[MAXPLAYERS + 1], NoFootSteps[MAXPLAYERS + 1], HighSpeed[MAXPLAYERS + 1], MoreLowGravity[MAXPLAYERS + 1], HealthRegeneration[MAXPLAYERS + 1];

public void OnPluginStart()
{
	HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
	
	g_selectedknife = RegClientCookie("sm_knifeselected", "Selected knife skills", CookieAccess_Protected);
	RegConsoleCmd("sm_knifes", Display_Knife);
	RegConsoleCmd("sm_cutit", Display_Knife);
	
	CVAR_HIGHSPEED = CreateConVar("km_highspeed", "2.5");
	CVAR_LOWSPEED = CreateConVar("km_lowspeed", "0.7");
	CVAR_HEALTH_ADD = CreateConVar("km_addhealth", "10");
	CVAR_HEALTH_MAX = CreateConVar("km_maxhealth", "100");
	CVAR_DAMAGE = CreateConVar("km_damage", "2.0");
	CVAR_LOWGRAV = CreateConVar("km_lowgravity", "0.6");
	AutoExecConfig(true, "Knife_Mod");
	AddNormalSoundHook(Sound);
	CreateTimer(480.0, kmodmsg, _, TIMER_REPEAT);
	CreateTimer(4.0, Healing, _, TIMER_REPEAT);
}

public void OnClientDisconnect(int client)
{
	if (AreClientCookiesCached(client))
	{
		char value[11];
		Format(value, sizeof(value), "%d", Knife[client]);
		SetClientCookie(client, g_selectedknife, value);
	}
	Knife[client] = 0;
	SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}

public void OnClientCookiesCached(int client)
{
	char value[11];
	GetClientCookie(client, g_selectedknife, value, sizeof(value));
	Knife[client] = StringToInt(value);
}

void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(event.GetInt("userid"));
	
	if (!HasKnifeEquipped(client))
		return;
	
	float lowspeed = CVAR_LOWSPEED.FloatValue;
	float highspeed = CVAR_HIGHSPEED.FloatValue;
	float gravity = CVAR_LOWGRAV.FloatValue;
	if (MoreDamageLowSpeed[client]) {
		SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", lowspeed);
	}
	else if (HighSpeed[client]) {
		SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", highspeed);
	}
	else if (MoreLowGravity[client]) {
		SetEntityGravity(client, gravity);
	}
}

public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon)
{
	float lowspeed = CVAR_LOWSPEED.FloatValue;
	float highspeed = CVAR_HIGHSPEED.FloatValue;
	float gravity = CVAR_LOWGRAV.FloatValue;
	
	if (HasKnifeEquipped(client))
	{
		if (MoreDamageLowSpeed[client]) {
			if (GetClientSpeed(client) != lowspeed) {
				SetClientSpeed(client, lowspeed);
			}
		}
		else if (HighSpeed[client]) {
			if (GetClientSpeed(client) != highspeed) {
				SetClientSpeed(client, highspeed);
			}
		}
		else if (MoreLowGravity[client]) {
			if (GetEntityGravity(client) != gravity) {
				SetEntityGravity(client, gravity);
			}
		}
	}
	else
	{
		// Reset speed and gravity if no knife is equipped
		RestartStats(client);
	}
	return Plugin_Continue;
}

Action OnTakeDamage(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& weapon, float damageForce[3], float damagePosition[3])
{
	if (IsValidClient(attacker) && MoreDamageLowSpeed[attacker])
	{
		// Check if the weapon used is valid
		if (!IsValidEntity(weapon))
			return Plugin_Continue;
		
		char sWeaponClass[64];
		GetEntityClassname(weapon, sWeaponClass, sizeof(sWeaponClass));
		// Check if the weapon's class is NOT a knife
		if ((StrContains(sWeaponClass, "knife", false) == -1) && !StrEqual(sWeaponClass, "weapon_bayonet", false))
			return Plugin_Continue;
		
		// Increase damage if the ability is enabled and a knife is equipped
		float dmg = CVAR_DAMAGE.FloatValue;
		
		damage *= dmg;
		return Plugin_Changed;
	}
	return Plugin_Continue;
}

Action Display_Knife(int client, int args)
{
	Menu menu = new Menu(Menu_Handler);
	menu.SetTitle("Choose your Knife ability:");
	menu.AddItem("", "Katana (Damage mare/Viteza mica)");
	menu.AddItem("", "Bak Knife (Pasi silentiosi)");
	menu.AddItem("", "Pocket Knife (Viteza mare)");
	menu.AddItem("", "Butcher Knife (Gravitate scazuta)");
	menu.AddItem("", "Default Knife (Regenerare HP)");
	menu.ExitButton = true;
	menu.Display(client, 60);
	
	return Plugin_Handled; // Suppresses the "Unknown command" message in the console
}

int Menu_Handler(Menu menu, MenuAction action, int client, int item)
{
	if (action == MenuAction_Select)
	{
		switch (item)
		{
			case 0:
				SetKnife(client, 0);
			case 1:
				SetKnife(client, 1);
			case 2:
				SetKnife(client, 2);
			case 3:
				SetKnife(client, 3);
			case 4:
				SetKnife(client, 4);
		}
	}
	else if (action == MenuAction_End)
		delete menu;
	
	return 0;
}

void SetKnife(int client, int knife) {
	switch (knife)
	{
		case 0:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = true;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			Knife[client] = 1;
		}
		case 1:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = true;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			Knife[client] = 2;
		}
		case 2:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = true;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = false;
			Knife[client] = 3;
		}
		case 3:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = true;
			HealthRegeneration[client] = false;
			Knife[client] = 4;
		}
		case 4:
		{
			RestartStats(client);
			MoreDamageLowSpeed[client] = false;
			NoFootSteps[client] = false;
			HighSpeed[client] = false;
			MoreLowGravity[client] = false;
			HealthRegeneration[client] = true;
			Knife[client] = 5;
		}
	}
}

Action Healing(Handle timer)
{
	int maxhp = CVAR_HEALTH_MAX.IntValue;
	int addhp = CVAR_HEALTH_ADD.IntValue;
	int new_health;
	for (int i = 1; i <= MaxClients; i++)
	{
		if (IsValidClient(i))
		{
			if (HealthRegeneration[i] && IsPlayerAlive(i))
			{
				if (GetClientHealth(i) < maxhp && HasKnifeEquipped(i))
				{
					new_health = GetClientHealth(i) + addhp;
					if (new_health > maxhp)
						new_health = maxhp;
					
					SetEntityHealth(i, new_health);
				}
			}
		}
	}
	return Plugin_Continue;
}


Action Sound(int clients[MAXPLAYERS], int &numClients, char sample[PLATFORM_MAX_PATH], int &entity, int &channel, float &volume, int &level, int &pitch, int &flags, char soundEntry[PLATFORM_MAX_PATH], int &seed)
{
	if (!IsValidClient(entity))
		return Plugin_Continue;
	
	if (NoFootSteps[entity] && (StrContains(sample, "physics") != -1 || StrContains(sample, "footsteps") != -1) && StrContains(sample, "suit") == -1)
	{
		return Plugin_Handled; // Suppress the sound
	}
	
	return Plugin_Continue;
}

Action kmodmsg(Handle timer) {
	CPrintToChatAll("%s Scrie {green}!cutit{default} pentru a-ti alege abilitatea cutitului{blue}.", MOD_TAG);
	return Plugin_Continue;
}

void RestartStats(int client)
{
	SetClientSpeed(client, 1.0);
	SetEntityGravity(client, 1.0);
}

void SetClientSpeed(int client, float speed)
{
	SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", speed);
}
float GetClientSpeed(int client)
{
	return GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue");
}

bool IsValidClient(int client)
{
	// Important note: if a client is in game (IsClientInGame), they are connected (IsClientConnected)
	if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client) || IsClientSourceTV(client))
		return false;
	
	return true;
}

// Can have a big performance impact
bool HasKnifeEquipped(int client)
{
	char sWeaponName[64];
	GetClientWeapon(client, sWeaponName, sizeof(sWeaponName));
	if ((StrContains(sWeaponName, "knife", false) == -1) && !StrEqual(sWeaponName, "weapon_bayonet", false))
	{
		// The player isn't holding a knife
		return false;
	}
	return true;
}

Last edited by mario1x; 07-15-2023 at 10:27.
mario1x 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 03:27.


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