Senior Member
Join Date: Jul 2013
Location: Bulgaria
|
03-28-2018
, 07:54
Re: [ CSGO ] dead players respawn as chicken
|
#15
|
PHP Code:
#include <sourcemod> #include <cstrike> #include <sdktools> #include <sdkhooks> #include <smlib> #include <multicolors>
#pragma semicolon 1 #pragma newdecls required
#define HIDE_RADAR_CSGO 1<<12
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); RegConsoleCmd("sm_cg", ChangeChickenGravity);
for(int i = 1; i <= MaxClients; i++) { if(IsClientInGame(i)) OnClientPutInServer(i); } }
public APLRes AskPluginLoad2(Handle myself, bool late, char [] error, int err_max) { CreateNative("RevivedAsChicken", Native_Spawnkiller); return APLRes_Success; }
public int Native_Spawnkiller(Handle plugin, int argc) { int client = GetNativeCell(1); bool value = GetNativeCell(2); RevivedAsChicken[client] = value; }
public void OnMapStart() { PrecacheModel("models/chicken/chicken.mdl", true); 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; } }
public Action ChangeChickenGravity(int client, int args) { if(RevivedAsChicken[client]) { CPrintToChat(client, "[{lightred}Info{default}] You can only use that command when you're a {blue}chicken{default}."); return Plugin_Handled; }
char gravity[4]; GetCmdArg(1, gravity, sizeof(gravity)); float gravityvalue = StringToFloat(gravity);
if(gravityvalue == 0.1 || gravityvalue == 0.2 || gravityvalue == 0.3 || gravityvalue == 0.4 || gravityvalue == 0.5 || gravityvalue == 0.6 || gravityvalue == 0.7 || gravityvalue == 0.8 || gravityvalue == 0.9 || gravityvalue == 1.0) { SetGravity(client, gravityvalue); CPrintToChat(client, "[{lightred}Info{default}] You changed your gravity to {green}%.1f{default}.", gravityvalue); } else { CPrintToChat(client, "[{lightred}Info{default}] Valid gravity values from {green}0,1 {default}to {green}1,0{default}."); } return Plugin_Continue; } //*******************************************************// // 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, "models/chicken/chicken.mdl"); 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;
AskPlayerIfHeWantsToBeAChicken(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)); }
//*******************************************************// // MENU // //*****************************************************//
public void AskPlayerIfHeWantsToBeAChicken(int client) { Menu menu = new Menu(ChickenMENU);
menu.SetTitle("%N, do you want to be revived as a chicken?", client); menu.AddItem("yes", "Yes"); menu.AddItem("no", "No"); menu.ExitButton = false; menu.Display(client, 15); }
public int ChickenMENU(Menu menu, MenuAction action, int client, int param2) { switch(action) { case MenuAction_Select: { char info[32]; menu.GetItem(param2, info, sizeof(info));
if (StrEqual(info, "yes")) { RevivedAsChicken[client] = true; CS_RespawnPlayer(client); } else if (StrEqual(info, "no")) { RevivedAsChicken[client] = false; } }
case MenuAction_End:{delete menu;} }
return 0; }
Of course it can be fixed. Try this version, see if it fix the missing chicken model. Now for the revive plugin you use:
PHP Code:
#include <revive_as_chicken>
And add this where the revive is happening:
PHP Code:
RevivedAsChicken(client, false);
I guess it'll be something like:
PHP Code:
CS_RespawnPlayer(client); RevivedAsChicken(client, false);
__________________
Last edited by PinHeaDi; 03-28-2018 at 12:48.
|
|