Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #define DEBUG
- #define PLUGIN_AUTHOR "Rachnus"
- #define PLUGIN_VERSION "1.3"
- #include <sourcemod>
- #include <sdktools>
- #include <cstrike>
- #include <sdkhooks>
- #include <emitsoundany>
- #include <ttt>
- #include <ttt_shop>
- #pragma newdecls required
- #define EXPLOSION_VOLUME 5.0
- #define PLUGIN_ITEM_SHORT "discom"
- EngineVersion g_Game;
- int g_PVMid[MAXPLAYERS + 1]; // Predicted ViewModel ID's
- bool g_bHasDiscombobulator[MAXPLAYERS+1];
- int g_iViewModelIndex;
- //GLOBAL
- ConVar g_cUseDecoyModel;
- ConVar g_cEnable;
- ConVar g_cFriendlyFire;
- //FORCE EXPLOSION
- ConVar g_cExplosionParticleEffect;
- ConVar g_cExplosionMinimumDistance;
- ConVar g_cExplosionForce;
- ConVar g_cExplosionProps;
- ConVar g_cExplosionWeapons;
- ConVar g_cExplosionGrenades;
- ConVar g_cExplosionFlashbangs;
- ConVar g_cExplosionSmokes;
- ConVar g_cExplosionBounce;
- ConVar g_cExplosionBounceVelocity;
- ConVar g_cExplosionPrice;
- ConVar g_cExplosionName;
- ConVar g_cDiscount = null;
- public Plugin myinfo =
- {
- name = "Futuristic Grenades",
- author = PLUGIN_AUTHOR,
- description = "Adds more modes for decoys grenades",
- version = PLUGIN_VERSION,
- url = "https://github.com/Rachnus"
- };
- public void OnPluginStart()
- {
- g_Game = GetEngineVersion();
- if(g_Game != Engine_CSGO)
- {
- SetFailState("This plugin is for CSGO only.");
- }
- HookEvent("player_spawn", Event_PlayerSpawn);
- //GENERAL CONVARS
- g_cUseDecoyModel = CreateConVar("fg_decoy_model", "0", "Whether or not to use custom model for decoy", FCVAR_NOTIFY);
- g_cEnable = CreateConVar("fg_cEnabled", "1", "Enable/Disable plugin", FCVAR_NOTIFY);
- g_cFriendlyFire = CreateConVar("fg_cFriendlyFire", "1", "Enable/Disable friendly fire", FCVAR_NOTIFY);
- //FORCE EXPLOSION CONVARS
- g_cExplosionParticleEffect = CreateConVar("fg_explosion_particle_effect", "explosion", "Name of the particle effect you want to use for force explosions", FCVAR_NOTIFY);
- g_cExplosionMinimumDistance = CreateConVar("fg_explosion_minimum_distance", "300", "Minimum distance to push player away from force explosions", FCVAR_NOTIFY);
- g_cExplosionForce = CreateConVar("fg_explosion_force", "800", "Force to push away from force explosions", FCVAR_NOTIFY);
- g_cExplosionProps = CreateConVar("fg_explosion_props", "1", "Push props away from force explosions", FCVAR_NOTIFY);
- g_cExplosionWeapons = CreateConVar("fg_explosion_weapons", "1", "Push dropped weapons away from force explosions", FCVAR_NOTIFY);
- g_cExplosionGrenades = CreateConVar("fg_explosion_hegrenades", "1", "Push active hand grenades away from force explosions", FCVAR_NOTIFY);
- g_cExplosionFlashbangs = CreateConVar("fg_explosion_flashbangs", "1", "Push active flashbangs away from force explosions", FCVAR_NOTIFY);
- g_cExplosionSmokes = CreateConVar("fg_explosion_smokes", "1", "Push active smoke grenades away from force explosions", FCVAR_NOTIFY);
- g_cExplosionBounce = CreateConVar("fg_explosion_bounce", "0", "Bounce the grenade before activating", FCVAR_NOTIFY);
- g_cExplosionBounceVelocity = CreateConVar("fg_explosion_bounce_velocity", "300", "Up/Down velocity to push the grenade on bounce (If fg_explosion_bounce enabled)", FCVAR_NOTIFY);
- g_cExplosionPrice = CreateConVar("fg_explosion_ttt_price", "5000", "Price of the black hole decoy");
- g_cExplosionName = CreateConVar("fg_explosion_ttt_name", "Discombobulator", "The name of the black hole in the shop");
- g_cDiscount = CreateConVar("ttt_discount", "1", "Should disco discountable?");
- HookConVarChange(g_cUseDecoyModel, ConVar_DecoyModel);
- for (int i = 1; i <= MaxClients;i++)
- {
- if(IsClientInGame(i) && !IsFakeClient(i))
- {
- SDKHook(i, SDKHook_WeaponSwitchPost, OnClientWeaponSwitchPost);
- g_PVMid[i] = Weapon_GetViewModelIndex(i, -1);
- }
- }
- AutoExecConfig(true);
- }
- public void OnConfigsExecuted()
- {
- if (TTT_IsLoaded())
- {
- char sName[64];
- g_cExplosionName.GetString(sName, sizeof(sName));
- int iPrice = g_cExplosionPrice.IntValue;
- TTT_RegisterCustomItem(PLUGIN_ITEM_SHORT, sName, iPrice, TTT_TEAM_TRAITOR, g_cDiscount.BoolValue);
- }
- }
- public Action TTT_OnItemPurchased(int client, const char[] item)
- {
- if (TTT_IsClientValid(client) && IsPlayerAlive(client) && (strcmp(item, PLUGIN_ITEM_SHORT) == 0))
- {
- if (g_bHasDiscombobulator[client])
- return Plugin_Stop;
- GiveDecoy(client);
- g_bHasDiscombobulator[client] = true;
- }
- return Plugin_Continue;
- }
- public void ConVar_DecoyModel(ConVar convar, const char[] oldValue, const char[] newValue)
- {
- if(convar.IntValue > 0)
- {
- for (int i = 1; i <= MaxClients;i++)
- {
- if(IsClientInGame(i) && !IsFakeClient(i))
- {
- g_PVMid[i] = Weapon_GetViewModelIndex(i, -1);
- }
- }
- }
- }
- void PushAwayFromExplosion(int entity, const char[] classname)
- {
- int iEnt = MaxClients + 1;
- while((iEnt = FindEntityByClassname(iEnt, classname)) != -1)
- {
- float propPos[3], entityPos[3];
- GetEntPropVector(iEnt, Prop_Send, "m_vecOrigin", propPos);
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", entityPos);
- entityPos[2] -= 30.0;
- float distance = GetVectorDistance(propPos, entityPos);
- if(distance < g_cExplosionMinimumDistance.FloatValue)
- {
- float direction[3];
- SubtractVectors(propPos, entityPos, direction);
- NormalizeVector(direction, direction);
- if (distance <= 20.0)
- distance = 20.0;
- ScaleVector(direction, g_cExplosionForce.FloatValue);
- float propVel[3];
- GetEntPropVector(iEnt, Prop_Data, "m_vecVelocity", propVel);
- AddVectors(propVel, direction, direction);
- TeleportEntity(iEnt, NULL_VECTOR, NULL_VECTOR, direction);
- }
- }
- }
- public void OnEntityCreated(int entity, const char[] classname)
- {
- if(!g_cEnable.BoolValue)
- return;
- if(StrEqual(classname, "decoy_projectile", false))
- {
- SDKHook(entity, SDKHook_SpawnPost, DecoySpawned);
- }
- }
- public Action DecoySpawned(int entity)
- {
- int client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
- if(TTT_IsClientValid(client) && g_bHasDiscombobulator[client])
- {
- g_bHasDiscombobulator[client] = false;
- SetEntPropString(entity, Prop_Data, "m_iName", "explosion");
- if(g_cUseDecoyModel.BoolValue)
- SetEntityModel(entity, "models/weapons/futuristicgrenades/w_eq_decoy.mdl");
- SDKHook(entity, SDKHook_TouchPost, DecoyTouchPost);
- }
- return Plugin_Continue;
- }
- public Action DecoyTouchPost(int entity, int other)
- {
- char name[16];
- GetEntPropString(entity, Prop_Data, "m_iName", name, sizeof(name));
- if(StrEqual(name, "explosion", false))
- {
- float vecPos[3], startPoint[3], endPoint[3], slopeAngle[3];
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", vecPos);
- endPoint = vecPos;
- startPoint = vecPos;
- endPoint[2] = vecPos[2] - 5.0;
- Handle traceZ = TR_TraceRayFilterEx(startPoint, endPoint, MASK_PLAYERSOLID, RayType_EndPoint, TraceFilterNotSelf, entity);
- TR_GetPlaneNormal(traceZ, slopeAngle);
- endPoint = vecPos;
- startPoint = vecPos;
- startPoint[1] = vecPos[1] + 1.0;
- endPoint[1] = vecPos[1] - 1.0;
- Handle traceX = TR_TraceRayFilterEx(startPoint, endPoint, MASK_PLAYERSOLID, RayType_EndPoint, TraceFilterNotSelf, entity);
- endPoint = vecPos;
- startPoint = vecPos;
- startPoint[0] = vecPos[0] + 1.0;
- endPoint[0] = vecPos[0] - 1.0;
- Handle traceY = TR_TraceRayFilterEx(startPoint, endPoint, MASK_PLAYERSOLID, RayType_EndPoint, TraceFilterNotSelf, entity);
- if((TR_DidHit(traceZ) && !TR_DidHit(traceX) && !TR_DidHit(traceY)) || slopeAngle[2] > 0.5)
- RequestFrame(FrameCallback, entity);
- }
- }
- public void FrameCallback(any entity)
- {
- char entityName[16];
- GetEntPropString(entity, Prop_Data, "m_iName", entityName, sizeof(entityName));
- float vel[3] = { 0.0, 0.0, 300.0 };
- if(StrEqual(entityName, "explosion", false))
- {
- vel[2] = g_cExplosionBounceVelocity.FloatValue;
- if(g_cExplosionBounce.BoolValue)
- {
- TeleportEntity(entity, NULL_VECTOR, NULL_VECTOR, vel);
- CreateTimer(0.5, Timer_Decoy, entity);
- }
- else
- SpawnExplosion(entity);
- }
- SDKUnhook(entity, SDKHook_TouchPost, DecoyTouchPost);
- }
- public Action Timer_Decoy(Handle timer, any entity)
- {
- SpawnExplosion(entity);
- }
- void SpawnExplosion(int entity)
- {
- int owner = GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity");
- if(!TTT_IsClientValid(owner))
- return;
- char particleEffect[PLATFORM_MAX_PATH];
- float nadeOrigin[3];
- GetEntPropVector(entity, Prop_Send, "m_vecOrigin", nadeOrigin);
- AcceptEntityInput(entity, "Kill");
- int particle = CreateEntityByName("info_particle_system");
- g_cExplosionParticleEffect.GetString(particleEffect, sizeof(particleEffect));
- DispatchKeyValue(particle , "start_active", "0");
- DispatchKeyValue(particle , "effect_name", particleEffect);
- DispatchSpawn(particle);
- TeleportEntity(particle, nadeOrigin, NULL_VECTOR,NULL_VECTOR);
- ActivateEntity(particle);
- AcceptEntityInput(particle, "Start");
- EmitAmbientSoundAny("misc/futuristicgrenades/explosion.mp3", nadeOrigin, particle,_,_, EXPLOSION_VOLUME);
- for (int client = 1; client <= MaxClients; client++)
- {
- if(IsClientInGame(client) && IsPlayerAlive(client))
- {
- if(!g_cFriendlyFire.BoolValue)
- {
- int ownerteam = GetClientTeam(owner);
- if((ownerteam != GetClientTeam(client)) || client == owner)
- {
- float clientPos[3], explosionPos[3];
- GetClientAbsOrigin(client, clientPos);
- GetEntPropVector(particle, Prop_Send, "m_vecOrigin", explosionPos);
- clientPos[2] += 30.0;
- float distance = GetVectorDistance(clientPos, explosionPos);
- if(distance < g_cExplosionMinimumDistance.FloatValue)
- {
- SetEntPropEnt(client, Prop_Data, "m_hGroundEntity", -1);
- float direction[3];
- SubtractVectors(clientPos, explosionPos, direction);
- NormalizeVector(direction, direction);
- if (distance <= 20.0)
- distance = 20.0;
- ScaleVector(direction, g_cExplosionForce.FloatValue);
- float playerVel[3];
- GetEntPropVector(client, Prop_Data, "m_vecVelocity", playerVel);
- AddVectors(playerVel, direction, direction);
- TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, direction);
- }
- }
- }
- else
- {
- float clientPos[3], explosionPos[3];
- GetClientAbsOrigin(client, clientPos);
- GetEntPropVector(particle, Prop_Send, "m_vecOrigin", explosionPos);
- if(GetEntPropEnt(client, Prop_Data, "m_hGroundEntity") != -1)
- explosionPos[2] -= 30.0;
- float distance = GetVectorDistance(clientPos, explosionPos);
- if(distance < g_cExplosionMinimumDistance.FloatValue)
- {
- SetEntPropEnt(client, Prop_Data, "m_hGroundEntity", -1);
- float direction[3];
- SubtractVectors(clientPos, explosionPos, direction);
- NormalizeVector(direction, direction);
- if (distance <= 20.0)
- distance = 20.0;
- ScaleVector(direction, g_cExplosionForce.FloatValue);
- float playerVel[3];
- GetEntPropVector(client, Prop_Data, "m_vecVelocity", playerVel);
- AddVectors(playerVel, direction, direction);
- TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, direction);
- }
- }
- }
- }
- if(g_cExplosionProps.BoolValue)
- PushAwayFromExplosion(particle, "prop_physics*");
- if(g_cExplosionWeapons.BoolValue)
- PushAwayFromExplosion(particle, "weapon_*");
- if(g_cExplosionGrenades.BoolValue)
- PushAwayFromExplosion(particle, "hegrenade_projectile");
- if(g_cExplosionFlashbangs.BoolValue)
- PushAwayFromExplosion(particle, "flashbang_projectile");
- if(g_cExplosionSmokes.BoolValue)
- PushAwayFromExplosion(particle, "smokegrenade_projectile");
- }
- public bool TraceFilterNotSelf(int entityhit, int mask, any entity)
- {
- if(entity == 0 && entityhit != entity)
- return true;
- return false;
- }
- public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
- {
- if(!g_cEnable.BoolValue)
- return Plugin_Continue;
- if(!g_cUseDecoyModel.BoolValue)
- return Plugin_Continue;
- int client = GetClientOfUserId(event.GetInt("userid"));
- g_PVMid[client] = Weapon_GetViewModelIndex(client, -1);
- return Plugin_Continue;
- }
- int Weapon_GetViewModelIndex(int client, int sIndex)
- {
- while ((sIndex = FindEntityByClassname2(sIndex, "predicted_viewmodel")) != -1)
- {
- int Owner = GetEntPropEnt(sIndex, Prop_Send, "m_hOwner");
- if (Owner != client)
- continue;
- return sIndex;
- }
- return -1;
- }
- // Get entity name
- int FindEntityByClassname2(int startEnt, char[] classname)
- {
- while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
- return FindEntityByClassname(startEnt, classname);
- }
- stock void AddMaterialsFromFolder(char path[PLATFORM_MAX_PATH])
- {
- DirectoryListing dir = OpenDirectory(path, true);
- if(dir != INVALID_HANDLE)
- {
- char buffer[PLATFORM_MAX_PATH];
- FileType type;
- while(dir.GetNext(buffer, PLATFORM_MAX_PATH, type))
- {
- if(type == FileType_File && ((StrContains(buffer, ".vmt", false) != -1) || (StrContains(buffer, ".vtf", false) != -1) && !(StrContains(buffer, ".ztmp", false) != -1)))
- {
- char fullPath[PLATFORM_MAX_PATH];
- Format(fullPath, sizeof(fullPath), "%s%s", path, buffer);
- if(g_cUseDecoyModel.BoolValue)
- AddFileToDownloadsTable(fullPath);
- if(!IsModelPrecached(fullPath))
- PrecacheModel(fullPath);
- }
- }
- }
- }
- public void OnClientWeaponSwitchPost(int client, int weaponid)
- {
- if(!g_cEnable.BoolValue)
- return;
- SetEntPropEnt(weaponid, Prop_Send, "m_hOwnerEntity", client);
- char weapon[64];
- GetEntityClassname(weaponid, weapon,sizeof(weapon));
- if(StrEqual(weapon, "weapon_decoy"))
- {
- if(!g_cUseDecoyModel.BoolValue)
- return;
- SetEntProp(weaponid, Prop_Send, "m_nModelIndex", 0);
- SetEntProp(g_PVMid[client], Prop_Send, "m_nModelIndex", g_iViewModelIndex);
- }
- }
- stock void PrecacheEffect(const char[] sEffectName)
- {
- static int table = INVALID_STRING_TABLE;
- if (table == INVALID_STRING_TABLE)
- {
- table = FindStringTable("EffectDispatch");
- }
- bool save = LockStringTables(false);
- AddToStringTable(table, sEffectName);
- LockStringTables(save);
- }
- stock void PrecacheParticleEffect(const char[] sEffectName)
- {
- static int table = INVALID_STRING_TABLE;
- if (table == INVALID_STRING_TABLE)
- {
- table = FindStringTable("ParticleEffectNames");
- }
- bool save = LockStringTables(false);
- AddToStringTable(table, sEffectName);
- LockStringTables(save);
- }
- public void OnClientPutInServer(int client)
- {
- SDKHook(client, SDKHook_WeaponSwitchPost, OnClientWeaponSwitchPost);
- }
- public void OnClientDisconnect(int client)
- {
- SDKUnhook(client, SDKHook_WeaponSwitchPost, OnClientWeaponSwitchPost);
- }
- public void OnMapStart()
- {
- //MATERIALS
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/electric1.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/electric1.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/conc_warp.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/conc_normal.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/conc_tint.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/star_noz.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/yellowflare_noz.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/effects/yellowflare.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_decals/snow_crater_1.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_decals/snow_crater_1.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/aircraft_white.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/aircraft_white.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/particle_flare_002.vtf");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/particle_flare_002_noz.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/particle_flare_004_nodepth.vmt");
- AddFileToDownloadsTable("materials/futuristicgrenades/particle/particle_flares/particle_flare_004.vtf");
- //PARTICLES
- AddFileToDownloadsTable("particles/futuristicgrenades/futuristicgrenades.pcf");
- //SOUND
- AddFileToDownloadsTable("sound/misc/futuristicgrenades/explosion.mp3");
- //Precaching
- PrecacheGeneric("particles/futuristicgrenades/futuristicgrenades.pcf",true);
- PrecacheModel("materials/futuristicgrenades/effects/electric1.vmt");
- PrecacheModel("materials/futuristicgrenades/effects/electric1.vtf");
- PrecacheModel("materials/futuristicgrenades/effects/conc_warp.vmt");
- PrecacheModel("materials/futuristicgrenades/effects/conc_normal.vtf");
- PrecacheModel("materials/futuristicgrenades/effects/conc_tint.vtf");
- PrecacheModel("materials/futuristicgrenades/effects/star_noz.vmt");
- PrecacheModel("materials/futuristicgrenades/effects/yellowflare_noz.vmt");
- PrecacheModel("materials/futuristicgrenades/effects/yellowflare.vtf");
- PrecacheModel("materials/futuristicgrenades/particle/particle_decals/snow_crater_1.vmt");
- PrecacheModel("materials/futuristicgrenades/particle/particle_decals/snow_crater_1.vtf");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/aircraft_white.vmt");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/aircraft_white.vtf");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/particle_flare_002.vtf");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/particle_flare_002_noz.vmt");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/particle_flare_004_nodepth.vmt");
- PrecacheModel("materials/futuristicgrenades/particle/particle_flares/particle_flare_004.vtf");
- PrecacheEffect("ParticleEffect");
- PrecacheParticleEffect("futuristicgrenades");
- PrecacheSoundAny("misc/futuristicgrenades/explosion.mp3", true);
- PrecacheSoundAny("buttons/button15.wav", true);
- }
- void GiveDecoy(int client) {
- int AmmoReserve = GetEntProp(client, Prop_Send, "m_iAmmo", 4, 15);
- if (!AmmoReserve)
- {
- GivePlayerItem(client, "weapon_decoy");
- }
- if (AmmoReserve)
- {
- SetEntProp(client, Prop_Send, "m_iAmmo", ++AmmoReserve, 4, 15);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement