View Single Post
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 03-27-2018 , 01:32   Re: [ CSGO ] dead players respawn as chicken
Reply With Quote #9

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 ChickenUseChickenTPChickenHealthChickenRespawnChickenGravityChickenSpeedChickenNoCollusion;

public 
void OnPluginStart()
{
    
ChickenNoCollusion CreateConVar("sm_chicken_nocollusion""1""Disbles collusions between chickens and normal players. 1 - on, 0 - off"0true0.0true1.0);
    
ChickenUse CreateConVar("sm_chicken_use""1""Disables '+use' for chickens. 1 - yes, 0 - no."0true0.0true1.0);
    
ChickenTP CreateConVar("sm_chicken_thirdperson""0""1 - Chichens will be in thirdperson, 0 - Chichens will be in firstperson."0true0.0true1.0);
    
ChickenHealth CreateConVar("sm_chicken_health""250""Chicken Health"0true0.0false2.0);
    
ChickenRespawn CreateConVar("sm_chicken_respawn_time""40.0""Time after death for respawn"0true0.1false1.0);
    
ChickenGravity CreateConVar("sm_chicken_gravity""0.1""0,1 = 100, 0,2 = 200, etc."0true0.1false1.0);
    
ChickenSpeed CreateConVar("sm_chicken_speed""2.5""1.0 - normal speed"0true0.1false1.0);

    
HookEvent("player_spawn"PlayerSpawn);
    
HookEvent("player_death"PlayerDeath);
    
HookEvent("round_end"RoundEnd);

    for(
int i 1<= MaxClientsi++)
    {
        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(clientSDKHook_WeaponEquipOnWeaponEquip);
    
SDKHook(clientSDKHook_OnTakeDamageAliveOnTakeDamage);
    
SDKHook(clientSDKHook_StartTouchOnPlayerTouch);
    
RevivedAsChicken[client] = false;
}

public 
void OnClientDisconnect(int client)
{
    
SDKUnhook(clientSDKHook_WeaponEquipOnWeaponEquip);
    
SDKUnhook(clientSDKHook_OnTakeDamageAliveOnTakeDamage);
    if (
ReviveAsChickenTimer[client] != null)
    {
        
KillTimer(ReviveAsChickenTimer[client]);
        
ReviveAsChickenTimer[client] = null;
    }
}

//*******************************************************//
//                   EVENTS                             //
//*****************************************************//
public Action PlayerSpawn(Event event, const char[] namebool 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(clientProp_Send"m_lifeState"1);  

        
Client_RemoveAllWeapons(client""true);
        
SetEntProp(clientProp_Send"m_iHideHUD"GetEntProp(clientProp_Send"m_iHideHUD") | HIDE_RADAR_CSGO);
        
SetEntProp(clientProp_Data"m_takedamage"01);
        
SetEntityModel(clientChickenModel);
        
SetEntityHealth(clientChickenHealth.IntValue);
        
SetGravity(clientChickenGravity.FloatValue);
        
SetSpeed(clientChickenSpeed.FloatValue);  
        return 
Plugin_Handled;
    }

    
SetEntProp(clientProp_Data"m_takedamage"21);
    
SetEntProp(clientProp_Send"m_iHideHUD"GetEntProp(clientProp_Send"m_iHideHUD") & ~HIDE_RADAR_CSGO);
    
SetGravity(client1.0);
    
SetSpeed(client1.0);
    return 
Plugin_Continue;
}

public 
Action PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if (!
RevivedAsChicken[client])
    {
        
ReviveAsChickenTimer[client] = CreateTimer(ChickenRespawn.FloatValueRevivePlayerAsChickenGetClientUserId(client));
    }
}

public 
Action RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
    {
        if(
IsValidClient(i) && RevivedAsChicken[i])
        {
            
RevivedAsChicken[i] = false;
        }

        if (
ReviveAsChickenTimer[i] != null)
        {
            
KillTimer(ReviveAsChickenTimer[i]);
            
ReviveAsChickenTimer[i] = null;
        }
    }
}

public 
Action RevivePlayerAsChicken(Handle timerany userid)
{
   
int client GetClientOfUserId(userid);
   if(
client == 0) return;

   
RevivedAsChicken[client] = true;
   
CS_RespawnPlayer(client);
}

//*******************************************************//
//                   ACTIONS                            //
//*****************************************************//

public Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weaponint &subtypeint &cmdnumint &tickcountint &seedint mouse[2])
{
    if(
RevivedAsChicken[client] && ChickenUse.IntValue)
    {
        
buttons buttons &= ~IN_USE;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;
}

public 
Action OnWeaponEquip(int clientint weapon)  
{
    
char weaponname[32];
    
GetEdictClassname(weaponweaponnamesizeof(weaponname)); 

    if(
RevivedAsChicken[client] && !StrEqual(weaponname"weapon_knife"))
    {
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;    


public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    if(
RevivedAsChicken[attacker])
    {
        
damage 0.0
        return 
Plugin_Handled
    }

    return 
Plugin_Continue;
}

//*******************************************************//
//                    VOIDS                             //
//*****************************************************//
public void OnPlayerTouch(int clientint ent)
{
    if(
RevivedAsChicken[client] && ChickenNoCollusion.IntValue && IsValidClient(client))
    {
        
SetEntProp(clientProp_Data"m_CollisionGroup", (ent <= MaxClients) ? 5);
    }  
}

public 
void SetSpeed(int clientfloat speed)
{
    
SetEntPropFloat(clientProp_Data"m_flLaggedMovementValue"speed);
}

public 
void SetGravity(int clientfloat amount)
{
    
SetEntityGravity(clientamount GetEntPropFloat(clientProp_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 (
<= client <= MaxClients && IsClientInGame(client));

PHP Code:
sm_chicken_nocollusion <Int Value> - Disbles collusions between chickens and normal playersonoff 
Try it now.
__________________
PinHeaDi is offline