AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   what is wrong? (https://forums.alliedmods.net/showthread.php?t=185055)

Leech_v2 05-12-2012 09:17

what is wrong?
 
Code:


#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <fun>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN_NAME "hl2weapon_shotgun"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "水蛭"
new g_hamczbots
new g_haswpn[33]
const PRIMARY_WEAPONS = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const SECONDARY_WEAPONS = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
public plugin_init()
{
 register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
 register_clcmd("buyshotgun", "Clcmd_BuyShotgun")
 register_clcmd("say buyshotgun", "Clcmd_BuyShotgun")
 register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
 register_forward(FM_CmdStart, "fw_CmdStart")
 register_forward(FM_Touch, "fw_ShotgunTouch")
 register_forward(FM_SetModel, "fw_SetModel")
 RegisterHam(Ham_TakeDamage, "player",  "fw_TakeDamage")
 RegisterHam(Ham_Item_Deploy, "weapon_xm1014", "fw_ShotgunDeploy", 1)
 RegisterHam(Ham_Item_PostFrame, "weapon_xm1014", "fw_ShotgunPostFrame")
 RegisterHam(Ham_Weapon_Reload, "weapon_xm1014", "fw_ShotgunReload", 1)
 RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_xm1014", "fw_ShotgunAttack2")
}
public plugin_precache()
{
 precache_model("models/hl2_weapons/p_shotgun.mdl")
 precache_model("models/hl2_weapons/v_shotgun.mdl")
 precache_model("models/hl2_weapons/w_shotgun.mdl")
}
public client_putinserver(id)
{
 if (g_hamczbots) return
 if (!is_user_bot(id)) return
 set_task(0.1, "register_ham_czbots", id)
}
public register_ham_czbots(id)
{
 if (g_hamczbots || !is_user_connected(id)) return
 if (!is_user_bot(id)) return
 RegisterHamFromEntity(Ham_TakeDamage, id, "fw_TakeDamage")
 g_hamczbots = true
}
public Clcmd_BuyShotgun(id)
{
 if (!is_user_alive(id)) return
 if (get_user_team(id)!=2) return
 if (cs_get_user_money(id)<2100) return
 if (g_haswpn[id]) return
 drop_weapons(id, 1)
 give_item(id, "weapon_xm1014")
 cs_set_user_bpammo(id, CSW_XM1014, 30)
 cs_set_weapon_ammo(fm_get_wpnentity(id, CSW_XM1014), 6)
 g_haswpn[id] = true
 cs_set_user_money(id, cs_get_user_money(id)-2100, 1)
 if (get_user_weapon(id)==CSW_XM1014)
 {
  set_pev(id, pev_viewmodel2, any:"models/hl2_weapons/v_shotgun.mdl")
  set_pev(id, pev_weaponmodel2, any:"models/hl2_weapons/p_shotgun.mdl")
 }
}
public Event_CurWeapon(id)
{
 if (!is_user_alive(id)) return PLUGIN_CONTINUE
 new weapon = read_data(2)
 if (weapon==CSW_XM1014 && g_haswpn[id])
 {
  set_pdata_int(fm_get_wpnentity(id, CSW_XM1014), 55, 0, 4)
  set_pev(id, pev_viewmodel2, any:"models/hl2_weapons/v_shotgun.mdl")
  set_pev(id, pev_weaponmodel2, any:"models/hl2_weapons/p_shotgun.mdl")
 }
 return PLUGIN_CONTINUE
}
public fw_CmdStart(id, handle)
{
 if (!is_user_alive(id)) return FMRES_IGNORED
 if (!g_haswpn[id]) return FMRES_IGNORED
 if (get_user_weapon(id)!=CSW_XM1014) return FMRES_IGNORED
 new button = get_uc(handle, UC_Buttons)
 if (button & IN_ATTACK2 && get_pdata_float(id, 83, 5)<=0.0)
 {
  new ent = fm_get_wpnentity(id, CSW_XM1014)
  fw_ShotgunAttack2(ent)
  set_uc(handle, UC_Buttons, button&~IN_ATTACK2)
  return FMRES_SUPERCEDE
 }
 return FMRES_IGNORED
}
public fw_ShotgunTouch(ent, id)
{
 if (!pev_valid(ent)) return FMRES_IGNORED
 new model[33]
 pev(ent, pev_model, any:model, any:32)
 if (!equal(model, "models/hl2_weapons/w_shotgun.mdl")) return FMRES_IGNORED
 if (pev(ent, pev_iuser4)) return FMRES_IGNORED
 if (!is_user_alive(id)) return FMRES_IGNORED
 if (has_weapons(id, 1)) return FMRES_IGNORED
 g_haswpn[id] = true
 if (get_user_weapon(id)==CSW_XM1014)
 {
  set_pev(id, pev_viewmodel2, any:"models/hl2_weapons/v_shotgun.mdl")
  set_pev(id, pev_weaponmodel2, any:"models/hl2_weapons/p_shotgun.mdl")
 }
 return FMRES_IGNORED
}
public fw_SetModel(ent, const model[])
{
 if (!pev_valid(ent)) return FMRES_IGNORED
 if (!equali(model, "models/w_xm1014.mdl")) return FMRES_IGNORED
 new class[33]
 pev(ent, pev_classname, any:class, any:32)
 if (equal(class, "weaponbox"))
 {
  new id = pev(ent, pev_owner)
  if (g_haswpn[id])
  {
  entity_set_model(ent, "models/hl2_weapons/w_shotgun.mdl")
  set_pev(ent, pev_iuser4, any:1)
  set_task(0.1, "TouchFix", ent)
  g_haswpn[id] = false
  return FMRES_SUPERCEDE
  }
 }
 return FMRES_IGNORED
}
public TouchFix(ent)
{
 if (!pev_valid(ent)) return
 set_pev(ent, pev_iuser4, any:0)
}
public fw_TakeDamage(victim, inflictor, attacker, Float:dmg, damage_type)
{
 if (!is_user_connected(attacker)) return
 if (!pev(victim, pev_takedamage)) return
 if (!g_haswpn[attacker]) return
 if (damage_type & DMG_BULLET)
 {
  if (get_user_weapon(attacker)==CSW_XM1014) dmg *= 1.3
  SetHamParamFloat(4, dmg)
 }
}
public fw_ShotgunDeploy(ent)
{
 new id = get_pdata_cbase(ent, 41, 5)
 if (!is_user_alive(id)) return
 if (!g_haswpn[id]) return
 if (get_user_weapon(id)==CSW_XM1014)
 {
  set_pev(id, pev_viewmodel2, any:"models/hl2_weapons/v_shotgun.mdl")
  set_pev(id, pev_weaponmodel2, any:"models/hl2_weapons/p_shotgun.mdl")
 }
 set_pev(id, pev_weaponanim, any:6)
 new wpnent = fm_get_wpnentity(id, CSW_XM1014)
 set_pdata_float(id, 83, 0.8, 5)
 set_pdata_float(wpnent, 46, 0.8, 5)
 set_pdata_float(wpnent, 47, 0.8, 5)
}
public fw_ShotgunPostFrame(ent)
{
 new id = get_pdata_cbase(ent, 41, 4)
 if (!is_user_alive(id)) return
 if (!g_haswpn[id]) return
 new fInReload = get_pdata_int(ent, 54, 4)
 new Float:flNextAttack = get_pdata_float(id, 83, 5)
 new iClip = get_pdata_int(ent, 51, 4)
 new iMaxClip = 1
 new iAmmoType = 376+get_pdata_int(ent, 49, 4)
 new iBpAmmo = get_pdata_int(id, iAmmoType, 5)
 if (fInReload && flNextAttack<=0.0)
 {
  new j = min(iMaxClip-iClip, iBpAmmo)
  set_pdata_int(ent, 51, iClip+j, 4)
  set_pdata_int(id, iAmmoType, iBpAmmo-j, 5)
  set_pdata_int(ent, 54, 1, 4)
  fInReload = 1
 }
 new iButton = pev(id, pev_button)
 if ((iButton & IN_ATTACK2 && get_pdata_float(ent, 47, 4)<=0.0) || (iButton & IN_ATTACK && get_pdata_float(ent, 46, 4)<=0.0))
  return
 if (iButton & IN_RELOAD && !fInReload)
 {
  if (iClip>=iMaxClip)
  {
  set_pev(id, pev_button, iButton & ~IN_RELOAD)
  set_pev(id, pev_weaponanim, any:0)
  }
  else if (iClip<6 && iBpAmmo)
  {
  set_pev(id, pev_weaponanim, any:5)
  set_pdata_int(ent, 55, 1, 4)
  set_pdata_float(id, 83, 0.4, 5)
  set_pdata_float(ent, 48, 0.4, 4)
  }
 }
}
public fw_ShotgunReload(ent)
{
 new id = get_pdata_cbase(ent, 41, 4)
 if (!is_user_alive(id)) return
 if (!g_haswpn[id]) return
 set_pdata_float(id, 83, 0.2, 5)
 set_pdata_float(ent, 48, 0.2, 4)
 if (cs_get_weapon_ammo(ent)>=6)
 {
  set_pdata_int(ent, 54, 0, 4)
  set_pdata_int(ent, 55, 0, 4)
  set_pdata_float(id, 83, 0.4, 5)
  set_pev(id, pev_weaponanim, any:4)
  ExecuteHam(Ham_Weapon_WeaponIdle, ent)
 }
}
public fw_ShotgunAttack2(ent)
{
 new id = get_pdata_cbase(ent, 41, 4)
 if (!is_user_alive(id)) return HAM_IGNORED
 if (!g_haswpn[id]) return HAM_IGNORED
 if (get_pdata_int(ent, 54, 4)==1) return HAM_IGNORED
 if (cs_get_weapon_ammo(ent)<=1) return HAM_IGNORED
 if (cs_get_weapon_ammo(ent)-2>0) set_pdata_int(ent, 55, 0, 4)
 else set_task(1.0, "Reload", id)
 set_pdata_float(id, 83, 1.0, 5)
 set_pdata_float(ent, 48, 1.0, 4)
 set_pev(id, pev_weaponanim, any:8)
 cs_set_weapon_ammo(ent, cs_get_weapon_ammo(ent)-2)
 return HAM_IGNORED
}
public Reload(id)
{
 if (!is_user_alive(id)) return
 if (!g_haswpn[id]) return
 new ent = fm_get_wpnentity(id, CSW_XM1014)
 if (get_pdata_int(ent, 54, 4)==1) return
 if (get_pdata_int(ent, 55, 4)==1) return
 if (cs_get_weapon_ammo(ent)>5) return
 set_pev(id, pev_weaponanim, any:5)
 set_pdata_int(ent, 55, 1, 4)
 set_pdata_float(id, 83, 0.4, 5)
 set_pdata_float(ent, 48, 0.4, 4)
}
stock drop_weapons(id, dropwhat)
{
 static weapons[32], num, i, weaponid
 num = 0
 get_user_weapons(id, weapons, num)
 for (i=0;i<num;i++)
 {
  weaponid = weapons[i]
  if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS)))
  {
  static wname[32], weapon_ent
  get_weaponname(weaponid, wname, charsmax(wname))
  weapon_ent = fm_find_ent_by_owner(-1, wname, id)
  set_pev(weapon_ent, pev_iuser1, any:(cs_get_user_bpammo(id, weaponid)))
  engclient_cmd(id, "drop", wname)
  cs_set_user_bpammo(id, weaponid, 0)
  }
 }
}
stock fm_find_ent_by_owner(ent, const classname[], owner)
{
 while ((ent = engfunc(EngFunc_FindEntityByString, any:ent, any:"classname", any:classname)) && pev(ent, pev_owner) != owner) { /* keep looping */ }
 return ent;
}
stock fm_get_wpnentity(id, wpn)
{
 new weapon[32]
 get_weaponname(wpn, weapon, 31)
 new wEnt
 while ((wEnt = engfunc(EngFunc_FindEntityByString, any:wEnt, any:"classname", any:weapon)) && pev(wEnt,pev_owner) != id) {}
 if (!pev_valid(wEnt)) return 0
 return wEnt
}
stock has_weapons(id, class)
{
 static weapons[32], num, i, weaponid
 num = 0
 get_user_weapons(id, weapons, num)
 for (i=0;i<num;i++)
 {
  weaponid = weapons[i]
  if ((class == 1 && ((1<<weaponid) & PRIMARY_WEAPONS)) || (class == 2 && ((1<<weaponid) & SECONDARY_WEAPONS)))
  return 1
 }
 return 0
}


Reload has only insert 1 bullet.


All times are GMT -4. The time now is 00:25.

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