PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
#pragma semicolon 1
#pragma newdecls required
#define HIDE_RADAR_CSGO 1<<12
#define ChickenModel "models/chicken/chicken.mdl"
bool RevivedAsChicken[MAXPLAYERS+1];
Handle ReviveAsChickenTimer[MAXPLAYERS+1];
ConVar ChickenUse, ChickenTP, ChickenHealth, ChickenRespawn, ChickenGravity, ChickenSpeed, ChickenNoCollusion;
public void OnPluginStart()
{
ChickenNoCollusion = CreateConVar("sm_chicken_nocollusion", "1", "Disbles collusions between chickens and normal players. 1 - on, 0 - off", 0, true, 0.0, true, 1.0);
ChickenUse = CreateConVar("sm_chicken_use", "1", "Disables '+use' for chickens. 1 - yes, 0 - no.", 0, true, 0.0, true, 1.0);
ChickenTP = CreateConVar("sm_chicken_thirdperson", "0", "1 - Chichens will be in thirdperson, 0 - Chichens will be in firstperson.", 0, true, 0.0, true, 1.0);
ChickenHealth = CreateConVar("sm_chicken_health", "250", "Chicken Health", 0, true, 0.0, false, 2.0);
ChickenRespawn = CreateConVar("sm_chicken_respawn_time", "40.0", "Time after death for respawn", 0, true, 0.1, false, 1.0);
ChickenGravity = CreateConVar("sm_chicken_gravity", "0.1", "0,1 = 100, 0,2 = 200, etc.", 0, true, 0.1, false, 1.0);
ChickenSpeed = CreateConVar("sm_chicken_speed", "2.5", "1.0 - normal speed", 0, true, 0.1, false, 1.0);
HookEvent("player_spawn", PlayerSpawn);
HookEvent("player_death", PlayerDeath);
HookEvent("round_end", RoundEnd);
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i)) OnClientPutInServer(i);
}
}
public void OnMapStart()
{
PrecacheModel(ChickenModel);
AddFileToDownloadsTable("materials/models/props_farm/chicken_white.vmt");
AddFileToDownloadsTable("materials/models/props_farm/chicken_white.vtf");
AddFileToDownloadsTable("models/chicken/chicken.dx90.vtx");
AddFileToDownloadsTable("models/chicken/chicken.phy");
AddFileToDownloadsTable("models/chicken/chicken.vvd");
AddFileToDownloadsTable("models/chicken/chicken.mdl");
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_WeaponEquip, OnWeaponEquip);
SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);
SDKHook(client, SDKHook_StartTouch, OnPlayerTouch);
RevivedAsChicken[client] = false;
}
public void OnClientDisconnect(int client)
{
SDKUnhook(client, SDKHook_WeaponEquip, OnWeaponEquip);
SDKUnhook(client, SDKHook_OnTakeDamageAlive, OnTakeDamage);
if (ReviveAsChickenTimer[client] != null)
{
KillTimer(ReviveAsChickenTimer[client]);
ReviveAsChickenTimer[client] = null;
}
}
//*******************************************************//
// EVENTS //
//*****************************************************//
public Action PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (ReviveAsChickenTimer[client] != null) //In case of an admin revives the player, before the time runs out. Or he's respawned in other ways.
{
KillTimer(ReviveAsChickenTimer[client]);
ReviveAsChickenTimer[client] = null;
}
if(ChickenTP.IntValue)
{
FirstPerson(client);
}
if (RevivedAsChicken[client])
{
SetEntProp(client, Prop_Send, "m_lifeState", 1);
Client_RemoveAllWeapons(client, "", true);
SetEntProp(client, Prop_Send, "m_iHideHUD", GetEntProp(client, Prop_Send, "m_iHideHUD") | HIDE_RADAR_CSGO);
SetEntProp(client, Prop_Data, "m_takedamage", 0, 1);
SetEntityModel(client, ChickenModel);
SetEntityHealth(client, ChickenHealth.IntValue);
SetGravity(client, ChickenGravity.FloatValue);
SetSpeed(client, ChickenSpeed.FloatValue);
return Plugin_Handled;
}
SetEntProp(client, Prop_Data, "m_takedamage", 2, 1);
SetEntProp(client, Prop_Send, "m_iHideHUD", GetEntProp(client, Prop_Send, "m_iHideHUD") & ~HIDE_RADAR_CSGO);
SetGravity(client, 1.0);
SetSpeed(client, 1.0);
return Plugin_Continue;
}
public Action PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!RevivedAsChicken[client])
{
ReviveAsChickenTimer[client] = CreateTimer(ChickenRespawn.FloatValue, RevivePlayerAsChicken, GetClientUserId(client));
}
}
public Action RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && RevivedAsChicken[i])
{
RevivedAsChicken[i] = false;
}
if (ReviveAsChickenTimer[i] != null)
{
KillTimer(ReviveAsChickenTimer[i]);
ReviveAsChickenTimer[i] = null;
}
}
}
public Action RevivePlayerAsChicken(Handle timer, any userid)
{
int client = GetClientOfUserId(userid);
if(client == 0) return;
RevivedAsChicken[client] = true;
CS_RespawnPlayer(client);
}
//*******************************************************//
// ACTIONS //
//*****************************************************//
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if(RevivedAsChicken[client] && ChickenUse.IntValue)
{
buttons = buttons &= ~IN_USE;
return Plugin_Changed;
}
return Plugin_Continue;
}
public Action OnWeaponEquip(int client, int weapon)
{
char weaponname[32];
GetEdictClassname(weapon, weaponname, sizeof(weaponname));
if(RevivedAsChicken[client] && !StrEqual(weaponname, "weapon_knife"))
{
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if(RevivedAsChicken[attacker])
{
damage = 0.0;
return Plugin_Handled;
}
return Plugin_Continue;
}
//*******************************************************//
// VOIDS //
//*****************************************************//
public void OnPlayerTouch(int client, int ent)
{
if(RevivedAsChicken[client] && ChickenNoCollusion.IntValue && IsValidClient(client))
{
SetEntProp(client, Prop_Data, "m_CollisionGroup", (0 < ent <= MaxClients) ? 2 : 5);
}
}
public void SetSpeed(int client, float speed)
{
SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", speed);
}
public void SetGravity(int client, float amount)
{
SetEntityGravity(client, amount / GetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue"));
}
void FirstPerson(int client)
{
if (IsValidClient(client) && RevivedAsChicken[client])
{
ClientCommand(client, "firstperson");
}
else
{
ClientCommand(client, "thirdperson");
}
}
stock bool IsValidClient(int client)
{
return (1 <= client <= MaxClients && IsClientInGame(client));
}