HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <hamsandwich>
  4. #include <engine>
  5. #include <fakemeta>
  6. #include <xs>
  7.  
  8. #define PLUGIN "Impulse Grenade"
  9. #define VERSION "1.41"
  10. #define AUTHOR "EFFx, RaZ_HU"
  11.  
  12. #if !defined MAX_PLAYERS
  13. #define MAX_PLAYERS 32
  14. #endif
  15.  
  16. #define explodeGrenade(%1) set_pev(%1, pev_dmgtime, 0.0)
  17. #define message_begin_fl(%1,%2,%3,%4) engfunc(EngFunc_MessageBegin, %1, %2, %3, %4)
  18. #define write_coord_fl(%1) engfunc(EngFunc_WriteCoord, %1)
  19. #define MAX_MONEY 16000
  20. #define MAX_PLAYERS 32
  21. #define LOG_FILE "ig_logfile.log"
  22.  
  23. //#define SET_PLUSMODELS // p_ & w_
  24.  
  25. const m_usEvent = 114
  26. const m_pPlayer = 41
  27. const OFFSET_LINUX_WEAPONS = 4
  28.  
  29. const DMG_HE = (1<<24)
  30.  
  31. new bool:g_bImpulsed[MAX_PLAYERS + 1]
  32.  
  33. new g_iSmokeEventID
  34. new bool:g_bIsPluginEnabled, bool:g_bIsImpactModeOn
  35.  
  36. new g_pCvarEnabled, g_pCvarSelfImpulse, g_pCvarImpulseMultiplier, g_pCvarRadius, g_pCvarFFA,
  37. g_pCvarKillMoney, g_pCvarKillInfo, g_pCvarPlayerTrailColor, g_pCvarExplosionColor, g_pCvarImpactMode, g_pCvarFragBonus
  38.  
  39. new g_iPlayerTrailSprite, g_iExplosionSprite
  40. new g_mMessageDeathMsg
  41. #if AMXX_VERSION_NUM < 183
  42. new g_mMessageSayText
  43. #endif
  44.  
  45. new const g_szViewModel[] = "models/v_impulsegrenade.mdl"
  46. #if defined SET_PLUSMODELS
  47. new const g_szPlayerModel[] = "models/p_impulsegrenade.mdl"
  48. new const g_szWorldModel[] = "models/w_impulsegrenade.mdl"
  49. #endif
  50.  
  51. new const g_szExplodeSound[] = "weapons/sbarrel1.wav"
  52.  
  53. public plugin_init()
  54. {
  55. register_plugin(PLUGIN, VERSION, AUTHOR)
  56.  
  57. g_pCvarEnabled = register_cvar("impulsegrenade_on", "1")
  58. g_pCvarSelfImpulse = register_cvar("impulsegrenade_self_impulse", "1")
  59. g_pCvarImpulseMultiplier = register_cvar("impulsegrenade_multiplier", "3.8")
  60. g_pCvarRadius = register_cvar("impulsegrenade_radius", "300.0")
  61. g_pCvarFFA = register_cvar("impulsegrenade_ffa", "0")
  62. g_pCvarKillMoney = register_cvar("impulsegrenade_killmoney", "300")
  63. g_pCvarKillInfo = register_cvar("impulsegrenade_killinfo", "1")
  64. g_pCvarPlayerTrailColor = register_cvar("impulsegrenade_trailcolor", "255150000")
  65. g_pCvarExplosionColor = register_cvar("impulsegrenade_blastcolor", "100100250")
  66. g_pCvarImpactMode = register_cvar("impulsegrenade_impactmode", "1")
  67. g_pCvarFragBonus = register_cvar("impulsegrenade_fragbonus", "1")
  68.  
  69. g_mMessageDeathMsg = get_user_msgid("DeathMsg")
  70. #if AMXX_VERSION_NUM < 183
  71. g_mMessageSayText = get_user_msgid("SayText")
  72. #endif
  73.  
  74. g_iSmokeEventID = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")
  75.  
  76. register_logevent("logevent_roundStart", 2, "1=Round_Start")
  77.  
  78. #if defined SET_PLUSMODELS
  79. register_forward(FM_SetModel, "forward_SetModel")
  80. #endif
  81. register_forward(FM_EmitSound, "forward_EmitSound")
  82. register_forward(FM_PlaybackEvent, "pfnPlaybackEvent", false)
  83.  
  84. #if defined SET_PLUSMODELS
  85. RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "ham_SmokeDeploy_Post", 1)
  86. #endif
  87. RegisterHam(Ham_Touch, "grenade", "ham_Touch_Post", 1)
  88. }
  89.  
  90. public plugin_precache()
  91. {
  92. g_iPlayerTrailSprite = precache_model("sprites/laserbeam.spr")
  93. g_iExplosionSprite = precache_model("sprites/shockwave.spr")
  94.  
  95. precache_model(g_szViewModel)
  96. #if defined SET_PLUSMODELS
  97. precache_model(g_szPlayerModel)
  98. precache_model(g_szWorldModel)
  99. #endif
  100.  
  101. precache_sound(g_szExplodeSound)
  102. }
  103.  
  104. public logevent_roundStart()
  105. {
  106. g_bIsPluginEnabled = bool:get_pcvar_num(g_pCvarEnabled)
  107. g_bIsImpactModeOn = bool:get_pcvar_num(g_pCvarImpactMode)
  108. }
  109.  
  110. public pfnPlaybackEvent(Flags, id, m_usFireEvent, Float:Delay, Float:Origin[3], Float:Angles[3], Float:DirectionX, Float:DirectionY, PunchAngleX, PunchAngleY, bool:Dummy1, bool:Dummy2)
  111. {
  112. if(g_iSmokeEventID == m_usFireEvent)
  113. {
  114. return FMRES_SUPERCEDE
  115. }
  116. return FMRES_IGNORED
  117. }
  118. public ham_Touch_Post(iGrenade, iTouched)
  119. {
  120. if(g_bIsPluginEnabled && isSolid(iTouched) && isAvaliableGrenade(iGrenade) && g_bIsImpactModeOn)
  121. {
  122. explodeGrenade(iGrenade)
  123.  
  124. entity_set_float(iGrenade, EV_FL_nextthink, get_gametime() + 0.001)
  125. entity_set_int(iGrenade, EV_INT_flags, entity_get_int(iGrenade, EV_INT_flags) | FL_ONGROUND)
  126. }
  127. }
  128.  
  129. public client_PreThink(id)
  130. {
  131. if(!is_user_alive(id))
  132. return
  133.  
  134. if((entity_get_int(id, EV_INT_flags) & FL_ONGROUND) && g_bImpulsed[id])
  135. {
  136. g_bImpulsed[id] = false
  137. killTrailBeam(id)
  138. }
  139. }
  140.  
  141. #if defined SET_PLUSMODELS
  142. public ham_SmokeDeploy_Post(iWeapon)
  143. {
  144. if(!g_bIsPluginEnabled)
  145. return
  146.  
  147. static id; id = get_pdata_cbase(iWeapon, m_pPlayer, OFFSET_LINUX_WEAPONS)
  148. if(!is_user_connected(id))
  149. return
  150.  
  151. set_pev(id, pev_viewmodel2, g_szViewModel)
  152. set_pev(id, pev_weaponmodel2, g_szPlayerModel)
  153. }
  154.  
  155. public forward_SetModel(iEnt, const szModel[])
  156. {
  157. if(!pev_valid(iEnt) || !g_bIsPluginEnabled)
  158. return FMRES_IGNORED
  159.  
  160. if(equal(szModel, "models/w_smokegrenade.mdl"))
  161. {
  162. engfunc(EngFunc_SetModel, iEnt, g_szWorldModel)
  163. return FMRES_SUPERCEDE
  164. }
  165. return FMRES_IGNORED
  166. }
  167. #endif
  168.  
  169. public forward_EmitSound(iEnt, channel, const szSample[])
  170. {
  171. if(!g_bIsPluginEnabled)
  172. return FMRES_IGNORED
  173.  
  174. if(!equal(szSample, "weapons/sg_explode.wav") || !pev_valid(iEnt))
  175. {
  176. return FMRES_IGNORED
  177. }
  178.  
  179. new Float:fEntOrigin[3], Float:fPlayerOrigin[3], Float:fRadius = get_pcvar_float(g_pCvarRadius)
  180. pev(iEnt, pev_origin, fEntOrigin)
  181.  
  182. createBlast(fEntOrigin)
  183. emit_sound(iEnt, CHAN_ITEM, g_szExplodeSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  184.  
  185. new iVictim = -1, iOwner = pev(iEnt, pev_owner)
  186. while((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, fEntOrigin, fRadius)) != 0)
  187. {
  188. if(!is_user_alive(iVictim)
  189. || (pev(iVictim, pev_takedamage) == DAMAGE_NO)
  190. || (pev(iVictim, pev_flags) & FL_GODMODE)
  191. || (iVictim == iOwner) && !get_pcvar_num(g_pCvarSelfImpulse)
  192. || !(iVictim == iOwner) && !get_pcvar_num(g_pCvarFFA) && (get_user_team(iOwner) == get_user_team(iVictim)))
  193. continue
  194.  
  195. pev(iVictim, pev_origin, fPlayerOrigin)
  196. impulsePlayer(iVictim, iEnt, iOwner, (fRadius - (get_distance_f(fEntOrigin, fPlayerOrigin) * 0.0254)))
  197. }
  198. set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME)
  199. return FMRES_SUPERCEDE
  200. }
  201.  
  202. createBlast(Float:fStartOrigin[3])
  203. {
  204. new iColor[3]
  205. getRgbColor(iColor, get_pcvar_num(g_pCvarExplosionColor))
  206.  
  207. message_begin_fl(MSG_PVS,SVC_TEMPENTITY, fStartOrigin, 0)
  208. write_byte(TE_BEAMCYLINDER)
  209. write_coord_fl(fStartOrigin[0])
  210. write_coord_fl(fStartOrigin[1])
  211. write_coord_fl(fStartOrigin[2])
  212. write_coord_fl(fStartOrigin[0])
  213. write_coord_fl(fStartOrigin[1])
  214. write_coord_fl(fStartOrigin[2] + get_pcvar_float(g_pCvarRadius))
  215. write_short(g_iExplosionSprite)
  216. write_byte(0)
  217. write_byte(0)
  218. write_byte(4)
  219. write_byte(50)
  220. write_byte(0)
  221. write_byte(iColor[0])
  222. write_byte(iColor[1])
  223. write_byte(iColor[2])
  224. write_byte(100)
  225. write_byte(0)
  226. message_end()
  227. }
  228.  
  229. // Code took from Weapon Physics edited by me.
  230. impulsePlayer(iVictim, iInflictor, iAttacker, Float:fDamage)
  231. {
  232. static Float:fPlayerVelocity[3], Float:fPlayerOrigin[3], Float:fGrenadeOrigin[3], Float:fTemp[3], Float:fMaxVelocity
  233. fMaxVelocity = Float:get_cvar_float("sv_maxvelocity")
  234. pev(iVictim, pev_velocity, fPlayerVelocity)
  235. pev(iVictim, pev_origin, fPlayerOrigin)
  236. pev(iInflictor, pev_origin, fGrenadeOrigin)
  237. xs_vec_sub(fPlayerOrigin, fGrenadeOrigin, fTemp)
  238. xs_vec_normalize(fTemp, fTemp)
  239. xs_vec_mul_scalar(fTemp, fDamage, fTemp)
  240. xs_vec_mul_scalar(fTemp, get_pcvar_float(g_pCvarImpulseMultiplier), fTemp)
  241. xs_vec_add(fPlayerVelocity, fTemp, fPlayerVelocity)
  242. if(fPlayerVelocity[0] > fMaxVelocity)
  243. fPlayerVelocity[0] = fMaxVelocity
  244. else if(fPlayerVelocity[1] > fMaxVelocity)
  245. fPlayerVelocity[1] = fMaxVelocity
  246. else if(fPlayerVelocity[2] > fMaxVelocity)
  247. fPlayerVelocity[2] = fMaxVelocity
  248.  
  249. set_pev(iVictim, pev_velocity, fPlayerVelocity)
  250.  
  251. static Float:fPlayerAVelocity[3]
  252. fPlayerAVelocity[1] = random_float(-1000.0, 1000.0)
  253. set_pev(iVictim, pev_avelocity, fPlayerAVelocity)
  254.  
  255. new iColor[3]
  256. getRgbColor(iColor, get_pcvar_num(g_pCvarPlayerTrailColor))
  257.  
  258. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  259. write_byte(TE_BEAMFOLLOW)
  260. write_short(iVictim)
  261. write_short(g_iPlayerTrailSprite)
  262. write_byte(4)
  263. write_byte(3)
  264. write_byte(iColor[0])
  265. write_byte(iColor[1])
  266. write_byte(iColor[2])
  267. write_byte(100)
  268. message_end()
  269.  
  270. new Float:fDamageTaken = (fDamage / 22.5)
  271. if(floatround(fDamageTaken) >= get_user_health(iVictim))
  272. {
  273. set_msg_block(g_mMessageDeathMsg, BLOCK_ONCE)
  274. make_deathmsg(iAttacker, iVictim, 0, "")
  275.  
  276. new bool:bIsTeamKilled = bool:(get_user_team(iAttacker) == get_user_team(iVictim))
  277. new iCvarKillBonus = get_pcvar_num(g_pCvarKillMoney), iUserMoney = cs_get_user_money(iAttacker)
  278. new iMoney = bIsTeamKilled ? (iUserMoney - iCvarKillBonus) : (iUserMoney + iCvarKillBonus)
  279.  
  280. cs_set_user_money(iAttacker, clamp(iMoney, 0, MAX_MONEY), 1)
  281.  
  282. if(get_pcvar_num(g_pCvarKillInfo) && (iAttacker != iVictim))
  283. {
  284. new szKillerName[MAX_PLAYERS], szVictimName[MAX_PLAYERS]
  285. get_user_name(iAttacker, szKillerName, charsmax(szKillerName))
  286. get_user_name(iVictim, szVictimName, charsmax(szVictimName))
  287. set_pev(iAttacker, pev_frags, get_user_frags(iAttacker)+get_pcvar_num(g_pCvarFragBonus))
  288.  
  289. log_to_file(LOG_FILE, "'%s' játékos megölte %s'%s' játékost egy Impulzus Gránáttal.", szKillerName, bIsTeamKilled ? "csapattársát " : "", szVictimName)
  290.  
  291. ChatColor(iAttacker, "^4[Impulzus Gránát]^1: %s ^4%d$ ^1amiért megölted ^4%s^1 játékost egy ^4Impulzus Gránáttal.", bIsTeamKilled ? "Veszítettél" : "Kaptál", iCvarKillBonus, szVictimName)
  292. ChatColor(iVictim, "^4[Impulzus Gránát]^1: %s ^3%s ^1megölt téged egy ^4Impulzus Gránáttal.", bIsTeamKilled ? "A csapattársad" : "", szKillerName)
  293. ChatColor(0, "^4[Impulzus Gránát]^1: ^4%s ^1megölte ^4%s ^1játékost egy ^4Impulzus Gránáttal.", szKillerName, szVictimName)
  294. }
  295. g_bImpulsed[iVictim] = false
  296. }
  297. else g_bImpulsed[iVictim] = true
  298.  
  299. ExecuteHam(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamageTaken, DMG_HE)
  300. }
  301.  
  302. getRgbColor(iColor[3], iCvar)
  303. {
  304. iColor[0] = (iCvar / 1000000)
  305. iCvar %= 1000000
  306. iColor[1] = (iCvar / 1000)
  307. iColor[2] = (iCvar % 1000)
  308. }
  309.  
  310. killTrailBeam(id)
  311. {
  312. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  313. write_byte(TE_KILLBEAM)
  314. write_short(id)
  315. message_end()
  316. }
  317.  
  318. ChatColor(id, szMessage[], any:...)
  319. {
  320. static szMsg[191]
  321. vformat(szMsg, charsmax(szMsg), szMessage, 3)
  322.  
  323. #if AMXX_VERSION_NUM < 183
  324. new iPlayers[MAX_PLAYERS], iNum = 1
  325.  
  326. replace_all(szMsg, charsmax(szMsg), "!g", "^4")
  327. replace_all(szMsg, charsmax(szMsg), "!y", "^1")
  328. replace_all(szMsg, charsmax(szMsg), "!t", "^3")
  329.  
  330. if(id) iPlayers[0] = id; else get_players(iPlayers, iNum, "ch")
  331.  
  332. for(new i, iPlayer; i < iNum; i++)
  333. {
  334. message_begin(MSG_ONE_UNRELIABLE, g_mMessageSayText, .player = (iPlayer = iPlayers[i]))
  335. write_byte(iPlayer)
  336. write_string(szMsg)
  337. message_end()
  338. }
  339. #else
  340. client_print_color(id, 0, szMsg)
  341. #endif
  342. }
  343.  
  344. bool:isSolid(iEnt)
  345. {
  346. return (iEnt ? ((pev(iEnt, pev_solid) > SOLID_TRIGGER) ? true : false ) : true )
  347. }
  348.  
  349. isAvaliableGrenade(iEnt)
  350. {
  351. return (get_pdata_int(iEnt, m_usEvent) == g_iSmokeEventID)
  352. }
  353.