Advertisement
regener

impulseGrenade.sma

Jun 7th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.88 KB | None | 0 0
  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.     RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "ham_SmokeDeploy_Post", 1)
  85.     RegisterHam(Ham_Touch, "grenade", "ham_Touch_Post", 1)
  86. }
  87.  
  88. public plugin_precache()
  89. {
  90.     g_iPlayerTrailSprite = precache_model("sprites/laserbeam.spr")
  91.     g_iExplosionSprite = precache_model("sprites/shockwave.spr")
  92.  
  93.     precache_model(g_szViewModel)
  94. #if defined SET_PLUSMODELS
  95.     precache_model(g_szPlayerModel)
  96.     precache_model(g_szWorldModel)
  97. #endif
  98.  
  99.     precache_sound(g_szExplodeSound)
  100. }
  101.  
  102. public logevent_roundStart()
  103. {
  104.     g_bIsPluginEnabled = bool:get_pcvar_num(g_pCvarEnabled)
  105.     g_bIsImpactModeOn = bool:get_pcvar_num(g_pCvarImpactMode)
  106. }
  107.  
  108. public pfnPlaybackEvent(Flags, id, m_usFireEvent, Float:Delay, Float:Origin[3], Float:Angles[3], Float:DirectionX, Float:DirectionY, PunchAngleX, PunchAngleY, bool:Dummy1, bool:Dummy2)
  109. {
  110.     if(g_iSmokeEventID == m_usFireEvent)
  111.     {
  112.         return FMRES_SUPERCEDE
  113.     }
  114.     return FMRES_IGNORED
  115. }
  116. public ham_Touch_Post(iGrenade, iTouched)
  117. {
  118.     if(g_bIsPluginEnabled && isSolid(iTouched) && isAvaliableGrenade(iGrenade) && g_bIsImpactModeOn)
  119.     {
  120.         explodeGrenade(iGrenade)
  121.  
  122.         entity_set_float(iGrenade, EV_FL_nextthink, get_gametime() + 0.001)
  123.         entity_set_int(iGrenade, EV_INT_flags, entity_get_int(iGrenade, EV_INT_flags) | FL_ONGROUND)
  124.     }
  125. }
  126.  
  127. public client_PreThink(id)
  128. {
  129.     if(!is_user_alive(id))
  130.         return
  131.  
  132.     if((entity_get_int(id, EV_INT_flags) & FL_ONGROUND) && g_bImpulsed[id])
  133.     {
  134.         g_bImpulsed[id] = false
  135.         killTrailBeam(id)
  136.     }
  137. }
  138.  
  139.  
  140. public ham_SmokeDeploy_Post(iWeapon)
  141. {
  142.     if(!g_bIsPluginEnabled)
  143.         return
  144.  
  145.     static id; id = get_pdata_cbase(iWeapon, m_pPlayer, OFFSET_LINUX_WEAPONS)
  146.     if(!is_user_connected(id))
  147.         return
  148.  
  149.     set_pev(id, pev_viewmodel2, g_szViewModel)
  150. #if defined SET_PLUSMODELS
  151.     set_pev(id, pev_weaponmodel2, g_szPlayerModel)
  152. #endif
  153. }
  154.  
  155. #if defined SET_PLUSMODELS
  156. public forward_SetModel(iEnt, const szModel[])
  157. {
  158.     if(!pev_valid(iEnt) || !g_bIsPluginEnabled)
  159.         return FMRES_IGNORED
  160.  
  161.     if(equal(szModel, "models/w_smokegrenade.mdl"))
  162.     {
  163.         engfunc(EngFunc_SetModel, iEnt, g_szWorldModel)
  164.         return FMRES_SUPERCEDE
  165.     }
  166.     return FMRES_IGNORED
  167. }
  168. #endif
  169.  
  170. public forward_EmitSound(iEnt, channel, const szSample[])
  171. {
  172.     if(!g_bIsPluginEnabled)
  173.         return FMRES_IGNORED
  174.  
  175.     if(!equal(szSample, "weapons/sg_explode.wav") || !pev_valid(iEnt))
  176.     {
  177.         return FMRES_IGNORED
  178.     }
  179.  
  180.     new Float:fEntOrigin[3], Float:fPlayerOrigin[3], Float:fRadius = get_pcvar_float(g_pCvarRadius)
  181.     pev(iEnt, pev_origin, fEntOrigin)
  182.  
  183.     createBlast(fEntOrigin)
  184.     emit_sound(iEnt, CHAN_ITEM, g_szExplodeSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  185.  
  186.     new iVictim = -1, iOwner = pev(iEnt, pev_owner)
  187.     while((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, fEntOrigin, fRadius)) != 0)
  188.     {
  189.         if(!is_user_alive(iVictim)
  190.         || (pev(iVictim, pev_takedamage) == DAMAGE_NO)
  191.         || (pev(iVictim, pev_flags) & FL_GODMODE)
  192.         || (iVictim == iOwner) && !get_pcvar_num(g_pCvarSelfImpulse)
  193.         || !(iVictim == iOwner) && !get_pcvar_num(g_pCvarFFA) && (get_user_team(iOwner) == get_user_team(iVictim)))
  194.             continue
  195.  
  196.         pev(iVictim, pev_origin, fPlayerOrigin)
  197.         impulsePlayer(iVictim, iEnt, iOwner, (fRadius - (get_distance_f(fEntOrigin, fPlayerOrigin) * 0.0254)))
  198.     }
  199.     set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME)
  200.     return FMRES_SUPERCEDE
  201. }
  202.  
  203. createBlast(Float:fStartOrigin[3])
  204. {
  205.     new iColor[3]
  206.     getRgbColor(iColor, get_pcvar_num(g_pCvarExplosionColor))
  207.  
  208.     message_begin_fl(MSG_PVS,SVC_TEMPENTITY, fStartOrigin, 0)
  209.     write_byte(TE_BEAMCYLINDER)
  210.     write_coord_fl(fStartOrigin[0])
  211.     write_coord_fl(fStartOrigin[1])
  212.     write_coord_fl(fStartOrigin[2])
  213.     write_coord_fl(fStartOrigin[0])
  214.     write_coord_fl(fStartOrigin[1])
  215.     write_coord_fl(fStartOrigin[2] + get_pcvar_float(g_pCvarRadius))
  216.     write_short(g_iExplosionSprite)
  217.     write_byte(0)
  218.     write_byte(0)
  219.     write_byte(4)
  220.     write_byte(50)
  221.     write_byte(0)
  222.     write_byte(iColor[0])
  223.     write_byte(iColor[1])
  224.     write_byte(iColor[2])
  225.     write_byte(100)
  226.     write_byte(0)
  227.     message_end()
  228. }
  229.  
  230. // Code took from Weapon Physics edited by me.
  231. impulsePlayer(iVictim, iInflictor, iAttacker, Float:fDamage)
  232. {
  233.     static Float:fPlayerVelocity[3], Float:fPlayerOrigin[3], Float:fGrenadeOrigin[3], Float:fTemp[3], Float:fMaxVelocity
  234.     fMaxVelocity = Float:get_cvar_float("sv_maxvelocity")
  235.     pev(iVictim, pev_velocity, fPlayerVelocity)
  236.     pev(iVictim, pev_origin, fPlayerOrigin)
  237.     pev(iInflictor, pev_origin, fGrenadeOrigin)
  238.     xs_vec_sub(fPlayerOrigin, fGrenadeOrigin, fTemp)
  239.     xs_vec_normalize(fTemp, fTemp)
  240.     xs_vec_mul_scalar(fTemp, fDamage, fTemp)
  241.     xs_vec_mul_scalar(fTemp, get_pcvar_float(g_pCvarImpulseMultiplier), fTemp)
  242.     xs_vec_add(fPlayerVelocity, fTemp, fPlayerVelocity)
  243.     if(fPlayerVelocity[0] > fMaxVelocity)
  244.         fPlayerVelocity[0] = fMaxVelocity
  245.     else if(fPlayerVelocity[1] > fMaxVelocity)
  246.         fPlayerVelocity[1] = fMaxVelocity
  247.     else if(fPlayerVelocity[2] > fMaxVelocity)
  248.         fPlayerVelocity[2] = fMaxVelocity
  249.  
  250.     set_pev(iVictim, pev_velocity, fPlayerVelocity)
  251.  
  252.     static Float:fPlayerAVelocity[3]
  253.     fPlayerAVelocity[1] = random_float(-1000.0, 1000.0)
  254.     set_pev(iVictim, pev_avelocity, fPlayerAVelocity)
  255.  
  256.     new iColor[3]
  257.     getRgbColor(iColor, get_pcvar_num(g_pCvarPlayerTrailColor))
  258.  
  259.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  260.     write_byte(TE_BEAMFOLLOW)
  261.     write_short(iVictim)
  262.     write_short(g_iPlayerTrailSprite)
  263.     write_byte(4)
  264.     write_byte(3)
  265.     write_byte(iColor[0])
  266.     write_byte(iColor[1])
  267.     write_byte(iColor[2])
  268.     write_byte(100)
  269.     message_end()
  270.  
  271.     new Float:fDamageTaken = (fDamage / 22.5)
  272.     if(floatround(fDamageTaken) >= get_user_health(iVictim))
  273.     {
  274.         set_msg_block(g_mMessageDeathMsg, BLOCK_ONCE)
  275.         make_deathmsg(iAttacker, iVictim, 0, "")
  276.  
  277.         new bool:bIsTeamKilled = bool:(get_user_team(iAttacker) == get_user_team(iVictim))
  278.         new iCvarKillBonus = get_pcvar_num(g_pCvarKillMoney), iUserMoney = cs_get_user_money(iAttacker)
  279.         new iMoney = bIsTeamKilled ? (iUserMoney - iCvarKillBonus) : (iUserMoney + iCvarKillBonus)
  280.  
  281.         cs_set_user_money(iAttacker, clamp(iMoney, 0, MAX_MONEY), 1)
  282.  
  283.         if(get_pcvar_num(g_pCvarKillInfo) && (iAttacker != iVictim))
  284.         {
  285.             new szKillerName[MAX_PLAYERS], szVictimName[MAX_PLAYERS]
  286.             get_user_name(iAttacker, szKillerName, charsmax(szKillerName))
  287.             get_user_name(iVictim, szVictimName, charsmax(szVictimName))
  288.             set_pev(iAttacker, pev_frags, get_user_frags(iAttacker)+get_pcvar_num(g_pCvarFragBonus))
  289.  
  290.             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)
  291.  
  292.             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)
  293.             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)
  294.             ChatColor(0, "^4[Impulzus Gránát]^1: ^4%s ^1megölte ^4%s ^1játékost egy ^4Impulzus Gránáttal.", szKillerName, szVictimName)
  295.         }
  296.         g_bImpulsed[iVictim] = false
  297.     }
  298.     else g_bImpulsed[iVictim] = true
  299.  
  300.     ExecuteHam(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamageTaken, DMG_HE)
  301. }
  302.  
  303. getRgbColor(iColor[3], iCvar)
  304. {
  305.     iColor[0] = (iCvar / 1000000)
  306.     iCvar %= 1000000
  307.     iColor[1] = (iCvar / 1000)
  308.     iColor[2] = (iCvar % 1000)
  309. }
  310.  
  311. killTrailBeam(id)
  312. {
  313.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  314.     write_byte(TE_KILLBEAM)
  315.     write_short(id)
  316.     message_end()
  317. }
  318.  
  319. ChatColor(id, szMessage[], any:...)
  320. {
  321.     static szMsg[191]
  322.     vformat(szMsg, charsmax(szMsg), szMessage, 3)
  323.  
  324. #if AMXX_VERSION_NUM < 183
  325.     new iPlayers[MAX_PLAYERS], iNum = 1
  326.  
  327.     replace_all(szMsg, charsmax(szMsg), "!g", "^4")
  328.     replace_all(szMsg, charsmax(szMsg), "!y", "^1")
  329.     replace_all(szMsg, charsmax(szMsg), "!t", "^3")
  330.  
  331.     if(id) iPlayers[0] = id; else get_players(iPlayers, iNum, "ch")
  332.  
  333.     for(new i, iPlayer; i < iNum; i++)
  334.     {
  335.         message_begin(MSG_ONE_UNRELIABLE, g_mMessageSayText, .player = (iPlayer = iPlayers[i]))
  336.         write_byte(iPlayer)
  337.         write_string(szMsg)
  338.         message_end()
  339.     }
  340. #else
  341.     client_print_color(id, 0, szMsg)
  342. #endif
  343. }
  344.  
  345. bool:isSolid(iEnt)
  346. {
  347.     return (iEnt ? ((pev(iEnt, pev_solid) > SOLID_TRIGGER) ? true : false ) : true )
  348. }
  349.  
  350. isAvaliableGrenade(iEnt)
  351. {
  352.     return (get_pdata_int(iEnt, m_usEvent) == g_iSmokeEventID)
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement