Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  1. /*======================================================*\
  2. || [ZP] Extra Item : Plasma Rifle ||
  3. || by Sh0oT3R ||
  4. \*======================================================*/
  5.  
  6. #include <amxmodx>
  7. #include <amxmisc>
  8. #include <hamsandwich>
  9. #include <engine>
  10. #include <cstrike>
  11. #include <fakemeta>
  12. #include <xs>
  13.  
  14. #define fm_create_entity(%1) engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, %1))
  15.  
  16. #define VERSION "1.0"
  17. #define AUTHOR "Sh0oT3R"
  18.  
  19. #define FIRERATE 0.2
  20. #define HITSD 0.7
  21. #define RELOADSPEED 5.0
  22. #define DAMAGE 250.0
  23. #define DAMAGE_MULTI 3.0
  24.  
  25. #define CSW_WPN CSW_FAMAS
  26. new const weapon[] = "weapon_famas"
  27.  
  28. new const spr_beam[] = "sprites/plasma/plasma_beam.spr"
  29. new const spr_exp[] = "sprites/plasma/plasma_exp.spr"
  30. new const spr_blood[] = "sprites/blood.spr"
  31. new const snd_fire[][] = { "zombie_plague/plasma/plasma_fire.wav" }
  32. new const snd_reload[][] = { "zombie_plague/plasma/plasma_reload.wav" }
  33. new const snd_hit[][] = { "zombie_plague/plasma/plasma_hit.wav" }
  34.  
  35. new bool:g_HasRifle[33]
  36. new g_iCurWpn[33], Float:g_flLastFireTime[33]
  37. new g_sprBeam, g_sprExp, g_sprBlood, g_msgDamage, g_msgScreenFade, g_msgScreenShake
  38.  
  39. const m_pPlayer = 41
  40. const m_fInReload = 54
  41. const m_pActiveItem = 373
  42. const m_flNextAttack = 83
  43. const m_flTimeWeaponIdle = 48
  44. const m_flNextPrimaryAttack = 46
  45. const m_flNextSecondaryAttack = 47
  46.  
  47. const UNIT_SECOND = (1<<12)
  48. const ENG_NULLENT = -1
  49. const WPN_MAXCLIP = 25
  50. const ANIM_FIRE = 5
  51. const ANIM_DRAW = 10
  52. const ANIM_RELOAD = 9
  53. const EV_INT_WEAPONKEY = EV_INT_impulse
  54. const WPNKEY = 2816
  55.  
  56. public plugin_init()
  57. {
  58. register_plugin("[ZP] Extra Item: Plasma Rifle", VERSION, AUTHOR)
  59.  
  60. register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0");
  61. register_event("CurWeapon", "event_CurWeapon", "b", "1=1")
  62.  
  63. register_forward(FM_CmdStart, "fw_CmdStart")
  64. register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  65.  
  66. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  67. RegisterHam(Ham_Item_AddToPlayer, weapon, "fw_AddToPlayer")
  68. RegisterHam(Ham_Item_PostFrame, weapon, "fw_PostFrame")
  69.  
  70.  
  71. g_msgDamage = get_user_msgid("Damage")
  72. g_msgScreenFade = get_user_msgid("ScreenFade")
  73. g_msgScreenShake = get_user_msgid("ScreenShake")
  74. }
  75.  
  76. public plugin_precache()
  77. {
  78. precache_model("models/zombie_plague/plasma/v_plasma.mdl")
  79. precache_model("models/zombie_plague/plasma/p_plasma.mdl")
  80.  
  81. g_sprBlood = precache_model(spr_blood)
  82. g_sprBeam = precache_model(spr_beam)
  83. g_sprExp = precache_model(spr_exp)
  84.  
  85. static i
  86. for(i = 0; i < sizeof snd_fire; i++)
  87. precache_sound(snd_fire[i])
  88. for(i = 0; i < sizeof snd_hit; i++)
  89. precache_sound(snd_hit[i])
  90. for(i = 0; i < sizeof snd_reload; i++)
  91. precache_sound(snd_reload[i])
  92. }
  93. public event_CurWeapon(id)
  94. {
  95. if(!is_user_alive(id))
  96. return PLUGIN_CONTINUE
  97.  
  98. g_iCurWpn[id] = read_data(2)
  99.  
  100. if(!g_HasRifle[id] || g_iCurWpn[id] != CSW_WPN)
  101. return PLUGIN_CONTINUE
  102.  
  103. entity_set_string(id, EV_SZ_viewmodel, "models/zombie_plague/plasma/v_plasma.mdl")
  104. entity_set_string(id, EV_SZ_weaponmodel, "models/zombie_plague/plasma/p_plasma.mdl")
  105. return PLUGIN_CONTINUE
  106. }
  107.  
  108. public fw_PlayerKilled(victim, attacker, shouldgib)
  109. {
  110. if(is_user_alive(victim))
  111. {
  112. g_HasRifle[victim] = false
  113. return HAM_HANDLED
  114. }
  115. return HAM_IGNORED
  116. }
  117.  
  118. public Event_NewRound()
  119. {
  120. for (new i = 1; i <= get_maxplayers(); i++)
  121. {
  122. g_HasRifle[i] = true
  123. }
  124. }
  125. public client_putinserver(id)
  126. {
  127. g_HasRifle[id] = true
  128. }
  129. public client_disconnect(id)
  130. {
  131. g_HasRifle[id] = false
  132. }
  133. public fw_CmdStart(id, handle, seed)
  134. {
  135. if(!is_user_alive(id))
  136. return FMRES_IGNORED
  137.  
  138. if(!g_HasRifle[id])
  139. return FMRES_IGNORED
  140.  
  141. if(g_iCurWpn[id] != CSW_WPN)
  142. return FMRES_IGNORED
  143.  
  144. static iButton
  145. iButton = get_uc(handle, UC_Buttons)
  146.  
  147. if(iButton & IN_ATTACK)
  148. {
  149. set_uc(handle, UC_Buttons, iButton & ~IN_ATTACK)
  150.  
  151. static Float:flCurTime
  152. flCurTime = halflife_time()
  153.  
  154. if(flCurTime - g_flLastFireTime[id] < FIRERATE)
  155. return FMRES_IGNORED
  156.  
  157. static iWpnID, iClip
  158. iWpnID = get_pdata_cbase(id, m_pActiveItem, 5)
  159. iClip = cs_get_weapon_ammo(iWpnID)
  160.  
  161. if(get_pdata_int(iWpnID, m_fInReload, 4))
  162. return FMRES_IGNORED
  163.  
  164. set_pdata_float(iWpnID, m_flNextPrimaryAttack, FIRERATE, 4)
  165. set_pdata_float(iWpnID, m_flNextSecondaryAttack, FIRERATE, 4)
  166. set_pdata_float(iWpnID, m_flTimeWeaponIdle, FIRERATE, 4)
  167. g_flLastFireTime[id] = flCurTime
  168. if(iClip <= 0)
  169. {
  170. ExecuteHamB(Ham_Weapon_PlayEmptySound, iWpnID)
  171. return FMRES_IGNORED
  172. }
  173. primary_attack(id)
  174. cs_set_weapon_ammo(iWpnID, --iClip)
  175.  
  176. return FMRES_IGNORED
  177. }
  178.  
  179. return FMRES_IGNORED
  180. }
  181. public fw_UpdateClientData_Post(id, sendweapons, handle)
  182. {
  183. if(!is_user_alive(id))
  184. return FMRES_IGNORED
  185.  
  186. if(!g_HasRifle[id])
  187. return FMRES_IGNORED
  188.  
  189. if(g_iCurWpn[id] != CSW_WPN)
  190. return FMRES_IGNORED
  191.  
  192. set_cd(handle, CD_flNextAttack, halflife_time() + 0.001)
  193. return FMRES_HANDLED
  194. }
  195.  
  196. public fw_AddToPlayer(wpn, id)
  197. {
  198. if(is_valid_ent(wpn) && is_user_connected(id) && entity_get_int(wpn, EV_INT_WEAPONKEY) == WPNKEY)
  199. {
  200. g_HasRifle[id] = true
  201. entity_set_int(wpn, EV_INT_WEAPONKEY, 0)
  202. return HAM_HANDLED
  203. }
  204. return HAM_IGNORED
  205. }
  206. public fw_PostFrame(wpn)
  207. {
  208. static id
  209. id = get_pdata_cbase(wpn, m_pPlayer, 4)
  210.  
  211. if(is_user_alive(id) && g_HasRifle[id])
  212. {
  213. static Float:flNextAttack, iBpAmmo, iClip, iInReload
  214. iInReload = get_pdata_int(wpn, m_fInReload, 4)
  215. flNextAttack = get_pdata_float(id, m_flNextAttack, 5)
  216. iBpAmmo = cs_get_user_bpammo(id, CSW_WPN)
  217. iClip = cs_get_weapon_ammo(wpn)
  218.  
  219. if(iInReload && flNextAttack <= 0.0)
  220. {
  221. new iRemClip = min(WPN_MAXCLIP - iClip, iBpAmmo)
  222. cs_set_weapon_ammo(wpn, iClip + iRemClip)
  223. cs_set_user_bpammo(id, CSW_WPN, iBpAmmo-iRemClip)
  224. iInReload = 0
  225. set_pdata_int(wpn, m_fInReload, 0, 4)
  226. }
  227. static iButton
  228. iButton = get_user_button(id)
  229.  
  230. if((iButton & IN_ATTACK2 && get_pdata_float(wpn, m_flNextSecondaryAttack, 4) <= 0.0) || (iButton & IN_ATTACK && get_pdata_float(wpn, m_flNextPrimaryAttack, 4) <= 0.0))
  231. return
  232.  
  233. if(iButton & IN_RELOAD && !iInReload)
  234. {
  235. if(iClip >= WPN_MAXCLIP)
  236. {
  237. entity_set_int(id, EV_INT_button, iButton & ~IN_RELOAD)
  238. }
  239. }
  240. }
  241. }
  242.  
  243. public primary_attack(id)
  244. {
  245. entity_set_vector(id, EV_VEC_punchangle, Float:{ -1.5, 0.0, 0.0 })
  246. emit_sound(id, CHAN_WEAPON, snd_fire[random_num(0, sizeof snd_fire - 1)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  247.  
  248. static iTarget, iBody, iEndOrigin[3], iStartOrigin[3]
  249. get_user_origin(id, iStartOrigin, 1)
  250. get_user_origin(id, iEndOrigin, 3)
  251. get_user_aiming(id, iTarget, iBody)
  252.  
  253. new iEnt = create_entity("info_target")
  254.  
  255. static Float:flOrigin[3]
  256. IVecFVec(iEndOrigin, flOrigin)
  257. entity_set_origin(iEnt, flOrigin)
  258. remove_entity(iEnt)
  259.  
  260. if(is_user_alive(iTarget))
  261. {
  262. if(HITSD > 0.0)
  263. {
  264. static Float:flVelocity[3]
  265. get_user_velocity(iTarget, flVelocity)
  266. xs_vec_mul_scalar(flVelocity, HITSD, flVelocity)
  267. set_user_velocity(iTarget, flVelocity)
  268. }
  269. }
  270. else
  271. {
  272. emit_sound(id, CHAN_WEAPON, snd_hit[random_num(0, sizeof snd_hit - 1)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  273. }
  274. }
  275. stock fire_effects(iStartOrigin[3], iEndOrigin[3])
  276. {
  277. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  278. write_byte(0)
  279. write_coord(iStartOrigin[0])
  280. write_coord(iStartOrigin[1])
  281. write_coord(iStartOrigin[2])
  282. write_coord(iEndOrigin[0])
  283. write_coord(iEndOrigin[1])
  284. write_coord(iEndOrigin[2])
  285. write_short(g_sprBeam)
  286. write_byte(1)
  287. write_byte(5)
  288. write_byte(10)
  289. write_byte(25)
  290. write_byte(0)
  291. write_byte(0)
  292. write_byte(255)
  293. write_byte(0)
  294. write_byte(100)
  295. write_byte(0)
  296. message_end()
  297.  
  298. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  299. write_byte(3)
  300. write_coord(iEndOrigin[0])
  301. write_coord(iEndOrigin[1])
  302. write_coord(iEndOrigin[2])
  303. write_short(g_sprExp)
  304. write_byte(10)
  305. write_byte(15)
  306. write_byte(4)
  307. message_end()
  308. }
  309. stock reload(id, wpn, force_reload = 0)
  310. {
  311. set_pdata_float(id, m_flNextAttack, RELOADSPEED, 5)
  312. set_wpnanim(id, ANIM_RELOAD)
  313. emit_sound(id, CHAN_WEAPON, snd_reload[random_num(0, sizeof snd_reload - 1)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  314.  
  315. if(force_reload)
  316. set_pdata_int(wpn, m_fInReload, 1, 4)
  317. }
  318. stock damage_effects(id)
  319. {
  320. message_begin(MSG_ONE_UNRELIABLE, g_msgDamage, _, id)
  321. write_byte(0)
  322. write_byte(0)
  323. write_long(DMG_NERVEGAS)
  324. write_coord(0)
  325. write_coord(0)
  326. write_coord(0)
  327. message_end()
  328.  
  329. message_begin(MSG_ONE_UNRELIABLE, g_msgScreenFade, {0,0,0}, id)
  330. write_short(1<<13)
  331. write_short(1<<14)
  332. write_short(0x0000)
  333. write_byte(0)
  334. write_byte(255)
  335. write_byte(0)
  336. write_byte(100)
  337. message_end()
  338.  
  339. message_begin(MSG_ONE, g_msgScreenShake, {0,0,0}, id)
  340. write_short(0xFFFF)
  341. write_short(1<<13)
  342. write_short(0xFFFF)
  343. message_end()
  344. }
  345. stock make_blood(id, scale)
  346. {
  347. new Float:iVictimOrigin[3]
  348. pev(id, pev_origin, iVictimOrigin)
  349.  
  350. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  351. write_byte(115)
  352. write_coord(floatround(iVictimOrigin[0]+random_num(-20,20)))
  353. write_coord(floatround(iVictimOrigin[1]+random_num(-20,20)))
  354. write_coord(floatround(iVictimOrigin[2]+random_num(-20,20)))
  355. write_short(g_sprBlood)
  356. write_short(g_sprBlood)
  357. write_byte(248)
  358. write_byte(scale)
  359. message_end()
  360. }
  361. stock set_wpnanim(id, anim)
  362. {
  363. entity_set_int(id, EV_INT_weaponanim, anim)
  364. message_begin(MSG_ONE, SVC_WEAPONANIM, {0, 0, 0}, id)
  365. write_byte(anim)
  366. write_byte(entity_get_int(id, EV_INT_body))
  367. message_end()
  368. }
  369. stock make_punch(id, velamount)
  370. {
  371. static Float:flNewVelocity[3], Float:flCurrentVelocity[3]
  372. velocity_by_aim(id, -velamount, flNewVelocity)
  373. get_user_velocity(id, flCurrentVelocity)
  374. xs_vec_add(flNewVelocity, flCurrentVelocity, flNewVelocity)
  375. set_user_velocity(id, flNewVelocity)
  376. }
  377. stock fm_give_item(index, const item[])
  378. {
  379. if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10))
  380. return 0;
  381.  
  382. new ent = fm_create_entity(item);
  383. if (!pev_valid(ent))
  384. return 0;
  385.  
  386. new Float:origin[3];
  387. pev(index, pev_origin, origin);
  388. set_pev(ent, pev_origin, origin);
  389. set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN);
  390. dllfunc(DLLFunc_Spawn, ent);
  391.  
  392. new save = pev(ent, pev_solid);
  393. dllfunc(DLLFunc_Touch, ent, index);
  394. if (pev(ent, pev_solid) != save)
  395. return ent;
  396.  
  397. engfunc(EngFunc_RemoveEntity, ent);
  398.  
  399. return -1;
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement