Raised This Month: $51 Target: $400
 12% 

T side only


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jemil
Junior Member
Join Date: Aug 2012
Old 08-05-2012 , 10:56   T side only
Reply With Quote #1

I would like to get help on making this to work on t side only on css
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define VERSION "1.0.0"
public Plugin:myinfo =
{
 name = "Only headshot",
 author = "Jemil",
 description = "Takes damage to the head only",
 version = "1.0.0",
 url = ""
};
new String:language[4];
new String:languagecode[4];
new String:g_headsounds[256];
new String:headsounds[5][256];
new bool:g_enabled;
new bool:g_useambient;
new soundsfound;
new Handle:g_Cvarenabled = INVALID_HANDLE;
new Handle:g_Cvarheadsounds = INVALID_HANDLE;
new Handle:g_Cvaruseambient = INVALID_HANDLE;
new g_iHealth, g_Armor;
public OnPluginStart()
{
  LoadTranslations("headshotonly.phrases");
  GetLanguageInfo(GetServerLanguage(), languagecode, sizeof(languagecode), language, sizeof(language));
  CreateConVar("sm_headshotonly_version", VERSION, "Headshot Only", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  g_Cvarenabled = CreateConVar("sm_headshotonly_enabled", "1", "Enable this plugin. 0 = Disabled");
  g_Cvarheadsounds = CreateConVar("sm_headshotonly_sounds", "", "Sound files to indicate headshots. (Max: 5)  Leave blank for default sounds.");
  g_Cvaruseambient = CreateConVar("sm_headshotonly_useambient", "1", "Emit sounds from victim to all players.  0 = Emit sound from victim only to attacker.");
  HookEvent("player_hurt", EventPlayerHurt, EventHookMode_Pre);
  HookConVarChange(g_Cvarenabled, OnSettingChanged);
  HookConVarChange(g_Cvaruseambient, OnSettingChanged);
  AutoExecConfig(true, "headshotonly");
  g_iHealth = FindSendPropOffs("CCSPlayer", "m_iHealth");
  if (g_iHealth == -1)
  {
    SetFailState("[Headshot Only] Error - Unable to get offset for CSSPlayer::m_iHealth");
  }
  g_Armor = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
  if (g_Armor == -1)
  {
    SetFailState("[Headshot Only] Error - Unable to get offset for CSSPlayer::m_ArmorValue");
  }
}
public OnConfigsExecuted()
{
  g_enabled = GetConVarBool(g_Cvarenabled);
  g_useambient = GetConVarBool(g_Cvaruseambient);
  GetConVarString(g_Cvarheadsounds, g_headsounds, sizeof(g_headsounds));
  if (!StrEqual(g_headsounds, "", false))
  {
    new String: buffer[256];
    soundsfound = ExplodeString(g_headsounds, ",", headsounds, 5, 64);
    if (soundsfound > 0)
    {
      for (new i = 0; i <= soundsfound -1; i++)
      {
        Format(buffer, PLATFORM_MAX_PATH, "headshotonly/%s", headsounds[i]);
        if (!PrecacheSound(buffer, true))
        {
          SetFailState("HeadShot Only: Could not pre-cache sound: %s", buffer);
        }
        else
        {
          Format(buffer, PLATFORM_MAX_PATH, "sound/headshotonly/%s", headsounds[i]);
          AddFileToDownloadsTable(buffer);
          buffer = "headshotonly/";
          StrCat(buffer, sizeof(buffer), headsounds[i]);
          headsounds[i] = buffer;
        }
      }
    }
    return;
  }
  soundsfound = 5;
  headsounds[0] = "physics/flesh/flesh_squishy_impact_hard1.wav";
  headsounds[1] = "physics/flesh/flesh_squishy_impact_hard2.wav";
  headsounds[2] = "physics/flesh/flesh_squishy_impact_hard3.wav";
  headsounds[3] = "physics/flesh/flesh_squishy_impact_hard4.wav";
  headsounds[4] = "physics/flesh/flesh_bloody_break.wav";
  PrecacheSound(headsounds[0], true);
  PrecacheSound(headsounds[1], true);
  PrecacheSound(headsounds[2], true);
  PrecacheSound(headsounds[3], true);
  PrecacheSound(headsounds[4], true);
}
public OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
  if (convar == g_Cvarenabled)
  {
    if (newValue[0] == '1')
    {
   g_enabled = true;
   PrintHintTextToAll("%t", "Headshot enabled");
   EmitSoundToAll("player/bhit_helmet-1.wav");
    }
    else
    {
      g_enabled = false;
      PrintHintTextToAll("%t", "Headshot disabled");
      EmitSoundToAll("player/bhit_helmet-1.wav");
    }
  }
  if (convar == g_Cvaruseambient)
  {
    if (newValue[0] == '1')
    {
   g_useambient = true;
    }
    else
    {
      g_useambient = false;
    }
  }
}
public Action:EventPlayerHurt(Handle:event, const String:name[],bool:dontBroadcast)
{
  if (g_enabled)
  {
    new hitgroup = GetEventInt(event, "hitgroup");
    new victim = GetClientOfUserId(GetEventInt(event, "userid"));
    new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    new dhealth = GetEventInt(event, "dmg_health");
    new darmor = GetEventInt(event, "dmg_armor");
    new health = GetEventInt(event, "health");
    new armor = GetEventInt(event, "armor");
    if (hitgroup == 1)
    {
      if (g_useambient)
      {
        new Float:vicpos[3];
        GetClientEyePosition(victim, vicpos);
        EmitAmbientSound(headsounds[GetRandomInt(0, soundsfound -1)], vicpos, victim, SNDLEVEL_GUNFIRE);
      }
      else
      {
        EmitSoundToClient(attacker, headsounds[GetRandomInt(0, soundsfound -1)], SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_RAIDSIREN);
      }
      return Plugin_Continue;
    }
    else if (attacker != victim && victim != 0 && attacker != 0)
    {
      if (dhealth > 0)
      {
        SetEntData(victim, g_iHealth, (health + dhealth), 4, true);
      }
      if (darmor > 0)
      {
        SetEntData(victim, g_Armor, (armor + darmor), 4, true);
      }
    }
  }
  return Plugin_Continue;
}

Last edited by jemil; 08-05-2012 at 11:02.
jemil is offline
MPQC
SourceMod Donor
Join Date: Dec 2011
Old 08-05-2012 , 13:37   Re: T side only
Reply With Quote #2

Do you mean only the T's have to get the headshots?
MPQC is offline
jemil
Junior Member
Join Date: Aug 2012
Old 08-05-2012 , 14:26   Re: T side only
Reply With Quote #3

Yes exactly, only the t's will get hurt by headshots
jemil is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 08-05-2012 , 14:59   Re: T side only
Reply With Quote #4

My understanding is that player_hurt is an informational event only and can't be used to change the damage players take. To prevent damage, you'll need SDKHooks and its SDKHOOK_OnTakeDamage (which has to be applied to each player).
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
jemil
Junior Member
Join Date: Aug 2012
Old 08-05-2012 , 15:23   Re: T side only
Reply With Quote #5

The plugin works on both sides but I just want it to work on one team which is T, meaning T's will be able to shot Ct's where ever like normal but only t's can get damaged by headshots. Plugin alredy works fine but as I said I just want headshots only to work on T's and not Ct's.
jemil is offline
MPQC
SourceMod Donor
Join Date: Dec 2011
Old 08-05-2012 , 17:00   Re: T side only
Reply With Quote #6

Haven't compiled it, but pretty sure this is what you want.

Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define VERSION "1.0.0"
public Plugin:myinfo =
{
 name = "Only headshot",
 author = "Jemil",
 description = "Takes damage to the head only",
 version = "1.0.0",
 url = ""
};
new String:language[4];
new String:languagecode[4];
new String:g_headsounds[256];
new String:headsounds[5][256];
new bool:g_enabled;
new bool:g_useambient;
new soundsfound;
new Handle:g_Cvarenabled = INVALID_HANDLE;
new Handle:g_Cvarheadsounds = INVALID_HANDLE;
new Handle:g_Cvaruseambient = INVALID_HANDLE;
new g_iHealth, g_Armor;
public OnPluginStart()
{
  LoadTranslations("headshotonly.phrases");
  GetLanguageInfo(GetServerLanguage(), languagecode, sizeof(languagecode), language, sizeof(language));
  CreateConVar("sm_headshotonly_version", VERSION, "Headshot Only", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  g_Cvarenabled = CreateConVar("sm_headshotonly_enabled", "1", "Enable this plugin. 0 = Disabled");
  g_Cvarheadsounds = CreateConVar("sm_headshotonly_sounds", "", "Sound files to indicate headshots. (Max: 5)  Leave blank for default sounds.");
  g_Cvaruseambient = CreateConVar("sm_headshotonly_useambient", "1", "Emit sounds from victim to all players.  0 = Emit sound from victim only to attacker.");
  HookEvent("player_hurt", EventPlayerHurt, EventHookMode_Pre);
  HookConVarChange(g_Cvarenabled, OnSettingChanged);
  HookConVarChange(g_Cvaruseambient, OnSettingChanged);
  AutoExecConfig(true, "headshotonly");
  g_iHealth = FindSendPropOffs("CCSPlayer", "m_iHealth");
  if (g_iHealth == -1)
  {
    SetFailState("[Headshot Only] Error - Unable to get offset for CSSPlayer::m_iHealth");
  }
  g_Armor = FindSendPropOffs("CCSPlayer", "m_ArmorValue");
  if (g_Armor == -1)
  {
    SetFailState("[Headshot Only] Error - Unable to get offset for CSSPlayer::m_ArmorValue");
  }
}
public OnConfigsExecuted()
{
  g_enabled = GetConVarBool(g_Cvarenabled);
  g_useambient = GetConVarBool(g_Cvaruseambient);
  GetConVarString(g_Cvarheadsounds, g_headsounds, sizeof(g_headsounds));
  if (!StrEqual(g_headsounds, "", false))
  {
    new String: buffer[256];
    soundsfound = ExplodeString(g_headsounds, ",", headsounds, 5, 64);
    if (soundsfound > 0)
    {
      for (new i = 0; i <= soundsfound -1; i++)
      {
        Format(buffer, PLATFORM_MAX_PATH, "headshotonly/%s", headsounds[i]);
        if (!PrecacheSound(buffer, true))
        {
          SetFailState("HeadShot Only: Could not pre-cache sound: %s", buffer);
        }
        else
        {
          Format(buffer, PLATFORM_MAX_PATH, "sound/headshotonly/%s", headsounds[i]);
          AddFileToDownloadsTable(buffer);
          buffer = "headshotonly/";
          StrCat(buffer, sizeof(buffer), headsounds[i]);
          headsounds[i] = buffer;
        }
      }
    }
    return;
  }
  soundsfound = 5;
  headsounds[0] = "physics/flesh/flesh_squishy_impact_hard1.wav";
  headsounds[1] = "physics/flesh/flesh_squishy_impact_hard2.wav";
  headsounds[2] = "physics/flesh/flesh_squishy_impact_hard3.wav";
  headsounds[3] = "physics/flesh/flesh_squishy_impact_hard4.wav";
  headsounds[4] = "physics/flesh/flesh_bloody_break.wav";
  PrecacheSound(headsounds[0], true);
  PrecacheSound(headsounds[1], true);
  PrecacheSound(headsounds[2], true);
  PrecacheSound(headsounds[3], true);
  PrecacheSound(headsounds[4], true);
}
public OnSettingChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
  if (convar == g_Cvarenabled)
  {
    if (newValue[0] == '1')
    {
   g_enabled = true;
   PrintHintTextToAll("%t", "Headshot enabled");
   EmitSoundToAll("player/bhit_helmet-1.wav");
    }
    else
    {
      g_enabled = false;
      PrintHintTextToAll("%t", "Headshot disabled");
      EmitSoundToAll("player/bhit_helmet-1.wav");
    }
  }
  if (convar == g_Cvaruseambient)
  {
    if (newValue[0] == '1')
    {
   g_useambient = true;
    }
    else
    {
      g_useambient = false;
    }
  }
}
public Action:EventPlayerHurt(Handle:event, const String:name[],bool:dontBroadcast)
{
  if (g_enabled)
  {
    new hitgroup = GetEventInt(event, "hitgroup");
    new victim = GetClientOfUserId(GetEventInt(event, "userid"));
    new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    new dhealth = GetEventInt(event, "dmg_health");
    new darmor = GetEventInt(event, "dmg_armor");
    new health = GetEventInt(event, "health");
    new armor = GetEventInt(event, "armor");
    
    if (GetClientTeam(victim) == 2)
    {
        if (hitgroup == 1)
        {
          if (g_useambient)
          {
            new Float:vicpos[3];
            GetClientEyePosition(victim, vicpos);
            EmitAmbientSound(headsounds[GetRandomInt(0, soundsfound -1)], vicpos, victim, SNDLEVEL_GUNFIRE);
          }
          else
          {
            EmitSoundToClient(attacker, headsounds[GetRandomInt(0, soundsfound -1)], SOUND_FROM_PLAYER, SNDCHAN_AUTO, SNDLEVEL_RAIDSIREN);
          }
          return Plugin_Continue;
        }
        else if (attacker != victim && victim != 0 && attacker != 0)
        {
          if (dhealth > 0)
          {
            SetEntData(victim, g_iHealth, (health + dhealth), 4, true);
          }
          if (darmor > 0)
          {
            SetEntData(victim, g_Armor, (armor + darmor), 4, true);
          }
        }
    }
  }
  return Plugin_Continue;
}
MPQC is offline
jemil
Junior Member
Join Date: Aug 2012
Old 08-05-2012 , 17:20   Re: T side only
Reply With Quote #7

Yes! Thank you!
jemil is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode