diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 96fe4d7..9605b71 100755 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -51,7 +51,8 @@ enum ZRSettings Handle:CVAR_RESPAWN, Handle:CVAR_RESPAWN_TEAM, Handle:CVAR_RESPAWN_DELAY, - Handle:CVAR_SUICIDE, + Handle:CVAR_SUICIDE_ZOMBIE, + Handle:CVAR_SUICIDE_HUMAN, Handle:CVAR_SUICIDE_ECHO, Handle:CVAR_SUICIDE_WORLD_DAMAGE, Handle:CVAR_SPAWN_MIN, @@ -137,7 +138,8 @@ CreateCvars() gCvars[CVAR_RESPAWN] = CreateConVar("zr_respawn", "0", "When player is killed, player will respawn"); gCvars[CVAR_RESPAWN_TEAM] = CreateConVar("zr_respawn_team", "zombie", "Which team to respawn player as (Choices: zombie, human)"); gCvars[CVAR_RESPAWN_DELAY] = CreateConVar("zr_respawn_delay", "1", "How long to wait after death to respawn, in seconds"); - gCvars[CVAR_SUICIDE] = CreateConVar("zr_suicide", "1", "Stops players from suiciding"); + gCvars[CVAR_SUICIDE_ZOMBIE] = CreateConVar("zr_suicide_zombie", "1", "Stops zombies from suiciding"); + gCvars[CVAR_SUICIDE_HUMAN] = CreateConVar("zr_suicide_human", "1", "Stops humans from suiciding"); gCvars[CVAR_SUICIDE_ECHO] = CreateConVar("zr_suicide_echo", "0", "Log suicide attempts to admin chat."); gCvars[CVAR_SUICIDE_WORLD_DAMAGE] = CreateConVar("zr_suicide_world_damage", "1", "Respawn zombies as zombies if they were killed by the world, like elevators, doors and lasers. (0: Disable)"); gCvars[CVAR_SPAWN_MIN] = CreateConVar("zr_spawn_min", "30", "Minimum time a player is picked to be zombie after the round starts, in seconds"); diff --git a/src/zr/damagecontrol.inc b/src/zr/damagecontrol.inc index 276fe79..3e5ea82 100755 --- a/src/zr/damagecontrol.inc +++ b/src/zr/damagecontrol.inc @@ -1,196 +1,188 @@ -/** - * ==================== - * Zombie:Reloaded - * File: damagecontrol.inc - * Author: Greyscale - * ==================== - */ - -#define DMG_GENERIC 0 // generic damage was done -#define DMG_BULLET (1 << 1) // shot -#define DMG_SLASH (1 << 2) // cut, clawed, stabbed -#define DMG_BURN (1 << 3) // heat burned -#define DMG_FALL (1 << 5) // fell too far -#define DMG_BLAST (1 << 6) // explosive blast damage -#define DMG_DROWN (1 << 14) // Drowning - -enum ZRHooks -{ - Hook_TraceAttack, - Hook_OnTakeDamage -} - -new gHooks[MAXPLAYERS+1][ZRHooks]; - -InitDmgControl() -{ - /* It's case sensitive! */ - RegConsoleCmd("kill", Attempt_Suicide); - RegConsoleCmd("KILL", Attempt_Suicide); - RegConsoleCmd("jointeam", Attempt_Suicide); - RegConsoleCmd("JOINTEAM", Attempt_Suicide); - RegConsoleCmd("spectate", Attempt_Suicide); -} - -ClientHookAttack(client) -{ - gHooks[client][Hook_TraceAttack] = Hacks_Hook(client, HACKS_HTYPE_TRACEATTACK, TraceAttack, false); - gHooks[client][Hook_OnTakeDamage] = Hacks_Hook(client, HACKS_HTYPE_ONTAKEDAMAGE, OnTakeDamage, false); -} - -ClientUnHookAttack(client) -{ - Hacks_Unhook(gHooks[client][Hook_TraceAttack]); - Hacks_Unhook(gHooks[client][Hook_OnTakeDamage]); -} - -public TraceAttack(client, inflictor, attacker, damage, hitbox, hitgroup) -{ - new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); - - if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker) || !enabled) - { - return Hacks_Continue; - } - - if (IsPlayerZombie(client) && IsPlayerZombie(attacker)) - { - return 0; - } - - if (IsPlayerHuman(client) && IsPlayerHuman(attacker)) - { - return 0; - } - - return Hacks_Continue; -} - -public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype) -{ - new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); - if (!enabled) - { - return Hacks_Continue; - } - - decl String:classname[64]; - GetEdictClassname(inflictor, classname, sizeof(classname)); - if (StrContains(classname, "trigger") > -1) - { - return Hacks_Continue; - } - - if (damagetype & DMG_FALL) - { - if (!IsPlayerZombie(client)) - { - return Hacks_Continue; - } - - new bool:blockfalldamage = GetClassNoFallDamage(pClass[client]); - if (!blockfalldamage) - { - return Hacks_Continue; - } - - return 0; - } - - if (damagetype & DMG_BLAST) - { - if (!IsPlayerHuman(client) || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) - { - return Hacks_Continue; - } - - return 0; - } - - if (damagetype & DMG_BULLET) - { - if (!client || !IsClientPlayer(client) || !IsClientInGame(client)) - { - return Hacks_Continue; - } - - if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) - { - return Hacks_Continue; - } - - if (IsPlayerZombie(client) && IsPlayerHuman(attacker)) - { - return Hacks_Continue; - } - - if (IsPlayerHuman(client) && IsPlayerZombie(attacker)) - { - new health = GetClientHealth(client); - SetEntityHealth(client, health + damage); - - return Hacks_Continue; - } - - return 0; - } - - return Hacks_Continue; -} - -public Action:Attempt_Suicide(client, argc) -{ - if (!client) - { - return Plugin_Continue; - } - - new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); - if (!enabled) - { - return Plugin_Continue; - } - - new bool:suicide = GetConVarBool(gCvars[CVAR_SUICIDE]); - if (!suicide) - { - return Plugin_Continue; - } - - decl String:cmd[16]; - GetCmdArg(0, cmd, sizeof(cmd)); - - if (!IsPlayerZombie(client) && StrEqual(cmd, "spectate", false)) - { - return Plugin_Continue; - } - - if (!IsPlayerZombie(client) && !GetConVarBool(gCvars[CVAR_RESPAWN])) - { - return Plugin_Continue; - } - - if (!IsPlayerAlive(client)) - { - return Plugin_Continue; - } - - ZR_ReplyToCommand(client, "Suicide text"); - ZR_PrintToChat(client, "Suicide text"); - - decl String:clientname[64]; - decl String:buffer[192]; - - GetClientName(client, clientname, sizeof(clientname)); - if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_DAMAGECONTROL)) - { - ZR_LogMessageFormatted(client, "damage control", "suicide", "Player \"%s\" attempted suicide.", true, clientname); - } - if (GetConVarBool(gCvars[CVAR_SUICIDE_ECHO])) - { - Format(buffer, sizeof(buffer), "Player '%s' attempted suicide.", clientname); - ZR_PrintToAdminChat(buffer); - } - - return Plugin_Handled; +/** + * ==================== + * Zombie:Reloaded + * File: damagecontrol.inc + * Author: Greyscale + * ==================== + */ + +#define DMG_GENERIC 0 // generic damage was done +#define DMG_BULLET (1 << 1) // shot +#define DMG_SLASH (1 << 2) // cut, clawed, stabbed +#define DMG_BURN (1 << 3) // heat burned +#define DMG_FALL (1 << 5) // fell too far +#define DMG_BLAST (1 << 6) // explosive blast damage +#define DMG_DROWN (1 << 14) // Drowning + +enum ZRHooks +{ + Hook_TraceAttack, + Hook_OnTakeDamage +} + +new gHooks[MAXPLAYERS+1][ZRHooks]; + +InitDmgControl() +{ + /* It's case sensitive! */ + RegConsoleCmd("kill", Attempt_Suicide); + RegConsoleCmd("KILL", Attempt_Suicide); + RegConsoleCmd("jointeam", Attempt_Suicide); + RegConsoleCmd("JOINTEAM", Attempt_Suicide); + RegConsoleCmd("spectate", Attempt_Suicide); +} + +ClientHookAttack(client) +{ + gHooks[client][Hook_TraceAttack] = Hacks_Hook(client, HACKS_HTYPE_TRACEATTACK, TraceAttack, false); + gHooks[client][Hook_OnTakeDamage] = Hacks_Hook(client, HACKS_HTYPE_ONTAKEDAMAGE, OnTakeDamage, false); +} + +ClientUnHookAttack(client) +{ + Hacks_Unhook(gHooks[client][Hook_TraceAttack]); + Hacks_Unhook(gHooks[client][Hook_OnTakeDamage]); +} + +public TraceAttack(client, inflictor, attacker, damage, hitbox, hitgroup) +{ + new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); + + if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker) || !enabled) + { + return Hacks_Continue; + } + + if (IsPlayerZombie(client) && IsPlayerZombie(attacker)) + { + return 0; + } + + if (IsPlayerHuman(client) && IsPlayerHuman(attacker)) + { + return 0; + } + + return Hacks_Continue; +} + +public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype) +{ + new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); + if (!enabled) + { + return Hacks_Continue; + } + + decl String:classname[64]; + GetEdictClassname(inflictor, classname, sizeof(classname)); + if (StrContains(classname, "trigger") > -1) + { + return Hacks_Continue; + } + + if (damagetype & DMG_FALL) + { + if (!IsPlayerZombie(client)) + { + return Hacks_Continue; + } + + new bool:blockfalldamage = GetClassNoFallDamage(pClass[client]); + if (!blockfalldamage) + { + return Hacks_Continue; + } + + return 0; + } + + if (damagetype & DMG_BLAST) + { + if (!IsPlayerHuman(client) || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) + { + return Hacks_Continue; + } + + return 0; + } + + if (damagetype & DMG_BULLET) + { + if (!client || !IsClientPlayer(client) || !IsClientInGame(client)) + { + return Hacks_Continue; + } + + if (!attacker || !IsClientPlayer(attacker) || !IsClientInGame(attacker)) + { + return Hacks_Continue; + } + + if (IsPlayerZombie(client) && IsPlayerHuman(attacker)) + { + return Hacks_Continue; + } + + if (IsPlayerHuman(client) && IsPlayerZombie(attacker)) + { + new health = GetClientHealth(client); + SetEntityHealth(client, health + damage); + + return Hacks_Continue; + } + + return 0; + } + + return Hacks_Continue; +} + +public Action:Attempt_Suicide(client, argc) +{ + if (!client) + { + return Plugin_Continue; + } + + new bool:enabled = GetConVarBool(gCvars[CVAR_ENABLE]); + if (!enabled) + { + return Plugin_Continue; + } + + + + new bool:suicide = IsPlayerZombie(client) ? GetConVarBool(gCvars[CVAR_SUICIDE_ZOMBIE]) : GetConVarBool(gCvars[CVAR_SUICIDE_HUMAN]); + if (!suicide) + { + return Plugin_Continue; + } + + decl String:cmd[16]; + GetCmdArg(0, cmd, sizeof(cmd)); + + if (!IsPlayerAlive(client)) + { + return Plugin_Continue; + } + + ZR_ReplyToCommand(client, "Suicide text"); + ZR_PrintToChat(client, "Suicide text"); + + decl String:clientname[64]; + decl String:buffer[192]; + + GetClientName(client, clientname, sizeof(clientname)); + if (LogFlagCheck(LOG_GAME_EVENTS, LOG_MODULE_DAMAGECONTROL)) + { + ZR_LogMessageFormatted(client, "damage control", "suicide", "Player \"%s\" attempted suicide.", true, clientname); + } + if (GetConVarBool(gCvars[CVAR_SUICIDE_ECHO])) + { + Format(buffer, sizeof(buffer), "Player '%s' attempted suicide.", clientname); + ZR_PrintToAdminChat(buffer); + } + + return Plugin_Handled; } \ No newline at end of file