Raised This Month: $23 Target: $400
 5% 

Snowball plugin problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jugule
Member
Join Date: Apr 2020
Old 05-27-2020 , 23:37   Snowball plugin problem
Reply With Quote #1

I use this Snowball plugin, the idea is that when someone has that snowball in their hand, the specific snowball model appears, then the weapon_decoy model. Example: 1 second snowball appears(photo: https://cdn.discordapp.com/attachmen...86/unknown.png), 1 second decoy Photo:https://cdn.discordapp.com/attachmen...06/unknown.png) (normal decoy pattern) in spam.

Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "boomix"
#define PLUGIN_VERSION "1.00"

#define TrailColor	{255,255,255,225}

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <sendproxy>
#include <emitsoundany>
#include <autoexecconfig>
#include <snowball>

#define LoopAllPlayers(%1) for(int %1=1;%1<=MaxClients;++%1)\
if(IsClientInGame(%1) && !IsFakeClient(%1))


EngineVersion g_Game;
int g_PVMid[MAXPLAYERS + 1];
int g_iSMGModel;
int g_iLaserBeam;
float f_LastThrowAng[MAXPLAYERS + 1][3];
Handle g_SnowBallHitPlayer;

//Cofig
Handle SnowballEnable;
Handle SpawnSBOnPlayerSpawn;
Handle GiveAnotherSnowball;
Handle TimeToGiveSnowball;
Handle EnableSnowballTrail;
Handle SnowballHitPlayer;
Handle SnowballHitDamage;
Handle HitUnfreezetime;
Handle WarmupOnlyEnable;

bool b_PluginEnable;
bool b_SpawnSnowBall;
bool b_GiveAnotherBall;
float fl_TimeToGiveSnowball;
bool b_EnableTrail;
int i_SnowballHitPlayer;
int i_SnowballDamage;
float f_UnfreezeTime;
bool b_OnlyWarmupEnable;

public Plugin myinfo = 
{
	name = "Snowball",
	author = PLUGIN_AUTHOR,
	description = "Grenade as snowball for CS:GO",
	version = PLUGIN_VERSION,
	url = "http://alliedmods.com"
};

public void OnPluginStart()
{
	g_Game = GetEngineVersion();
	if(g_Game != Engine_CSGO)
		SetFailState("This plugin is for CSGO/CSS only.");
	
	LoopAllPlayers(i)
	{
		SDKHook(i, SDKHook_WeaponSwitchPost, 	OnClientWeaponSwitchPost); 
		SendProxy_Hook(i, "m_flNextAttack", Prop_Float, ProxyCallback);
	}
	
	AddNormalSoundHook(SoundHook);
	HookEvent("player_spawn", Event_PlayerSpawn);
	
	//Config
	AutoExecConfig_SetFile("snowball");
	
	HookConVarChange(SnowballEnable 		=	AutoExecConfig_CreateConVar("sm_SnowballEnable", 				"1", 	"0 disabled | 1 enabled (Enabled/disabled the plugin)"), 			OnCvarChanged);
	HookConVarChange(WarmupOnlyEnable 		=	AutoExecConfig_CreateConVar("sm_SnowballEnableOnlyWarmup", 		"0", 	"0 disabled | 1 enabled (If set to 1, plugin will be turned on only in warmup period)"), 			OnCvarChanged);
	HookConVarChange(SpawnSBOnPlayerSpawn 	=	AutoExecConfig_CreateConVar("sm_SpawnSnowballOnPlayerSpawn", 	"1", 	"0 disabled | 1 enabled (Give players decoy (snowball) on player spawn)"), 			OnCvarChanged);
	HookConVarChange(GiveAnotherSnowball 	=	AutoExecConfig_CreateConVar("sm_GiveAnotherSnowballAfterThrow", "1", 	"0 disabled | 1 enabled (Give another decoy (snowball) after after player throws one)"), 			OnCvarChanged);
	HookConVarChange(TimeToGiveSnowball 	=	AutoExecConfig_CreateConVar("sm_TimeToGiveSnowballAfterThrow", 	"5.0", "Time to give another decoy (snowball) back to player after he throws one out."), 			OnCvarChanged);
	HookConVarChange(EnableSnowballTrail 	=	AutoExecConfig_CreateConVar("sm_EnableSnowballTrail", 			"0", 	"0 disabled | 1 enabled (Enable trail for the decoy (snowball))"), 			OnCvarChanged);
	HookConVarChange(SnowballHitPlayer 		=	AutoExecConfig_CreateConVar("sm_SnowballHitPlayerType", 		"1", 	"What to do when player hits other player with snowball (1: kill, 2: freeze, 3: dmg, 4: freeze+dmg, 5: custom) | (kill: kills player, freeze: freezes player, dmg: give damage to player, freeze+dmg: freeze and damage together enabled, custom: for developers if they want something custom)"), 			OnCvarChanged);
	HookConVarChange(SnowballHitDamage 		=	AutoExecConfig_CreateConVar("sm_SnowballHitDamage", 			"50", 	"0 - 100 (how much damage you want to give /if sm_SnowballHitPlayerType = 1/)"), 			OnCvarChanged);
	HookConVarChange(HitUnfreezetime 		=	AutoExecConfig_CreateConVar("sm_SnowballUnfreezeTime", 			"5.0", 	"Unfreeze time if /sm_SnowballHitPlayerType = 2/)"), 			OnCvarChanged);
	
	
	AutoExecConfig_ExecuteFile();
	AutoExecConfig_CleanFile();
	UpdateConvars();

}

public void OnConfigsExecuted()
{
	
	//Models
	AddFileToDownloadsTable("models/weapons/v_snowball.dx80.vtx");
	AddFileToDownloadsTable("models/weapons/v_snowball.dx90.vtx");
	AddFileToDownloadsTable("models/weapons/v_snowball.mdl");
	AddFileToDownloadsTable("models/weapons/v_snowball.sw.vtx");
	AddFileToDownloadsTable("models/weapons/v_snowball.vvd");
	AddFileToDownloadsTable("models/weapons/w_snowball.dx80.vtx");
	AddFileToDownloadsTable("models/weapons/w_snowball.dx90.vtx");
	AddFileToDownloadsTable("models/weapons/w_snowball.mdl");
	AddFileToDownloadsTable("models/weapons/w_snowball.phy");
	AddFileToDownloadsTable("models/weapons/w_snowball.sw.vtx");
	AddFileToDownloadsTable("models/weapons/w_snowball.vvd");

	//Materials
	AddFileToDownloadsTable("materials/models/weapons/v_models/sball/v_hands.vmt");
	AddFileToDownloadsTable("materials/models/weapons/v_models/sball/v_hands.vtf");
	AddFileToDownloadsTable("materials/models/weapons/v_models/sball/v_hands_normal.vtf");
	AddFileToDownloadsTable("materials/models/weapons/v_models/Snooball/s.vmt");
	AddFileToDownloadsTable("materials/models/weapons/v_models/Snooball/s.vtf");
	AddFileToDownloadsTable("materials/models/weapons/v_models/Snooball/s_norm.vtf");
	
	AddFileToDownloadsTable("materials/snowball/snowball.vmt");
	AddFileToDownloadsTable("materials/snowball/snowball.vtf");
	
	//Sound
	AddFileToDownloadsTable("sound/snowball/hit.mp3");
	
	g_iSMGModel = PrecacheModel("models/weapons/v_snowball.mdl");
	g_iLaserBeam = PrecacheModel("materials/sprites/laserbeam.vmt");
	PrecacheModel("models/weapons/w_snowball.mdl");
	
	PrecacheSound("physics/glass/glass_impact_bullet4.wav", true);
	PrecacheSoundAny("snowball/hit.mp3");
}

public void OnCvarChanged(Handle hConvar, const char[] chOldValue, const char[] chNewValue)
{
	UpdateConvars();
}

public void UpdateConvars()
{
	b_PluginEnable 			= GetConVarBool(SnowballEnable);
	b_SpawnSnowBall 		= GetConVarBool(SpawnSBOnPlayerSpawn);	
	b_GiveAnotherBall 		= GetConVarBool(GiveAnotherSnowball);
	fl_TimeToGiveSnowball 	= GetConVarFloat(TimeToGiveSnowball);
	b_EnableTrail			= GetConVarBool(EnableSnowballTrail);
	i_SnowballHitPlayer 	= GetConVarInt(SnowballHitPlayer);
	i_SnowballDamage 		= GetConVarInt(SnowballHitDamage);
	f_UnfreezeTime 			= GetConVarFloat(HitUnfreezetime);
	b_OnlyWarmupEnable 		= GetConVarBool(WarmupOnlyEnable);
}

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
	RegPluginLibrary("snowball");
	g_SnowBallHitPlayer = CreateGlobalForward("Snowball_HitPlayer", ET_Ignore, Param_Cell, Param_Cell);
	return APLRes_Success;
}


