Member
Join Date: Feb 2016
Location: bulgaria
|
05-22-2017
, 16:16
Re: [SourceMod] HitAndRun Plugin.
|
#9
|
Quote:
Originally Posted by shavit
An ugly, poorly written code. But I was 13 years old so.. whatever.
Made for CS:S, I don't know if it works for CS:GO nor did I test it.
Have fun.
Change the audio files' paths to something else.
|
ohh, ty very much its possible to add to this plugin a countdown timer in hud when a player got infected ? like in the video ? :-Z (using the new csgo hud)
ty very much guys for your help.
something like that:
if someone can do it its can be very nice, ty
add to this code: https://pastebin.com/sApBPcuT
Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <morecolors>
#include <smlib>
#undef REQUIRE_EXTENSIONS
#include <steamtools>
#pragma semicolon 1
new String:PREFIX[] = "{cyan}[Hit N Run]{default}";
new String:gS_Music[][] = {"clock_sound.mp3", "infected2.wav", "loser.wav", "winsound1.mp3", "winsound2.mp3", "winsound3.mp3", "winsound4.mp3", "winsound5.mp3", "winsound6.mp3", "winsound7.mp3"};
new Handle:gH_Restart_Timer = INVALID_HANDLE;
new Handle:gH_Infection_Timer = INVALID_HANDLE;
new Handle:gH_Infection_Timer2 = INVALID_HANDLE;
new Handle:gH_Enabled = INVALID_HANDLE;
new bool:gB_Enabled;
new gI_Offset_Ammo = -1;
new gI_Infected = -1;
new gI_HaloSprite = -1;
new gI_BeamSprite = -1;
new bool:gB_Allow_Respawn;
new bool:gB_Someone_Won;
public Plugin:myinfo =
{
name = "Hit N Run",
author = "ml/shavit & Hyuna (Roy) for sounds",
description = "Hit N Run plugin for CS:S.",
version = "1.0.2",
url = "-none-"
}
public OnPluginStart()
{
AddCommandListener(Command_Block, "explode");
AddCommandListener(Command_Block, "jointeam");
AddCommandListener(Command_Block, "kill");
AddCommandListener(Command_Block, "drop");
AddCommandListener(Command_Block, "buy");
AddCommandListener(Command_Block, "rebuy");
AddCommandListener(Command_Block, "autobuy");
AddCommandListener(Command_Jointeam, "jointeam");
gH_Enabled = CreateConVar("sm_hitnrun_enabled", "1", "Hit N Run is enabled?", FCVAR_PLUGIN|FCVAR_NOTIFY, true, 0.0, true, 1.0);
gB_Enabled = GetConVarBool(gH_Enabled);
HookConVarChange(gH_Enabled, OnConVarChanged);
if(gB_Enabled)
{
SetConVarString(FindConVar("mp_humanteam"), "T");
SetConVarInt(FindConVar("mp_friendlyfire"), 1);
SetConVarInt(FindConVar("mp_limitteams"), 0);
SetConVarInt(FindConVar("sv_ignoregrenaderadio"), 1);
}
else
{
SetConVarString(FindConVar("mp_humanteam"), "any");
SetConVarInt(FindConVar("mp_friendlyfire"), 0);
SetConVarInt(FindConVar("sv_ignoregrenaderadio"), 0);
}
RegAdminCmd("sm_reload_hnr", Command_Reload, ADMFLAG_GENERIC, "Reload Hit N Run");
HookEvent("player_spawn", Player_Spawn);
HookEvent("weapon_fire", Weapon_Fire);
HookEvent("round_start", Round_Start, EventHookMode_Pre);
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
OnClientPutInServer(i);
}
}
gI_Offset_Ammo = FindSendPropInfo("CCSPlayer", "m_iAmmo");
if(gI_Offset_Ammo == -1)
{
SetFailState("Unable to find offset for ammo.");
}
CreateTimer(0.25, Timer_Beacon, INVALID_HANDLE, TIMER_REPEAT);
CreateTimer(10.0, Timer_Restart, INVALID_HANDLE, TIMER_REPEAT);
gB_Allow_Respawn = true;
gB_Someone_Won = false;
}
public OnMapStart()
{
gI_BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
gI_HaloSprite = PrecacheModel("materials/sprites/glow01.vmt", true);
decl String:File[128];
for(new i; i < sizeof(gS_Music); i++)
{
Format(File, 128, "hit_n_run/%s", gS_Music[i]);
PrecacheSound(File, true);
Format(File, 128, "sound/%s", File);
AddFileToDownloadsTable(File);
}
gH_Infection_Timer = INVALID_HANDLE;
gH_Infection_Timer2 = INVALID_HANDLE;
}
public OnConVarChanged(Handle:ConVar, const String:OldVal[], const String:NewVal[])
{
if(ConVar == gH_Enabled)
{
gB_Enabled = bool:StringToInt(NewVal);
if(gB_Enabled)
{
SetConVarString(FindConVar("mp_humanteam"), "T");
SetConVarInt(FindConVar("mp_friendlyfire"), 1);
SetConVarInt(FindConVar("mp_limitteams"), 0);
SetConVarInt(FindConVar("sv_ignoregrenaderadio"), 1);
}
else
{
SetConVarString(FindConVar("mp_humanteam"), "any");
SetConVarInt(FindConVar("mp_friendlyfire"), 0);
SetConVarInt(FindConVar("sv_ignoregrenaderadio"), 0);
}
}
}
public Action:Command_Reload(client, args)
{
ServerCommand("sm plugins reload hitnrun");
return Plugin_Handled;
}
public Action:OnPlayerRunCmd(client, &buttons)
{
if(!IsValidClient(client, true) || !gB_Enabled)
{
return Plugin_Continue;
}
decl String:weapon[32];
GetClientWeapon(client, weapon, 32);
if(buttons & IN_ATTACK)
{
if(!(StrEqual(weapon, "weapon_knife") || StrEqual(weapon, "weapon_scout") || StrContains(weapon, "gren") != -1 || StrContains(weapon, "smoke") != -1 || StrContains(weapon, "flash") != -1))
{
buttons &= ~IN_ATTACK;
return Plugin_Changed;
}
}
return Plugin_Continue;
}
public OnClientDisconnect(client)
{
if(gI_Infected == client)
{
if(!gB_Someone_Won)
{
if(gH_Infection_Timer != INVALID_HANDLE)
{
CloseHandle(gH_Infection_Timer);
gH_Infection_Timer = INVALID_HANDLE;
}
Kill_Infection(INVALID_HANDLE);
gH_Infection_Timer = CreateTimer(20.0, Kill_Infection, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
}
}
public OnClientPutInServer(client)
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
SDKHook(client, SDKHook_ThinkPost, ThinkPost);
}
public ThinkPost(client)
{
if(IsValidClient(client, true))
{
SetEntProp(client, Prop_Send, "m_bSpotted", 0);
}
}
public Action:OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
if(!gB_Enabled)
{
return Plugin_Continue;
}
if(attacker == gI_Infected && victim != gI_Infected)
{
SetEntityRenderMode(attacker, RENDER_NORMAL);
SetEntityRenderColor(attacker);
gI_Infected = victim;
SetEntityRenderMode(victim, RENDER_TRANSALPHA);
SetEntityRenderColor(victim, GetRandomInt(1, 255), GetRandomInt(1, 255), GetRandomInt(1, 255));
CPrintToChatAllEx(victim, "%s {teamcolor}%N{default} has infected {teamcolor}%N{default}.", PREFIX, attacker, victim);
EmitSoundToClient(victim, "hit_n_run/infected2.wav");
}
return Plugin_Handled;
}
public Action:Command_Block(client, const String:command[], args)
{
if(StrEqual(command, "jointeam"))
{
if(IsValidClient(client) && GetClientTeam(client) != CS_TEAM_T)
{
return Plugin_Continue;
}
}
if(gB_Enabled)
{
return Plugin_Handled;
}
if(StrEqual(command, "kill") || StrEqual(command, "explode"))
{
if(!IsValidClient(client) || GetClientTeam(client) != CS_TEAM_T)
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:WeaponCanUse(client, weapon)
{
if(gB_Enabled)
{
decl String:Weapon[32];
GetEntityClassname(weapon, Weapon, 32);
if(!(StrEqual(Weapon, "weapon_knife") || StrEqual(Weapon, "weapon_scout") || StrContains(Weapon, "gren") != -1 || StrContains(Weapon, "smoke") != -1 || StrContains(Weapon, "flash") != -1))
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:Player_Spawn(Handle:Event, const String:Name[], bool:DontBroadcast)
{
if(!gB_Enabled)
{
return Plugin_Continue;
}
new client = GetClientOfUserId(GetEventInt(Event, "userid"));
if(!IsValidClient(client))
{
return Plugin_Continue;
}
CreateTimer(0.1, KillLate, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
SetEntityRenderMode(client, RENDER_NORMAL);
SetEntityRenderColor(client);
if(GetClientTeam(client) == CS_TEAM_T)
{
GivePlayerItem(client, "weapon_scout");
GivePlayerItem(client, "weapon_hegrenade");
GivePlayerItem(client, "weapon_flashbang");
GivePlayerItem(client, "weapon_smokegrenade");
}
return Plugin_Continue;
}
public Action:GiveWeapons(Handle:Timer, any:serial)
{
new client = GetClientFromSerial(serial);
if(!IsValidClient(client, true))
{
return Plugin_Handled;
}
return Plugin_Handled;
}
public Action:Weapon_Fire(Handle:Event, const String:Name[], bool:DontBroadcast)
{
if(!gB_Enabled)
{
return Plugin_Continue;
}
new client = GetClientOfUserId(GetEventInt(Event, "userid"));
if(!IsValidClient(client, true))
{
return Plugin_Continue;
}
new Weapon = GetPlayerWeaponSlot(client, CS_SLOT_PRIMARY);
decl String:sWeapon[32];
GetClientWeapon(client, sWeapon, 32);
if(!StrEqual(sWeapon, "weapon_scout"))
{
return Plugin_Continue;
}
SetEntData(client, gI_Offset_Ammo + (GetEntProp(Weapon, Prop_Send, "m_iPrimaryAmmoType") * 4), 9999, 4, true);
return Plugin_Continue;
}
public Action:Round_Start(Handle:Event, const String:Name[], bool:DontBroadcast)
{
if(!gB_Enabled)
{
return Plugin_Continue;
}
gB_Allow_Respawn = true;
gB_Someone_Won = false;
gI_Infected = -1;
if(gH_Infection_Timer2 != INVALID_HANDLE)
{
CloseHandle(gH_Infection_Timer2);
gH_Infection_Timer2 = INVALID_HANDLE;
}
if(gH_Infection_Timer != INVALID_HANDLE)
{
CloseHandle(gH_Infection_Timer);
gH_Infection_Timer = INVALID_HANDLE;
}
if(gH_Restart_Timer != INVALID_HANDLE)
{
CloseHandle(gH_Restart_Timer);
gH_Restart_Timer = INVALID_HANDLE;
}
CPrintToChatAll("%s The infected player will get back from the hospital in {khaki}10{default} seconds.", PREFIX);
gH_Infection_Timer2 = CreateTimer(10.0, Infection, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Continue;
}
public Action:Infection(Handle:Timer)
{
gB_Allow_Respawn = false;
if(gH_Infection_Timer != INVALID_HANDLE)
{
CloseHandle(gH_Infection_Timer);
}
gH_Infection_Timer = INVALID_HANDLE;
gH_Infection_Timer2 = INVALID_HANDLE;
gI_Infected = GetRandomPlayer();
if(gI_Infected == -1 || !IsValidClient(gI_Infected, true))
{
return Plugin_Stop;
}
new Count = 0;
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true))
{
Count++;
}
}
if(Count <= 1)
{
return Plugin_Stop;
}
EmitSoundToClient(gI_Infected, "hit_n_run/infected2.wav");
PrintCenterTextAll("%N is infected with the sickness!", gI_Infected);
PrintHintTextToAll("%N is infected with the sickness!", gI_Infected);
CPrintToChatAllEx(gI_Infected, "%s {teamcolor}%N{default} is infected with the sickness!", PREFIX, gI_Infected);
CPrintToChatEx(gI_Infected, gI_Infected, "%s {teamcolor}%N{default}, you are infected! Spread this sickness by {khaki}shooting your teammates{default}.", PREFIX, gI_Infected);
CPrintToChatAll("%s The infected player {valve}MUST{default} transfer his sickness in 20 seconds or he will die.", PREFIX);
PlayForAll("hit_n_run/clock_sound.mp3");
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true) && i != gI_Infected)
{
SetEntityRenderMode(i, RENDER_NORMAL);
}
}
SetEntityRenderMode(gI_Infected, RENDER_TRANSALPHA);
SetEntityRenderColor(gI_Infected, GetRandomInt(1, 255), GetRandomInt(1, 255), GetRandomInt(1, 255));
gH_Infection_Timer = CreateTimer(20.0, Kill_Infection, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
return Plugin_Stop;
}
public Action:Kill_Infection(Handle:Timer)
{
if(WinnerCheck())
{
gH_Infection_Timer = INVALID_HANDLE;
return Plugin_Stop;
}
if(IsValidClient(gI_Infected, true))
{
ForcePlayerSuicide(gI_Infected);
EmitSoundToClient(gI_Infected, "hit_n_run/loser.wav");
}
else
{
gI_Infected = GetRandomPlayer();
}
if(WinnerCheck())
{
gH_Infection_Timer = INVALID_HANDLE;
return Plugin_Stop;
}
gI_Infected = GetRandomPlayer();
EmitSoundToClient(gI_Infected, "hit_n_run/infected2.wav");
PrintCenterTextAll("%N is infected with the sickness!", gI_Infected);
PrintHintTextToAll("%N is infected with the sickness!", gI_Infected);
CPrintToChatAllEx(gI_Infected, "%s {teamcolor}%N{default} is infected with the sickness!", PREFIX, gI_Infected);
CPrintToChatEx(gI_Infected, gI_Infected, "%s {teamcolor}%N{default}, you are infected! Spread this sickness by {khaki}shooting your teammates{default}.", PREFIX, gI_Infected);
CPrintToChatAll("%s The infected player {valve}MUST{default} transfer his sickness in 20 seconds or he will die.", PREFIX);
PlayForAll("hit_n_run/clock_sound.mp3");
if(IsValidClient(gI_Infected, true))
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true))
{
if(i != gI_Infected)
{
SetEntityRenderMode(gI_Infected, RENDER_TRANSALPHA);
SetEntityRenderColor(gI_Infected, GetRandomInt(1, 255), GetRandomInt(1, 255), GetRandomInt(1, 255));
}
}
}
SetEntityRenderMode(gI_Infected, RENDER_TRANSALPHA);
SetEntityRenderColor(gI_Infected, GetRandomInt(1, 255), GetRandomInt(1, 255), GetRandomInt(1, 255));
}
return Plugin_Continue;
}
stock bool:WinnerCheck()
{
new Count = 0;
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true))
{
Count++;
}
}
if(Count <= 1)
{
CreateTimer(1.5, Winner);
return true;
}
return false;
}
public Action:Winner(Handle:Timer)
{
gI_Infected = GetRandomPlayer();
if(gI_Infected == -1)
{
return Plugin_Stop;
}
gB_Someone_Won = true;
PrintCenterTextAll("%N is the winner!", gI_Infected);
PrintHintTextToAll("%N is the winner!", gI_Infected);
CPrintToChatAllEx(gI_Infected, "%s {teamcolor}%N{selfmade} is the winner!", PREFIX, gI_Infected);
new Float:Time = 0.0;
decl String:MusicFile[128];
new Song = Math_GetRandomInt(1, 7);
Format(MusicFile, 128, "hit_n_run/winsound%d.mp3", Song);
if(Song == 6)
{
Song = 7;
Format(MusicFile, 128, "hit_n_run/winsound7.mp3", Song);
}
PlayForAll(MusicFile);
switch(Song)
{
case 1: Time = 28.0;
case 2: Time = 25.0;
case 3: Time = 18.0;
case 4: Time = 17.0;
case 5: Time = 19.5;
case 7: Time = 22.0;
}
CreateTimer(Time, Restart);
return Plugin_Handled;
}
public Action:Restart(Handle:Timer)
{
CS_TerminateRound(0.0, CSRoundEnd_VIPEscaped);
return Plugin_Handled;
}
public Action:Timer_Beacon(Handle:Timer)
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true))
{
if(i == gI_Infected)
{
new Float:vec[3];
GetClientAbsOrigin(i, vec);
vec[2] += 10;
new Color[4];
Color[0] = GetRandomInt(1, 255);
Color[1] = GetRandomInt(1, 255);
Color[2] = GetRandomInt(1, 255);
Color[3] = GetRandomInt(150, 255);
TE_SetupBeamRingPoint(vec, 10.0, 50.0, gI_BeamSprite, gI_HaloSprite, 0, 15, 0.5, 5.0, 0.0, Color, 10, 0);
TE_SendToAll();
}
}
}
if(LibraryExists("SteamTools"))
{
Steam_SetGameDescription("CS:S - Hit N Run");
}
return Plugin_Continue;
}
public OnEntityCreated(entity, const String:classname[])
{
if(IsValidEntity(entity) && IsValidEdict(entity))
{
if(StrEqual(classname, "func_buyzone") || StrContains(classname, "func_bombsite"))
{
SDKHook(entity, SDKHook_Spawn, OnSpawn);
}
}
}
public Action:OnSpawn(entity)
{
AcceptEntityInput(entity, "Disable");
return Plugin_Continue;
}
public Action:Command_Jointeam(client, const String:command[], args)
{
if(gB_Enabled)
{
decl String:arg1[32];
GetCmdArgString(arg1, 32);
TrimString(arg1);
StripQuotes(arg1);
if(arg1[0] != '2')
{
FakeClientCommand(client, "jointeam 2");
}
}
return Plugin_Continue;
}
public Action:Timer_Restart(Handle:Timer)
{
new Count = 0;
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetClientTeam(i) != CS_TEAM_NONE && GetClientTeam(i) != CS_TEAM_SPECTATOR)
{
Count++;
}
}
if(Count <= 1)
{
CPrintToChatAll("%s No players are available to play Hit N Run, restarting the game!", PREFIX);
SetConVarInt(FindConVar("mp_restartgame"), 1);
}
return Plugin_Continue;
}
public Action:KillLate(Handle:Timer, any:serial)
{
new client = GetClientFromSerial(serial);
if(!IsValidClient(client, true))
{
return Plugin_Handled;
}
Client_HideRadar(client);
if(!gB_Allow_Respawn || gB_Someone_Won)
{
ForcePlayerSuicide(client);
CPrintToChatEx(client, client, "%s Sorry {teamcolor}%N{default}, I killed you because you came too late.", PREFIX, client);
}
return Plugin_Handled;
}
void:Client_HideRadar(client)
{
SetEntPropFloat(client, Prop_Send, "m_flFlashDuration", 3600.0);
SetEntPropFloat(client, Prop_Send, "m_flFlashMaxAlpha", 0.5);
}
stock bool:IsValidClient(client, bool:alive = false)
{
return bool:(client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)));
}
stock GetRandomPlayer()
{
new clients[MaxClients+1];
new Count;
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i, true) && (GetClientTeam(i) == CS_TEAM_T))
{
clients[Count++] = i;
}
}
return (Count == 0)? -1:clients[GetRandomInt(0, Count - 1)];
}
stock PlayForAll(const String:Sound[])
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
EmitSoundToClient(i, Sound);
}
}
}
@shavit
Last edited by g00gl3; 05-22-2017 at 16:54.
|
|