AMX MOD X
Пятница, 29.03.2024, 01:11:19



Приветствую Вас Гость | RSS
[ Главная ] [ Не получается нанести урон игроку - AMX Mod X Форум ] [ Регистрация ] [ Вход ]
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]

Вниманию участников! Данный форум теперь является архивом и вскором времени здесь нельзя будет создавать новых тем! Просьба всем для общения и создания новых тем перейти на наш новый форум: http://amxmodx.su/

  • Страница 1 из 1
  • 1
Модератор форума: slogic, AlMod  
AMX Mod X Форум » Скриптинг » Помощь по скриптингу » Не получается нанести урон игроку (хелп)
Не получается нанести урон игроку
NiHiLaNThДата: Четверг, 09.07.2009, 21:27:11 | Сообщение # 1
Рядовой
Группа: Пользователи
Сообщений: 6
Репутация: 0
Статус: Не в сети
Я недавно начал писать плагин для Zombie Plague который добавляет в игру новую пушку AK47 с подствольным гранатометом.Сам гранатомет работает вроде бы нормально, только мне не удается нанести урон игрокам.Я тестировал гранатомет с ботами и хотя граната взрывалась прямо под ногами игроков(зомбиков) у них не снималось ни одного ХП.
Code

#include <amxmodx>
#include <cstrike>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
#include <zombieplague>

// Plugin stuff
new const PLUGIN[] = "[ZP] Ak47 + Gp30"
new const VERSION[] = "2.0"
new const AUTHOR[] = "NiHiLaNTh"

// Models
new const view_model[] = "models/v_gp30.mdl"
new const world_model[] = "models/w_gp30.mdl"
new const grenade_model[] = "models/grenade.mdl"

// Sounds
new const launch_sound[] = "weapons/glauncher.wav"
new const empty_sound[] = "weapons/357_cock1.wav"
new const xplode_sound[] = "weapons/explode3.wav"

// Sprites
new const trail_sprite[] = "sprites/laserbeam.spr"
new const explode_sprite[] = "sprites/zerogxplode2.spr"

// CVAR pointers
new cvar_enabled, cvar_gp30_dmg

// Message ID's
new g_msgScoreInfo, g_msgStatusIcon

// Item ID
new g_akgp

// Player variables
new g_hasGp[33] // has Ak47+ Gp30
new grenade_counter // how many grenades are in Gp25
new Float:g_last_launch_time[33] // last time grenade launcher used

// Cached sprite indexes
new g_trailSpr, g_xploSpr

// Explosion radius
const Float:LAUNCHER_RADIUS = 350.0

// Plugin precache
public plugin_precache()
{
  // Precache models...
  precache_model(view_model)
  precache_model(world_model)
  precache_model(grenade_model)
   
  // ...sounds...
  precache_sound(launch_sound)
  precache_sound(empty_sound)
  precache_sound(xplode_sound)
   
  // and sprites
  g_trailSpr = precache_model(trail_sprite)
  g_xploSpr = precache_model(explode_sprite)
}

// Plugin initialization
public plugin_init()
{
  // Register plugin
  register_plugin(PLUGIN, VERSION, AUTHOR)
   
  // Register new extra item
  g_akgp = zp_register_extra_item("Ak47 + Gp30", 30, ZP_TEAM_HUMAN)
   
  // CVARs
  cvar_enabled = register_cvar("zp_akgp30", "1")
  cvar_gp30_dmg = register_cvar("zp_gp30_dmg", "350")
   
  // Messages
  g_msgScoreInfo = get_user_msgid("ScoreInfo")
  g_msgStatusIcon = get_user_msgid("StatusIcon")
   
  // Event
  register_event("CurWeapon", "Event_CurWeapon", "be","1=1")
   
  // Forward
  register_forward(FM_PlayerPreThink, "fwd_player_think_pre")
  register_forward(FM_SetModel, "fwd_set_model")
  RegisterHam(Ham_Killed, "player", "fwd_player_killed")
}

// Player connected
public client_connect(id)
{
  g_hasGp[id] = false
  grenade_counter = 0
}

// Player bought our extra item
public zp_extra_item_selected(id, itemid)
{
  if (itemid == g_akgp)
  {
   // Notice player
   client_print(id, print_chat, "[ZP] You bought Ak47+Gp30 grenade launcher.")
   client_print(id, print_chat, "[ZP] Press attack2 button to launch grenade launcher.")
    
   // Reset variables
   g_hasGp[id] = true
   grenade_counter = 10
    
   // Give ak47
   fm_give_item(id, "weapon_ak47")
  }
}

