设为首页收藏本站新闻投稿

MOD中国同盟社

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1129|回复: 6

[求助] 跪求帮忙检查一下武器插件的源码 [复制链接]

Rank: 5Rank: 5

帖子
448
精华
0
声望
1150 点
金币
134 Mold
被赞许
0 次
注册时间
2009-3-28
发表于 2010-7-13 20:08:41 |显示全部楼层
上午看见论坛里发m249ex的模型.还有声音 我看看能不能写成插件 但是我写好了,也没有错误 M菜单里面就是不显示
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <engine>
  4. #include <hamsandwich>
  5. #include <zombieplague>
  6. const m249ex_ap_cost = 40 // Ammo packs Cost
  7. new const m249ex_viewmodel[] = "models/wanpub/v_m249ex.mdl" // View Weapon Model (v_)
  8. new const m249ex_playermodel[] = "models/wanpub/p_m249ex.mdl" // Player Weapon Model (p_)
  9. new const m249ex_worldmodel[] = "models/w_m249.mdl" // World Weapon Model (w_)
  10. new const m249ex_sounds[][] =
  11. {
  12. "weapons/m249ex-1.wav",
  13. "weapons/m249ex-2.wav"
  14. }

  15. new Float:m249ex_mins[3] = { -2.0, -2.0, -2.0 }
  16. new Float:m249ex_maxs[3] = { 2.0, 2.0, 2.0 }
  17. new g_iItemID, g_msgCurWeapon, g_msgSayText
  18. new g_iHasm249ex[33], g_iCurrentWeapon[33]

  19. new cvar_enable, cvar_dmgmult, cvar_oneround, cvar_sounds, cvar_dmggore, cvar_dropflags, cvar_body_xplode

  20. const DROPFLAG_NORMAL = (1<<0) // "a", with "drop" clcmd (pressing G by default)
  21. const DROPFLAG_INDEATH = (1<<1) // "b", death victim
  22. const DROPFLAG_INFECTED = (1<<2) // "c", user infected
  23. const DROPFLAG_SURVHUMAN = (1<<3) // "d", user become survivor
  24. const m_pPlayer = 41
  25. const m_flNextPrimaryAttack = 46
  26. const m_flNextSecondaryAttack = 47
  27. const m_flTimeWeaponIdle = 48

  28. new const oldm249_sounds[][] =
  29. {
  30. "weapons/m249-1.wav",
  31. "weapons/m249-2.wav"
  32. }

  33. public plugin_init()
  34. {
  35. register_plugin("[ZP] Extra Item: m249ex", "1", "2")

  36. register_event("HLTV", "event_RoundStart", "a", "1=0", "2=0")
  37. register_event("CurWeapon", "event_CurWeapon", "b", "1=1")

  38. cvar_enable = register_cvar("zp_m249ex_enable", "1")
  39. cvar_sounds = register_cvar("zp_m249ex_custom_sounds", "1")
  40. cvar_dmgmult = register_cvar("zp_m249ex_damage_mult", "1.5")
  41. cvar_dmggore = register_cvar("zp_m249ex_gore_in_damage", "1")
  42. cvar_oneround = register_cvar("zp_m249ex_oneround", "1")
  43. cvar_dropflags = register_cvar("zp_m249ex_drop_flags", "abcd")
  44. cvar_body_xplode = register_cvar("zp_m249ex_victim_explode", "1")

  45. new szCvar[30]
  46. formatex(szCvar, charsmax(szCvar), "v%s by %s", "1", "2")
  47. register_cvar("zp_extra_m249ex", szCvar, FCVAR_SERVER|FCVAR_SPONLY)

  48. register_forward(FM_EmitSound, "fw_EmitSound")

  49. register_touch("cs_chainsaw", "player", "fw_m249ex_Touch")

  50. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
  51. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  52. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  53. RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m249", "fw_m249PrimaryAttack_Post", 1)

  54. g_iItemID = zp_register_extra_item("M249EX", m249ex_ap_cost, ZP_TEAM_HUMAN)

  55. g_msgSayText = get_user_msgid("SayText")
  56. g_msgCurWeapon = get_user_msgid("CurWeapon")

  57. register_clcmd("drop", "clcmd_drop")
  58. }

  59. public plugin_precache()
  60. {
  61. precache_model(m249ex_viewmodel)
  62. precache_model(m249ex_playermodel)
  63. precache_model(m249ex_worldmodel)

  64. for(new i = 0; i < sizeof m249ex_sounds; i++)
  65. precache_sound(m249ex_sounds[i])

  66. precache_sound("items/gunpickup4.wav")
  67. }

  68. public event_RoundStart()
  69. {
  70. remove_entity_name("cs_m249ex")
  71. }

  72. public event_CurWeapon(id)
  73. {
  74. // Not alive...
  75. if(!is_user_alive(id))
  76. return PLUGIN_CONTINUE

  77. g_iCurrentWeapon[id] = read_data(2)

  78. if(zp_get_user_zombie(id) || zp_get_user_survivor(id))
  79. return PLUGIN_CONTINUE

  80. if(!g_iHasm249ex[id] || g_iCurrentWeapon[id] != CSW_M249)
  81. return PLUGIN_CONTINUE

  82. entity_set_string(id, EV_SZ_viewmodel, m249ex_viewmodel)
  83. entity_set_string(id, EV_SZ_weaponmodel, m249ex_playermodel)

  84. return PLUGIN_CONTINUE
  85. }

  86. /*================================================================================
  87. [Main Functions]
  88. =================================================================================*/

  89. public clcmd_drop(id)
  90. {
  91. if(g_iHasm249ex[id] && g_iCurrentWeapon[id] == CSW_M249)
  92. {
  93. if(check_drop_flag(DROPFLAG_NORMAL))
  94. {
  95. drop_m249ex(id)
  96. return PLUGIN_HANDLED
  97. }
  98. }

  99. return PLUGIN_CONTINUE
  100. }

  101. public drop_m249ex(id)
  102. {
  103. static Float:flAim[3], Float:flOrigin[3]
  104. VelocityByAim(id, 64, flAim)
  105. entity_get_vector(id, EV_VEC_origin, flOrigin)

  106. flOrigin[0] += flAim[0]
  107. flOrigin[1] += flAim[1]

  108. new iEnt = create_entity("info_target")

  109. entity_set_string(iEnt, EV_SZ_classname, "cs_m249ex")

  110. entity_set_origin(iEnt, flOrigin)

  111. entity_set_model(iEnt, m249ex_worldmodel)

  112. set_size(iEnt, m249ex_mins, m249ex_maxs)
  113. entity_set_vector(iEnt, EV_VEC_mins, m249ex_mins)
  114. entity_set_vector(iEnt, EV_VEC_maxs, m249ex_maxs)

  115. entity_set_int(iEnt, EV_INT_solid, SOLID_TRIGGER)

  116. entity_set_int(iEnt, EV_INT_movetype, MOVETYPE_TOSS)

  117. g_iHasm249ex[id] = false

  118. reset_user_m249(id)
  119. }

  120. public reset_user_m249(id)
  121. {
  122. if(user_has_weapon(id, CSW_M249))
  123. ExecuteHamB(Ham_Item_Deploy, find_ent_by_owner(-1, "weapon_m249", id))

  124. engclient_cmd(id, "weapon_m249")
  125. emessage_begin(MSG_ONE, g_msgCurWeapon, _, id)
  126. ewrite_byte(1) // active
  127. ewrite_byte(CSW_M249) // weapon
  128. ewrite_byte(-1) // clip
  129. emessage_end()
  130. }
  131. public zp_extra_item_selected(id, itemid)
  132. {
  133. if (itemid == g_iItemID)
  134. {
  135. if(get_pcvar_num(cvar_enable))
  136. {
  137. if (g_iHasm249ex[id])
  138. {
  139. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + m249ex_ap_cost)
  140. }
  141. else
  142. {
  143. g_iHasm249ex[id] = true

  144. emit_sound(id, CHAN_WEAPON, "items/gunpickup2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)

  145. reset_user_m249(id)
  146. }
  147. }
  148. else
  149. {
  150. zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + m249ex_ap_cost)
  151. client_printcolor(id, "/y 道具被禁用")
  152. }
  153. }
  154. }

  155. public zp_user_infected_pre(id, infector)
  156. {
  157. if (g_iHasm249ex[id])
  158. {
  159. if(check_drop_flag(DROPFLAG_INFECTED))
  160. drop_m249ex(id)
  161. else
  162. {
  163. g_iHasm249ex[id] = false
  164. reset_user_m249(id)
  165. }
  166. }
  167. }

  168. public zp_user_humanized_post(id)
  169. {
  170. if(zp_get_user_survivor(id) && g_iHasm249ex[id])
  171. {
  172. if(check_drop_flag(DROPFLAG_SURVHUMAN))
  173. drop_m249ex(id)
  174. else
  175. {
  176. g_iHasm249ex[id] = false
  177. reset_user_m249(id)
  178. }
  179. }
  180. }

  181. public client_putinserver(id)
  182. {
  183. g_iHasm249ex[id] = false
  184. }

  185. public client_disconnect(id)
  186. {
  187. g_iHasm249ex[id] = false
  188. }

  189. public fw_PlayerSpawn_Post(id)
  190. {
  191. if(get_pcvar_num(cvar_oneround) || !get_pcvar_num(cvar_enable))
  192. {
  193. if(g_iHasm249ex[id])
  194. {
  195. g_iHasm249ex[id] = false

  196. reset_user_m249(id)
  197. }
  198. }
  199. }
  200. public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_bits)
  201. {
  202. if(victim == attacker || !attacker)
  203. return HAM_IGNORED

  204. if(!is_user_connected(attacker))
  205. return HAM_IGNORED

  206. if(g_iHasm249ex[attacker] && g_iCurrentWeapon[attacker] == CSW_M249)
  207. {
  208. if(get_pcvar_num(cvar_dmggore))
  209. a_lot_of_blood(victim)

  210. SetHamParamFloat(4, damage * get_pcvar_float(cvar_dmgmult))

  211. }

  212. }

  213. public fw_PlayerKilled(victim, attacker, shouldgib)
  214. {
  215. if(victim == attacker || !attacker)
  216. return HAM_IGNORED

  217. if(!is_user_connected(attacker))
  218. return HAM_IGNORED

  219. if(g_iHasm249ex[attacker] && g_iCurrentWeapon[attacker] == CSW_M249 && !zp_get_user_nemesis(victim) && get_pcvar_num(cvar_body_xplode))
  220. SetHamParamInteger(3, 2) // Body Explodes

  221. if(g_iHasm249ex[victim])
  222. {
  223. if(check_drop_flag(DROPFLAG_INDEATH))
  224. drop_m249ex(victim)
  225. else
  226. {
  227. g_iHasm249ex[victim] = false
  228. reset_user_m249(victim)
  229. }
  230. }

  231. return HAM_IGNORED
  232. }

  233. public fw_m249ex_Touch(saw, player)
  234. {
  235. if(!is_valid_ent(saw) || !is_valid_ent(player))
  236. return PLUGIN_CONTINUE

  237. if(!is_user_connected(player))
  238. return PLUGIN_CONTINUE

  239. if(!is_user_alive(player) || zp_get_user_zombie(player) || zp_get_user_survivor(player) || g_iHasm249ex[player])
  240. return PLUGIN_CONTINUE

  241. g_iHasm249ex[player] = true

  242. emit_sound(player, CHAN_WEAPON, "items/gunpickup4.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)

  243. reset_user_m249(player)

  244. remove_entity(saw)

  245. return PLUGIN_CONTINUE
  246. }

  247. public fw_EmitSound(id, channel, const sound[])
  248. {
  249. if(!is_user_connected(id))
  250. return FMRES_IGNORED

  251. if(!is_user_alive(id) || zp_get_user_zombie(id) || zp_get_user_survivor(id) || !g_iHasm249ex[id] || !get_pcvar_num(cvar_sounds))
  252. return FMRES_IGNORED

  253. for(new i = 0; i < sizeof m249ex_sounds; i++)
  254. {
  255. if(equal(sound, oldm249_sounds[i]))
  256. {
  257. emit_sound(id, channel, m249ex_sounds[i], 1.0, ATTN_NORM, 0, PITCH_NORM)
  258. return FMRES_SUPERCEDE
  259. }
  260. }

  261. return FMRES_IGNORED
  262. }

  263. check_drop_flag(flag)
  264. {
  265. new szFlags[10]
  266. get_pcvar_string(cvar_dropflags, szFlags, charsmax(szFlags))

  267. if(read_flags(szFlags) & flag)
  268. return true

  269. return false
  270. }

  271. a_lot_of_blood(id)
  272. {
  273. static iOrigin[3]
  274. get_user_origin(id, iOrigin)

  275. message_begin(MSG_PVS, SVC_TEMPENTITY, iOrigin)
  276. write_byte(TE_BLOODSTREAM)
  277. write_coord(iOrigin[0])
  278. write_coord(iOrigin[1])
  279. write_coord(iOrigin[2]+10)
  280. write_coord(random_num(-360, 360)) // x
  281. write_coord(random_num(-360, 360)) // y
  282. write_coord(-10) // z
  283. write_byte(70) // color
  284. write_byte(random_num(50, 100)) // speed
  285. message_end()

  286. for (new j = 0; j < 4; j++)
  287. {
  288. message_begin(MSG_PVS, SVC_TEMPENTITY, iOrigin)
  289. write_byte(TE_WORLDDECAL)
  290. write_coord(iOrigin[0]+random_num(-100, 100))
  291. write_coord(iOrigin[1]+random_num(-100, 100))
  292. write_coord(iOrigin[2]-36)
  293. write_byte(random_num(190, 197)) // index
  294. message_end()
  295. }
  296. }

  297. stock client_printcolor(const id, const input[], any:...)
  298. {
  299. new iCount = 1, iPlayers[32]

  300. static szMsg[191]
  301. vformat(szMsg, charsmax(szMsg), input, 3)

  302. replace_all(szMsg, 190, "/g", "^4") // green txt
  303. replace_all(szMsg, 190, "/y", "^1") // orange txt
  304. replace_all(szMsg, 190, "/ctr", "^3") // team txt
  305. replace_all(szMsg, 190, "/w", "^0") // team txt

  306. if(id) iPlayers[0] = id
  307. else get_players(iPlayers, iCount, "ch")

  308. for (new i = 0; i < iCount; i++)
  309. {
  310. if (is_user_connected(iPlayers[i]))
  311. {
  312. message_begin(MSG_ONE_UNRELIABLE, g_msgSayText, _, iPlayers[i])
  313. write_byte(iPlayers[i])
  314. write_string(szMsg)
  315. message_end()
  316. }
  317. }
  318. }
  319. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  320. *{\\ rtf1\\ ansi\\ ansicpg936\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset134 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang2052\\ f0\\ fs16 \n\\ par }
  321. */
复制代码
不想这样看的这里有
附件:[color]
                        各位PAWN高手帮忙看看啊..
附件: 你需要登录才可以下载或查看附件。没有帐号?注册

使用道具 举报

Rank: 10Rank: 10Rank: 10

帖子
3735
精华
1
声望
5900 点
金币
2148 Mold
被赞许
47 次
注册时间
2009-12-20

优秀版主奖 Modchina灌水王 星界财团 可爱小猫

发表于 2010-7-13 20:29:19 |显示全部楼层
好像没写购买的名字哦
至于你信不信,我反正信了

使用道具 举报

Rank: 10Rank: 10Rank: 10

帖子
1250
精华
0
声望
3577 点
金币
470 Mold
被赞许
45 次
注册时间
2010-7-13

可爱小猫

发表于 2010-7-13 20:43:46 |显示全部楼层
写的的确没错,但是没有写上显示道具和名称

使用道具 举报

头像被屏蔽

禁止发言

帖子
667
精华
0
声望
558 点
金币
1135 Mold
被赞许
3 次
注册时间
2009-8-2
发表于 2010-7-13 21:15:54 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽

使用道具 举报

Rank: 5Rank: 5

帖子
448
精华
0
声望
1150 点
金币
134 Mold
被赞许
0 次
注册时间
2009-3-28
发表于 2010-7-13 21:42:54 |显示全部楼层
我往前面加了个
new const g_item_name[] = {"M249-EX"}

后面改成
g_iItemID = zp_register_extra_item( g_item_name , m249ex_ap_cost, ZP_TEAM_HUMAN)
这样写不对吗? 求指点.

使用道具 举报

头像被屏蔽

禁止发言

帖子
667
精华
0
声望
558 点
金币
1135 Mold
被赞许
3 次
注册时间
2009-8-2
发表于 2010-7-13 21:49:36 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽

使用道具 举报

Rank: 5Rank: 5

帖子
448
精华
0
声望
1150 点
金币
134 Mold
被赞许
0 次
注册时间
2009-3-28
发表于 2010-7-13 22:13:31 |显示全部楼层
本帖最后由 zh8829zh 于 2010-7-13 22:24 编辑

感谢IS.......不过我那样改了怎么还是不显示. 而且还编译失败

Error 035 : argument type mismatch  <argument  1 >

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

回顶部