public Action Event_PlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
{
	if(b_PluginEnable && b_SpawnSnowBall)
	{
		int client = GetClientOfUserId(GetEventInt(event, "userid"));
		GivePlayerItem(client, "weapon_decoy");
	}
}

public Action SoundHook(int clients[64], int &numClients, char sound[PLATFORM_MAX_PATH], int &entity, int &channel, float &volume, int &level, int &pitch, int &flags)
{
	if(entity > 0 && b_PluginEnable)
	{
		char classname[120];
		GetEntityClassname(entity, classname, 120);
		
		if(StrEqual(classname, "decoy_projectile"))
		{
			EmitSoundToAllAny("snowball/hit.mp3", entity, channel, level, flags, 0.9, pitch);
			return Plugin_Stop;
		}
	}
	
	return Plugin_Continue;
}

public Action ProxyCallback(int entity, const char[] propname, float &fValue, int element)
{
	
	if(IsClientInGame(entity) && IsPlayerAlive(entity) && b_PluginEnable)
	{
		if(HasGrenadeInHands(entity))
		{
	   	 	fValue = GetGameTime()+9999.0;
	   	 	return Plugin_Changed;
	   	} else {
	   		fValue = GetGameTime()-1.0;
	   	}
	} 
	
	return Plugin_Continue;
} 