// Current weapon player is holding
public Event_CurWeapon(id)
{
  // Plugin enabled?
  static on
  on = get_pcvar_num(cvar_enabled)
   
  if (on == 1)
  {
   // Get weapon ID
   new weaponID = read_data(2)
    
   // Not AK47
   if (weaponID != CSW_AK47)
    return PLUGIN_CONTINUE
     
   // If has ak47 + gp30
   if (g_hasGp[id] || grenade_counter >= 1)
   {
    // View model
    entity_set_string(id, EV_SZ_viewmodel, view_model)
     
    // Player model
    entity_set_string(id, EV_SZ_weaponmodel, "models/p_ak47.mdl")
   }
   // Just an ak47
   else
   {
    // View model
    entity_set_string(id, EV_SZ_viewmodel, "models/v_ak47.mdl")
     
    // Player model
    entity_set_string(id, EV_SZ_weaponmodel, "models/p_ak47.mdl")
   }
  }
   
  return PLUGIN_CONTINUE
}

// Player thinks before
public fwd_player_think_pre(id)
{
  // Plugin enabled?
  static on
  on = get_pcvar_num(cvar_enabled)
    
  if (on == 1)
  {
   // Get clip, ammo and weapon
   new szClip, szAmmo, szWeapon = get_user_weapon(id, szClip, szAmmo)
    
   // If weapon is Ak47...
   if (szWeapon == 28)
   {
    // If player has our AK47...
    if (g_hasGp[id])
    {
     // If player pressed secondary attack button...
     if ((get_user_button(id) & IN_ATTACK2) && !(get_user_oldbutton(id) & IN_ATTACK2))
     {
      Launch_Grenade(id)
     }
    }
   }
  }
}

// Set model
public fwd_set_model(ent, const model[])
{
  // Valid entity
  if (!is_valid_ent(ent))
  {
   client_print(0 , print_chat , "[AMXX] Error! Invalid ENTITY: %i" , ent);
  }
}

// Player died
public fwd_player_killed(victim, attacker, shouldgib)
{
  if (g_hasGp[victim])
  {
   g_hasGp[victim] = false
  }
}

// Launch grenade
public Launch_Grenade(id)
{
  // Not alive
  if (!is_user_alive(id))
   return PLUGIN_CONTINUE
    
  // Dont have our weapon
  if (!g_hasGp[id])
   return PLUGIN_CONTINUE
    
  // Oops, you dont have any grenades anymore
  if (grenade_counter == 0)
  {
   // Notice player
   client_print(id, print_chat, "You are out of grenades.")
    
   // Play sound
   emit_sound(id, CHAN_WEAPON, empty_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    
   return PLUGIN_CONTINUE
  }
   
  // A zombie?
  if (zp_get_user_zombie(id) || zp_get_user_nemesis(id))
   return PLUGIN_CONTINUE
    
  // You recently launched a grenade
  if (get_gametime() - g_last_launch_time[id] < 3.0)
  {
   client_print(id, print_center, "Reloading grenade launcher.");
   return PLUGIN_CONTINUE;
  }
   
  // We cannot use this in water
  static inwater
  set_pev(id, pev_waterlevel, inwater)
   
  if (inwater == 3)
  {
   // Play sound
   emit_sound(id, CHAN_WEAPON, empty_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    
   return PLUGIN_CONTINUE
  }
    
  // Play launch sound
  emit_sound(id, CHAN_VOICE, launch_sound, VOL_NORM, ATTN_NORM, 0 ,PITCH_NORM)
   
  // Create nade entity
  set_task(0.1, "Create_Nade", id, _, _, _)
   
  // Decrease nade count
  grenade_counter--
   
  // Create trail
  set_task(0.1, "Create_Trail", id, _, _, _)
   
  // Get current time
  g_last_launch_time[id] = get_gametime()
   
  // Create explosion
  set_task(1.0, "Create_Explosion", id, _, _, _)
   
  return PLUGIN_CONTINUE
}

// Create nade
public Create_Nade(id)
{
  // Now let's create new entity  
  new iNade = create_entity("info_target")  
   
  // Not out entity
  if (!iNade)
   return PLUGIN_HANDLED
    
  // Set nade's classname
  entity_set_string(iNade, EV_SZ_classname, "gp30_nade")
    
  // Set nade's model
  entity_set_model(iNade, grenade_model)
    
  entity_set_int(id, EV_INT_weaponanim, 3)

  // Get origin
  new Float: Origin[3], Float: Velocity[3], Float: vAngle[3]

  entity_get_vector(id, EV_VEC_origin , Origin)
  entity_get_vector(id, EV_VEC_v_angle, vAngle)
   
  // Size
  new Float:MinBox[3] = {-1.0, -1.0, -1.0}
  new Float:MaxBox[3] = {1.0, 1.0, 1.0}
  entity_set_vector(iNade, EV_VEC_mins, MinBox)
  entity_set_vector(iNade, EV_VEC_maxs, MaxBox)

  // Origin and angle
  entity_set_origin(iNade, Origin)
  entity_set_vector(iNade, EV_VEC_angles, vAngle)

  // Misc
  entity_set_int(iNade, EV_INT_effects, EF_MUZZLEFLASH)
  entity_set_int(iNade, EV_INT_solid, SOLID_TRIGGER)
  entity_set_int(iNade, EV_INT_movetype, MOVETYPE_TOSS)
  entity_set_edict(iNade, EV_ENT_owner, id)

  // Velocity
  VelocityByAim(id, 2000 , Velocity)
  entity_set_vector(iNade, EV_VEC_velocity ,Velocity)
   
  // Set next think
  entity_set_float(iNade, EV_FL_nextthink, halflife_time() + 0.01)
   
  return PLUGIN_HANDLED
}

// Create trail
public Create_Trail(id)
{
  new ent = find_ent_by_class(id, "gp30_nade")
   
  if (ent)
  {
   message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
   write_byte( TE_BEAMFOLLOW )
   write_short(ent) // entity
   write_short(g_trailSpr)  // model
   write_byte( 10 )       // life
   write_byte( 5 )        // width
   write_byte( 255 )      // r, g, b
   write_byte( 0 )    // r, g, b
   write_byte( 0 )      // r, g, b
   write_byte( 100 ) // brightness
   message_end()
  }
}
      
// Create Effects
public Create_Explosion(ent)
{
  new EntID = find_ent_by_class(ent, "gp30_nade")
   
  // Get origin
  static Float:originX[3]
  entity_get_vector(EntID, EV_VEC_origin, originX)
  static originY[3]
  originY[0] = floatround(originX[0])
  originY[1] = floatround(originX[1])
  originY[2] = floatround(originX[2])
  FVecIVec(originX, originY)
   
  // Explosion
  message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  write_byte (TE_EXPLOSION)
  write_coord(originY[0])
  write_coord(originY[1])
  write_coord(originY[2] + 60)
  write_short(g_xploSpr)
  write_byte(30)
  write_byte(15)
  write_byte(0)
  message_end()
    
  // Play sound
  emit_sound(EntID, CHAN_WEAPON, xplode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
   
  // Get owner
  new owner = entity_get_edict(EntID, EV_ENT_owner)
    
  // Loop through all players
  new aPlayers[32], iNum, x
  get_players(aPlayers, iNum, "a")
    
  // Bomb exploded - now let's find victims
  for (x = 0; x >= iNum; x++)  
  {
   new victim = aPlayers[x]
   new origin[3], origin1[3], DistanceBetween
   origin[0] = originY[0]
   origin[1] = originY[1]
   origin[2] = originY[2]
   get_user_origin(victim, origin1)
   DistanceBetween = get_distance(origin, origin1)
    
   if (DistanceBetween <= LAUNCHER_RADIUS)
   {
    // We founded zombie victims
    if (zp_get_user_zombie(victim) || zp_get_user_nemesis(victim))
    {
     // Get damage and health
     static health, damage
     health = get_user_health(victim)
     damage = get_pcvar_num(cvar_gp30_dmg)
    
     // After all this victim is still alive
     if (health - damage > 1)
     {
      set_user_health(victim, health - damage)
     }
     // And now he is dead
     else
     {
      // Silently kill victim
      user_silentkill(victim)
     
      // Death Message
      make_deathmsg(owner, victim, 0, "grenade")
     
      // Score Info
      // Attacker
      message_begin(MSG_BROADCAST, g_msgScoreInfo)
      write_byte(owner) // id
      write_short(pev(owner, pev_frags) +1) // frags
      write_short(get_user_deaths(owner)) // deaths
      write_short(0) // class?
      write_short(get_user_team(owner)) // team
      message_end()
      
      // Victim
      message_begin(MSG_BROADCAST, g_msgScoreInfo)
      write_byte(victim) // id
      write_short(pev(victim, pev_frags)) // frags
      write_short(get_user_deaths(victim) +1) // deaths
      write_short(0) // class?
      write_short(get_user_team(victim)) // team
      message_end()
     
      // Set attackers ammo packs
      new ap = zp_get_user_ammo_packs(owner)
      zp_set_user_ammo_packs(owner, ap + 1)
     }
    }
   }
  }
   
  remove_entity(EntID)
}

Вот код %) %) %)

 
PAHANCSДата: Понедельник, 13.07.2009, 03:53:30 | Сообщение # 2
Полковник
Группа: Пользователи
Сообщений: 183
Репутация: 4
Статус: Не в сети
Для нанесения урона игроку можно использовать эту функцию:

#include <hamsandwich>

Code

  /**
   * Description:  Usually called whenever an entity takes any kind of damage.
   *     Inflictor is the entity that caused the damage (such as a gun).
   *     Attacker is the entity that tirggered the damage (such as the gun's owner).
   * Forward params:    function(this, idinflictor, idattacker, Float:damage, damagebits);
   * Return type:  Integer.
   * Execute params:    ExecuteHam(Ham_TakeDamage, this, idinflictor, idattacker, Float:damage, damagebits);
   */
  Ham_TakeDamage



PAHANCS
 
AMX Mod X Форум » Скриптинг » Помощь по скриптингу » Не получается нанести урон игроку (хелп)
  • Страница 1 из 1
  • 1
Поиск:

AMX Mod X Russian Community © 2006-2024