广告广告
  加入我的最爱 设为首页 风格修改
首页 首尾
 手机版   订阅   地图  繁体 
您是第 2157 个阅读者
 
发表文章 发表投票 回覆文章
  可列印版   加为IE收藏   收藏主题   上一主题 | 下一主题   
xiangxiang
个人文章 个人相簿 个人日记 个人地图
路人甲
级别: 路人甲 该用户目前不上站
推文 x1 鲜花 x2
分享: 转寄此文章 Facebook Plurk Twitter 复制连结到剪贴簿 转换为繁体 转换为简体 载入图片
推文 x0
[1.6][插件] 为什么新武器源码的效果有问题?
               这个武器插件用了是可以用,不过在弹夹打完后扔掉,选同一样的普通的枪,在捡起它,重复做,有时候会不知道怎么,会自动退出游戏。不知道是源码哪里不足或是错误,希望大家改进一下,顺便说说怎么回事,不要直接改在上面。谢谢[code][/code]#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike>
#include <zombieplague>
#include <xs>
#define SUPPORT_CZBOT
#if defined SUPPORT_CZBOT
new cvar_botquota
new bool:BotHasDebug = false
#endif
#define TASK_RESET_WEAPON 12345
const OFFSET_FlNextPrimaryAttack = 46
const OFFSET_LINUX_WEAPONS = 4
const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_AUG)
new const xaug_V_Model[] = { "models/v_aug1.mdl" }
new const xaug_P_Model[] = { "models/p_aug1.mdl" }
new const xaug_W_Model[] = { "models/w_aug1.mdl" }
new const g_item_name[] = { "人类道具:变态AUG" }
new g_itemid_xaug
new cvar_xaug_cost, cvar_dmg_multiplier, cvar_knock_power, cvar_fire_rate, cvar_bullet_tracer
new g_beamSpr
new g_maxplayers
new bool:has_xaug[33] = { false, ... }
new user_clip[33] = { 0, ... }, user_bpammo[33] = { 0, ... }
new user_drop[33] = { -1, ... }, Float:drop_time[33] = { 0.0, ... }
new bool:user_shoot[33] = { false, ... }
public plugin_init()
{
 register_plugin("Make your own weapon", "4.0", "FOT")
 
 cvar_xaug_cost = register_cvar("zp_lahumshi_cost", "20")
 cvar_dmg_multiplier = register_cvar("zp_lahumshi_dmgmultiplier", "5")
 cvar_knock_power = register_cvar("zp_lahumshi_knockpower", "5")
 cvar_fire_rate = register_cvar("zp_lahumshi_firerate", "0.2")
 
 g_itemid_xaug = zp_register_extra_item(g_item_name, get_pcvar_num(cvar_xaug_cost), ZP_TEAM_HUMAN)
 
 RegisterHam(Ham_TakeDamage, "player", "fw_Player_TakeDamage")
 RegisterHam(Ham_TraceAttack, "player", "fw_Player_TraceAttack")
 RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_aug", "fw_aug_PriAttack")
 RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_aug", "fw_aug_PriAttack_Post", 1)
 
 register_forward(FM_SetModel, "fw_SetModel")
 register_forward(FM_Touch, "fw_Touch")
 
 register_event("CurWeapon", "event_cur_weapon", "be", "1=1")
 register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
 
 g_maxplayers = get_maxplayers()
 
 #if defined SUPPORT_CZBOT
 cvar_botquota = get_cvar_pointer("bot_quota")
 #endif
}
public plugin_precache()
{
 precache_model(xaug_V_Model)
 precache_model(xaug_P_Model)
 precache_model(xaug_W_Model)
 
 g_beamSpr = precache_model("sprites/zbeam4.spr")
}
public zp_extra_item_selected (id, itemid)
{
 if (itemid == g_itemid_xaug)
 {
  if (has_xaug[id] && user_has_weapon(id, CSW_AUG))
  {
   zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + get_pcvar_num(cvar_xaug_cost))
   client_print(id, print_chat, "[ZP] 你已经拥有变态AUG了.")
   return PLUGIN_CONTINUE;
  }
  
  user_drop_aug(id)
  has_xaug[id] = true
  fm_give_item(id, "weapon_aug")
  cs_set_user_bpammo(id, CSW_AUG, 300)
  engclient_cmd(id, "weapon_aug")
  
  client_print(id, print_chat, "[ZP] 你购买了变态AUG!!!!");
 }
 
 return PLUGIN_CONTINUE;
}
user_drop_aug(id)
{
 if (user_has_weapon(id, CSW_AUG))
 {
  engclient_cmd(id, "drop", "weapon_aug")
 }
}
public fw_Player_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
{
 static Float:damage_multiplier
 damage_multiplier = get_pcvar_float(cvar_dmg_multiplier)
 if (damage_multiplier <= 0.0)
  return HAM_IGNORED;
 
 if (victim == attacker || !is_user_connected(attacker))
  return HAM_IGNORED;
 
 if (zp_get_user_zombie(victim) == zp_get_user_zombie(attacker))
  return HAM_IGNORED;
 
 if (!(damage_type & DMG_BULLET))
  return HAM_IGNORED;
 
 if (!has_xaug[attacker] || (get_user_weapon(attacker) != CSW_AUG))
  return HAM_IGNORED;
 
 SetHamParamFloat(4, damage * damage_multiplier)
 
 return HAM_IGNORED;
}
public fw_Player_TraceAttack(victim, attacker, Float:damage, Float:direction[3], tracehandle, damage_type)
{
 static Float:knockpower
 knockpower = get_pcvar_float(cvar_knock_power)
 if (knockpower <= 0.0)
  return HAM_IGNORED;
 
 if (victim == attacker || !is_user_connected(attacker))
  return HAM_IGNORED;
 
 if (zp_get_user_zombie(attacker) == zp_get_user_zombie(victim))
  return HAM_IGNORED;
 
 if (!zp_get_user_zombie(victim) || zp_get_user_nemesis(victim))
  return HAM_IGNORED;
 
 if (!(damage_type & DMG_BULLET) || !get_cvar_num("zp_knockback"))
  return HAM_IGNORED;
 
 if (!has_xaug[attacker] || (get_user_weapon(attacker) != CSW_AUG))
  return HAM_IGNORED;
 
 static victimflags, Float:knockduck
 victimflags = pev(victim, pev_flags)
 knockduck = get_cvar_float("zp_knockback_ducking")
 
 if (knockduck == 0.0 && (victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
  return HAM_IGNORED;
 
 static Float:origin1F[3], Float:origin2F[3]
 pev(victim, pev_origin, origin1F)
 pev(attacker, pev_origin, origin2F)
 
 if (get_distance_f(origin1F, origin2F) > get_cvar_float("zp_knockback_distance"))
  return HAM_IGNORED;
 
 static Float:velocity[3]
 pev(victim, pev_velocity, velocity)
 
 if (get_cvar_num("zp_knockback_damage"))
  xs_vec_mul_scalar(direction, damage, direction)
 
 if (knockpower > 0.0 && get_cvar_num("zp_knockback_power"))
  xs_vec_mul_scalar(direction, knockpower, direction)
 
 if ((victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
  xs_vec_mul_scalar(direction, knockduck, direction)
 
 xs_vec_add(velocity, direction, direction)
 
 if (!get_cvar_num("zp_knockback_zvel"))
  direction[2] = velocity[2]
 
 set_pev(victim, pev_velocity, direction)
 
 SetHamParamVector(4, Float:{0.0, 0.0, 0.0})
 
 return HAM_IGNORED;
}
public fw_aug_PriAttack(weapon)
{
 if (!pev_valid(weapon))
  return HAM_IGNORED;
 
 static owner
 owner = pev(weapon, pev_owner)
 
 if (has_xaug[owner])
 {
  if (cs_get_weapon_ammo(weapon) > 0)
  {
   user_shoot[owner] = true
  }
 }
 
 return HAM_IGNORED;
}
public fw_aug_PriAttack_Post(weapon)
{
 if (!pev_valid(weapon))
  return HAM_IGNORED;
 
 static owner
 owner = pev(weapon, pev_owner)
 
 if (has_xaug[owner])
 {
  if (user_shoot[owner])
  {
   static Float:fire_rate
   fire_rate = get_pcvar_float(cvar_fire_rate)
   if (fire_rate > 0.0)
   {
    static Float:next_pri_attack_time
    next_pri_attack_time = get_weapon_next_pri_attack(weapon) * fire_rate
    set_weapon_next_pri_attack(weapon, next_pri_attack_time)
   }
   
   if (get_pcvar_num(cvar_bullet_tracer))
   {
    static Float:origin1[3], Float:origin2[3] //, iOrigin[3]
    fm_get_aim_vector(owner, 40, origin1, origin2)
    origin1[2] += (pev(owner, pev_flags) & FL_DUCKING) ? 3.0 : -7.0
    show_tracer_effect(origin1, origin2)
   }
   
   user_shoot[owner] = false
  }
 }
 
 return HAM_IGNORED;
}
show_tracer_effect(const Float:start_point[3], const Float:end_point[3])
{
 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
 write_byte(TE_BEAMPOINTS) // TE id: 0
 engfunc(EngFunc_WriteCoord, start_point[0]) // x
 engfunc(EngFunc_WriteCoord, start_point[1]) // y
 engfunc(EngFunc_WriteCoord, start_point[2]) // z
 engfunc(EngFunc_WriteCoord, end_point[0]) // x
 engfunc(EngFunc_WriteCoord, end_point[1]) // y
 engfunc(EngFunc_WriteCoord, end_point[2]) // z
 write_short(g_beamSpr) // sprite index
 write_byte(0) // starting frame
 write_byte(1) // frame rate in 0.1's
 write_byte(1) // life in 0.1's
 write_byte(30) // line width in 0.1's
 write_byte(0) // noise amplitude in 0.01's
 write_byte(0) // red (R.G.B)
 write_byte(245) // green (R.G.B)
 write_byte(255) // blue (R.G.B)
 write_byte(255) // brightness
 write_byte(0) // scroll speed in 0.1's
 message_end()
}
public fw_SetModel(entity, const model[])
{
 if (!pev_valid(entity))
  return FMRES_IGNORED;
 
 new owner
 owner = pev(entity, pev_owner)
 
 if (equal(model[7], "w_weaponbox.mdl"))
 {
  user_drop[owner] = entity;
  return FMRES_IGNORED;
 }
 
 if (user_drop[owner] == entity)
 {
  if (has_xaug[owner] && equal(model[7], "w_aug.mdl"))
  {
   fm_kill_entity(entity)
   
   if (!is_user_alive(owner) || zp_get_user_zombie(owner))
    drop_xaug(owner, 1, 0)
   else
    drop_xaug(owner, 0, 1)
   
   drop_time[owner] = get_gametime()
   has_xaug[owner] = false
  }
 }
 
 user_drop[owner] = -1
 
 return FMRES_IGNORED;
}
public fw_Touch(ptr, ptd)
{
 if (!pev_valid(ptr) || !pev_valid(ptd))
  return FMRES_IGNORED;
 
 new classname[32]
 pev(ptr, pev_classname, classname, charsmax(classname))
 
 if (!equal(classname, "ZP_xaug"))
  return FMRES_IGNORED;
 
 if (!(1 <= ptd <= 32) || !is_user_alive(ptd) || zp_get_user_zombie(ptd) || zp_get_user_survivor(ptd))
  return FMRES_IGNORED;
 
 if (has_custom_weapons(ptd, PRIMARY_WEAPONS_BIT_SUM))
  return FMRES_IGNORED;
 
 if (get_gametime() - drop_time[ptd] < 0.5)
  return FMRES_IGNORED;
 
 has_xaug[ptd] = true
 fm_give_item(ptd, "weapon_aug")
 
 static weap_clip, user_bpammo, weap_ent
 weap_clip = pev(ptr, pev_iuser3)
 user_bpammo = min(cs_get_user_bpammo(ptd, CSW_AUG) + pev(ptr, pev_iuser4), 30)
 weap_ent = fm_find_ent_by_owner(-1, "weapon_aug", ptd)
 
 cs_set_weapon_ammo(weap_ent, weap_clip)
 cs_set_user_bpammo(ptd, CSW_AUG, user_bpammo)
 
 engfunc(EngFunc_RemoveEntity, ptr)
 
 client_print(ptd, print_chat, "[ZP] 你捡到了一把变态AUG.")
 
 return FMRES_IGNORED;
}
public event_cur_weapon(id)
{
 if (!has_xaug[id])
  return;
 
 new weap_id, weap_clip, weap_bpammo
 weap_id = get_user_weapon(id, weap_clip, weap_bpammo)
 
 if (weap_id != CSW_AUG)
  return;
 
 set_xaug_model(id)
 user_clip[id] = weap_clip
 user_bpammo[id] = weap_bpammo
 user_shoot[id] = false
}
public set_xaug_model(id)
{
 set_pev(id, pev_viewmodel2, xaug_V_Model)
 set_pev(id, pev_weaponmodel2, xaug_P_Model)
}
public drop_xaug(id, store_bpammo, drop_type)
{
 new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
 
 if (!pev_valid(ent))return 0;
 
 set_pev(ent, pev_classname, "ZP_xaug")
 set_pev(ent, pev_iuser1, 0) // hasn't bounced yet
 set_pev(ent, pev_solid, SOLID_TRIGGER)
 set_pev(ent, pev_movetype, MOVETYPE_TOSS)
 
 new Float:mins[3] = { -16.0, -16.0, -16.0 }
 new Float:maxs[3] = { 16.0, 16.0, 16.0 }
 engfunc(EngFunc_SetSize, ent, mins, maxs)
 
 set_pev(ent, pev_iuser3, user_clip[id])
 
 if (store_bpammo)
 {
  set_pev(ent, pev_iuser4, user_bpammo[id])
  cs_set_user_bpammo(id, CSW_AUG, 0)
 }
 else
 {
  set_pev(ent, pev_iuser4, 0)
 }
 
 new Float:angles[3]
 pev(id, pev_angles, angles)
 angles[0] = angles[2] = 0.0
 set_pev(ent, pev_angles, angles)
 
 engfunc(EngFunc_SetModel, ent, xaug_W_Model)
 
 new Float:origin[3]
 pev(id, pev_origin, origin)
 
 if (drop_type)
 {
  new Float:velocity[3]
  velocity_by_aim(id, 15, velocity)
  origin[0] += velocity[0]
  origin[1] += velocity[1]
  origin[2] += velocity[2]
  set_pev(ent, pev_origin, origin)
  velocity_by_aim(id, 400, velocity)
  set_pev(ent, pev_velocity, velocity)
 }
 else
 {
  new Float:drop_angle = random_float(0.0, 360.0)
  origin[0] += 15.0 * floatcos(drop_angle, degrees)
  origin[1] += 15.0 * floatsin(drop_angle, degrees)
  set_pev(ent, pev_origin, origin)
 }
 
 return 1;
}
public client_connect(id)
{
 has_xaug[id] = false
}
public client_disconnect(id)
{
 has_xaug[id] = false
}
public reset_xaug()
{
 for (new id = 1; id <= g_maxplayers; id++)
 {
  if (is_user_connected(id) && is_user_alive(id) && has_xaug[id] && !user_has_weapon(id, CSW_AUG))
  {
   has_xaug[id] = false
  }
 }
}
stock drop_primary_weapons(id)
{
 static weapons[32], num, i, weaponid
 num = 0
 get_user_weapons(id, weapons, num)
 
 for (i = 0; i < num; i++)
 {
  weaponid = weapons
  
  if ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)
  {
   static wname[32]
   get_weaponname(weaponid, wname, sizeof wname - 1)
   engclient_cmd(id, "drop", wname)
  }
 }
}
stock fm_give_item(index, const item[])
{
 if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
  return 0
 
 new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
 if (!pev_valid(ent))
  return 0
 
 new Float:origin[3]
 pev(index, pev_origin, origin)
 set_pev(ent, pev_origin, origin)
 set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN)
 dllfunc(DLLFunc_Spawn, ent)
 
 new save = pev(ent, pev_solid)
 dllfunc(DLLFunc_Touch, ent, index)
 if (pev(ent, pev_solid) != save)
  return ent
 
 engfunc(EngFunc_RemoveEntity, ent)
 
 return -1
}
stock bool:has_custom_weapons(id, const bitsum)
{
 static weapons[32], num, i, weaponid
 num = 0
 get_user_weapons(id, weapons, num)
 
 for (i = 0; i < num; i++)
 {
  weaponid = weapons
  
  if ((1<<weaponid) & bitsum)
   return true;
 }
 
 return false;
}
stock fm_find_ent_by_owner(entity, const classname[], owner)
{
 while ((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", classname)) && (pev(entity, pev_owner) != owner)) {}
 
 return entity;
}
stock fm_find_ent_by_class(index, const classname[])
{
 return engfunc(EngFunc_FindEntityByString, index, "classname", classname)
}
stock fm_kill_entity(index)
{
 set_pev(index, pev_flags, pev(index, pev_flags) | FL_KILLME);
 
 return 1;
}
stock Float:get_weapon_next_pri_attack(entity)
{
 return get_pdata_float(entity, OFFSET_FlNextPrimaryAttack, OFFSET_LINUX_WEAPONS)
}
stock set_weapon_next_pri_attack(entity, Float:time)
{
 set_pdata_float(entity, OFFSET_FlNextPrimaryAttack, time, OFFSET_LINUX_WEAPONS)
}
stock fm_get_aim_vector(index, forward_distance, Float:forward_origin[3], Float:view_end_origin[3])
{
 new Float:start[3], Float:view_ofs[3]
 pev(index, pev_origin, start);
 pev(index, pev_view_ofs, view_ofs);
 xs_vec_add(start, view_ofs, start);
 
 new Float:vector[3], Float:temp[3];
 pev(index, pev_v_angle, vector);
 engfunc(EngFunc_MakeVectors, vector);
 global_get(glb_v_forward, vector);
 xs_vec_mul_scalar(vector, float(forward_distance), temp);
 xs_vec_add(start, temp, forward_origin);
 
 new Float:dest[3]
 xs_vec_mul_scalar(vector, 9999.0, temp);
 xs_vec_add(start, temp, dest);
 engfunc(EngFunc_TraceLine, start, dest, 0, index, 0);
 get_tr2(0, TR_vecEndPos, view_end_origin);
 
 return 1;
}
#if defined SUPPORT_CZBOT
// CZBot support
public client_putinserver(id)
{
 if (!cvar_botquota || !is_user_bot(id) || BotHasDebug)
  return;
 
 new classname[32]
 pev(id, pev_classname, classname, 31)
 
 if (!equal(classname, "player"))
  set_task(0.1, "_Debug", id)
}
public _Debug(id)
{
 // Make sure it's a CZ bot and it's still connected
 if (!get_pcvar_num(cvar_botquota) || !is_user_connected(id))
  return;
 
 BotHasDebug = true
 RegisterHamFromEntity(Ham_TakeDamage, id, "fw_Player_TakeDamage")
 RegisterHamFromEntity(Ham_TraceAttack, id, "fw_Player_TraceAttack")
}



献花 x0 回到顶端 [楼 主] From:未知地址 | Posted:2011-07-28 19:54 |

首页  发表文章 发表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.064039 second(s),query:15 Gzip disabled
本站由 瀛睿律师事务所 担任常年法律顾问 | 免责声明 | 本网站已依台湾网站内容分级规定处理 | 连络我们 | 访客留言