public void OnEntityCreated(int entity, const char[] classname)
{ 
	if(StrEqual(classname, "weapon_decoy") && b_PluginEnable)
	{
		if(!IsModelPrecached("models/weapons/w_snowball.mdl"))
			PrecacheModel("models/weapons/w_snowball.mdl");
		
		SetEntityModel(entity, "models/weapons/w_snowball.mdl");
	}
	
	if(StrEqual(classname, "decoy_projectile") && b_PluginEnable)
	{
		SetCvar("sv_ignoregrenaderadio", "1");
		SDKHook(entity, SDKHook_SpawnPost, ProjectileSpawned);
	}
}

public void ProjectileSpawned2(int entity)
{
	SetEntityModel(entity, "models/weapons/w_snowball.mdl");
}

public void ProjectileSpawned(int entity)
{
	int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
	GetClientAbsAngles(client, f_LastThrowAng[client]);
	SetEntityModel(entity, "models/weapons/w_snowball.mdl");
	SDKHook(entity, SDKHook_StartTouch, StartTouch);
	
	//Trail
	if(b_EnableTrail)
	{
		TE_SetupBeamFollow(entity, g_iLaserBeam, 0, 1.0, 1.0, 1.0, 5, TrailColor);
		TE_SendToAll();
	}
	
	CreateTimer(0.1, SetCvars);
	
	if(b_GiveAnotherBall)
		CreateTimer(fl_TimeToGiveSnowball, GiveDecoy, client);
}

public Action SetCvars(Handle tmr, any client)
{
	SetCvar("sv_ignoregrenaderadio", "0");
}

public void OnClientPutInServer(int client)
{
	if(!IsFakeClient(client))
	{
		SDKHook(client, SDKHook_WeaponSwitchPost, 	OnClientWeaponSwitchPost); 
		SendProxy_Hook(client, "m_flNextAttack", Prop_Float, ProxyCallback);
	}
}

public void OnClientWeaponSwitchPost(int client, int weapon) 
{ 
	if(IsClientInGame(client) && IsPlayerAlive(client) && !IsFakeClient(client) && b_PluginEnable)
	{
		char classname[120];
		GetEntityClassname(weapon, classname, 120);
		if(StrEqual(classname, "weapon_decoy"))
		{
			g_PVMid[client] = Weapon_GetViewModelIndex2(client, -1); 
			if(g_PVMid[client] > 0)
			{
				SetEntProp(g_PVMid[client], Prop_Send, "m_nModelIndex", g_iSMGModel);	
				int clientview = EntRefToEntIndex(g_PVMid[client]);	
				SetEntProp(clientview, Prop_Send, "m_nSequence", 0);
			}
		}
	}	
}

public void OnGameFrame()
{
	if(b_OnlyWarmupEnable)
	{
		if(GameRules_GetProp("m_bWarmupPeriod") == 1)
		{
			b_PluginEnable = true;
		} else {
			b_PluginEnable = false;
		}
	}	
}


public StartTouch(int entity, int client) 
{
	if(b_PluginEnable)
	{
		int clients = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
		
		if(client > 0 && client < MaxClients + 1 && IsClientInGame(client) && IsPlayerAlive(client))
		{
			Call_StartForward(g_SnowBallHitPlayer);
			Call_PushCell(client);
			Call_PushCell(clients);
			Call_Finish();
	
			int armor = GetEntProp(client, Prop_Send, "m_ArmorValue");
			SetEntProp(client, Prop_Send, "m_ArmorValue", 0, 10);
	
			//Kill
			bool Kills = false;
			if(i_SnowballHitPlayer == 1)
			{
				Kills = true;
				DealDamage(client, GetClientHealth(client) + 2, clients, DMG_BULLET, "weapon_hegrenade");
			}
			
			//Freeze
			if(!Kills)
			{
				if(i_SnowballHitPlayer == 2 || i_SnowballHitPlayer == 4)
				{
					SetEntityMoveType(client, MOVETYPE_NONE);
					SetEntityRenderColor(client, 0, 128, 255, 192);
					float vec[3];
					GetClientEyePosition(client, vec);
					EmitAmbientSound("physics/glass/glass_impact_bullet4.wav", vec, client, SNDLEVEL_RAIDSIREN);
					CreateTimer(f_UnfreezeTime, UnfreezePlayer, client);
				}
				
				//Damage
				if(i_SnowballHitPlayer == 3 || i_SnowballHitPlayer == 4)
				{
					DealDamage(client, i_SnowballDamage, clients, DMG_BULLET, "weapon_hegrenade");
				}
			}
			
			
			if(IsPlayerAlive(client))
				SetEntProp(client, Prop_Send, "m_ArmorValue", armor, 10);
	
			
		}
	
		
		
		//Create snow particle
		int ent = CreateEntityByName("info_particle_system");
		float particleOrigin[3];
		GetEntPropVector(entity, Prop_Send, "m_vecOrigin", particleOrigin);
		DispatchKeyValue(ent , "start_active", "0");
		DispatchKeyValue(ent, "effect_name", "impact_snow_child_smoke_puff");
		DispatchSpawn(ent);
		TeleportEntity(ent , particleOrigin, f_LastThrowAng[clients] ,NULL_VECTOR);
		ActivateEntity(ent);
		AcceptEntityInput(ent, "Start");
		
		//Create snow decal
		CreatePaint(particleOrigin);
		
		//Unhook ball
		SDKUnhook(entity, SDKHook_StartTouch, StartTouch);
		
		//Kill ball entity
		AcceptEntityInput(entity, "kill");	
		
	}
}

public Action UnfreezePlayer(Handle tmr, any client)
{
	if(IsClientInGame(client))
	{
		if(IsPlayerAlive(client))
			SetEntityMoveType(client, MOVETYPE_WALK);	
		
		SetEntityRenderColor(client, 255, 255, 255, 255);
	}
}

public Action GiveDecoy(Handle tmr, any client)
{
	if(IsClientInGame(client) && IsPlayerAlive(client) && b_PluginEnable)
		GivePlayerItem(client, "weapon_decoy");
}

//GUBKA LOVE YOU! <3
int Weapon_GetViewModelIndex2(int client, int sIndex) 
{ 
    while ((sIndex = FindEntityByClassname2(sIndex, "predicted_viewmodel")) != -1) 
    { 
        int Owner = GetEntPropEnt(sIndex, Prop_Send, "m_hOwner"); 
        int ClientWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon"); 
        int Weapon = GetEntPropEnt(sIndex, Prop_Send, "m_hWeapon"); 
        
        if (Owner != client) 
            continue; 
         
        if (ClientWeapon != Weapon) 
            continue; 
         
        return sIndex; 
    } 
    return -1; 
} 

int FindEntityByClassname2(int sStartEnt, char[] szClassname) 
{ 
    while (sStartEnt > -1 && !IsValidEntity(sStartEnt)) sStartEnt--; 
    return FindEntityByClassname(sStartEnt, szClassname); 
}  

bool HasGrenadeInHands(int client)
{
	int weapon 	= GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
	if(weapon > 0 && IsValidEntity(weapon))
	{
		char weaponName[64];
		GetEntityClassname(weapon, weaponName, sizeof(weaponName));
		
		if(StrContains(weaponName, "decoy") != -1){ 
			return true;
		}
	}
	return false;
}

public void CreatePaint(float coords[3]) 
{

	int precacheId = PrecacheDecal("snowball/snowball", true);
	
	TE_SetupBSPDecal(coords, precacheId);
	TE_SendToAll();

}

void TE_SetupBSPDecal(const float vecOrigin[3], int index2) {
	TE_Start("World Decal");
	TE_WriteVector("m_vecOrigin",vecOrigin);
	TE_WriteNum("m_nIndex",index2);
}

public Action RemoveParticle(Handle timer, any particle)
{
    if(IsValidEdict(particle))
    {
        AcceptEntityInput(particle, "Deactivate");
        AcceptEntityInput(particle, "Kill");
    }
}

void SetCvar(char[] scvar, char[] svalue)
{
	Handle cvar = FindConVar(scvar);
	SetConVarString(cvar, svalue, true);
}

void DealDamage(int nClientVictim, int nDamage, int nClientAttacker = 0, int nDamageType = DMG_GENERIC, char[] sWeapon = "")
{
    if(nClientVictim > 0 && IsValidEntity(nClientVictim) && IsClientInGame(nClientVictim) && nDamage > 0) {
	    int EntityPointHurt = CreateEntityByName("point_hurt");
	    if(EntityPointHurt != 0)
	    {
            char sDamage[16];
            IntToString(nDamage, sDamage, sizeof(sDamage));

            char sDamageType[32];
            IntToString(nDamageType, sDamageType, sizeof(sDamageType));

            DispatchKeyValue(nClientVictim,                 "targetname",           "war3_hurtme");
            DispatchKeyValue(EntityPointHurt,               "DamageTarget", "war3_hurtme");
            DispatchKeyValue(EntityPointHurt,               "Damage",                               sDamage);
            DispatchKeyValue(EntityPointHurt,               "DamageType",           sDamageType);
            if(!StrEqual(sWeapon, ""))
                    DispatchKeyValue(EntityPointHurt,       "classname",            sWeapon);
            DispatchSpawn(EntityPointHurt);
            AcceptEntityInput(EntityPointHurt,      "Hurt",                                 (nClientAttacker != 0) ? nClientAttacker : -1);
            DispatchKeyValue(EntityPointHurt,               "classname",            "point_hurt");
            DispatchKeyValue(nClientVictim,                 "targetname",           "war3_donthurtme");

            RemoveEdict(EntityPointHurt);
	    }
    }
}
Help me, please

Last edited by jugule; 05-27-2020 at 23:42.
jugule is offline
jugule
Member
Join Date: Apr 2020
Old 06-02-2020 , 00:46   Re: Snowball plugin problem
Reply With Quote #2

not solved

Last edited by jugule; 06-02-2020 at 00:47.
jugule is offline
BOT Benson
Member
Join Date: Jun 2018
Location: Istanbul, Turkey
Old 06-02-2020 , 07:48   Re: Snowball plugin problem
Reply With Quote #3

Quote:
Originally Posted by jugule View Post
not solved
why don't you use weapon_snowball?
__________________
BOT Benson is offline
jugule
Member
Join Date: Apr 2020
Old 06-07-2020 , 09:19   Re: Snowball plugin problem
Reply With Quote #4

Quote:
Originally Posted by BOT Benson View Post
why don't you use weapon_snowball?
I didn't know it existed, thank you very much!
jugule is offline
Reply


Thread Tools
Display Modes

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 01:41.


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