AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Impulse Grenade (https://forums.alliedmods.net/showthread.php?t=307526)

EFFx 05-13-2018 17:58

Impulse Grenade
 
2 Attachment(s)
IMPULSE GRENADE


- Description
- This plugin replaces the smoke grenade with a a funny feature similar to a Fortnite's: If you throw the smoke grenade and it explodes close to a player, he'll be impulsed with the explosion. It does a little damage.
Theres a random video I found with that feature - https://www.youtube.com/watch?v=WUftN-hy19w

- Cvars
impulsegrenade_on - Turn plugin on/off
impulsegrenade_self_impulse - Self impulse on/off
impulsegrenade_multiplier - Impulse's multiplier
impulsegrenade_radius - Explosion radius
impulsegrenade_ffa - Impulse teammates.
impulsegrenade_killmoney - Amount of money that the player gets when he kill someone with the Impulse Grenade.
impulsegrenade_killinfo - Display when someone kills another player with the Impulse Grenade.
impulsegrenade_impactmode - Instant explosion after touch the worldspawn or a player).

- Credits
Nomexous' Weapon Physics (Weapons being impulsed with the HE Explosion, just changed to smoke and made it work with players) - https://forums.alliedmods.net/showthread.php?p=580384

- Change log
Spoiler

EFFx 06-13-2018 00:39

Re: Impulse Grenade
 
Plugin Updated to v1.1

Code:

. Added money bonus when someone kills another player with the Impulse Grenade.
{
        - Two cvars to configure: impulsegrenade_killmoney and impulsegrenade_killinfo.

        > impulsegrenade_killmoney - Amount of money that the player gets when he kill someone with the Impulse Grenade.
        > impulsegrenade_killinfo - Display when someone kills another player with the Impulse Grenade.
}
. Fixed the wrong radius on the createBlast.
. Added impulsegrenade_trailcolor cvar to change the player's trail color.
. Added impulsegrenade_blastcolor cvar to change the explosion's color.


Fuck For Fun 06-13-2018 07:34

Re: Impulse Grenade
 
Look great, gj :)

NiHiLaNTh 06-13-2018 17:00

Re: Impulse Grenade
 
Its 2018, why you still change viewmodels with CurWeapon event?

EFFx 06-13-2018 20:03

Re: Impulse Grenade
 
Because I want.

HamletEagle 06-14-2018 03:51

Re: Impulse Grenade
 
Quote:

Originally Posted by EFFx (Post 2596814)
Because I want.

Nice attitude.

EFFx 06-14-2018 09:05

Re: Impulse Grenade
 
Ty

Rivotril 06-14-2018 17:22

Re: Impulse Grenade
 
Looks cool!

Nia 06-24-2018 09:26

Re: Impulse Grenade
 
...

EFFx 07-14-2018 01:47

Re: Impulse Grenade
 
Updated to v1.2:

Code:

. Added impact mode (instant explosion after touch).

HamletEagle 07-14-2018 04:21

Re: Impulse Grenade
 
1.
Quote:

Originally Posted by NiHiLaNTh (Post 2596791)
Its 2018, why you still change viewmodels with CurWeapon event?

Fix this.

2.Don't use FM_Touch when you want to catch specific touches between entities, register_touch from engine or Ham_Touch should be better in this case because filtering is doing in the module.

3.
PHP Code:

#define SMOKE_ID            26 

Don't hardcode that, use precache_event with createsmoke.sc.

4.Use real offset names OFFSET_GRENADE - > m_usEvent

5.Don't duplicate code, create a private function for this:
PHP Code:

    new iColor[3], iCvar get_pcvar_num(g_pCvarExplosionColor)
    
iColor[0] = (iCvar 1000000)
    
iCvar %= 1000000
    iColor
[1] = (iCvar 1000)
    
iColor[2] = (iCvar 1000

6.I don't think you have to check both isGrenade and isAvaliableGrenade, isAvaliableGrenade should be enough.

EFFx 07-14-2018 10:13

Re: Impulse Grenade
 
I'm still without understand what's the problem with CurWeapon. The rest are done.

iceeedr 07-14-2018 11:43

Re: Impulse Grenade
 
Because CurWeapon is called everytime a weapon is fired or weapon changed (or clip ammo changed to be precise).

HamletEagle 07-14-2018 11:49

Re: Impulse Grenade
 
Quote:

Originally Posted by EFFx (Post 2603538)
I'm still without understand what's the problem with CurWeapon. The rest are done.

If you look at how game works you will see it changes models during Deploy, so this is the right moment to set them. By using CurWeapon you update the models way more times than it's actually needed and in moments where you should not be updating them.
That's like saying using preThink to detect IN_ATTACK is fine instead of using PrimaryAttack.

EFFx 07-14-2018 12:56

Re: Impulse Grenade
 
Quote:

Originally Posted by HamletEagle (Post 2603574)
If you look at how game works you will see it changes models during Deploy, so this is the right moment to set them. By using CurWeapon you update the models way more times than it's actually needed and in moments where you should not be updating them.
That's like saying using preThink to detect IN_ATTACK is fine instead of using PrimaryAttack.

I get it now. I actually was using just because it's the easier format to use.

Updated to v1.3:

- Code optimized.
. Added impulsegrenade_impactmode cvar to turn on/off impact mode.

Off:
Incrível a cara de pau, "PerfectPug", sma toda bugada, Premier até usou a minha :3

wilianmaique 07-16-2018 16:43

Re: Impulse Grenade
 
brazil is toxic :(

RaZ_HU 07-26-2018 16:54

Re: Impulse Grenade
 
Nice plugin, +1

joy0406 07-27-2018 02:55

Re: Impulse Grenade
 
Server Crashes for some reason as soon as the grenade is thrown.

EFFx 07-27-2018 03:23

Re: Impulse Grenade
 
1 Attachment(s)
I was getting sometimes as well, try this one:

RaZ_HU 07-31-2018 13:41

Re: Impulse Grenade
 
Quote:

Originally Posted by joy0406 (Post 2606370)
Server Crashes for some reason as soon as the grenade is thrown.

Same for me. I mean on windows server (homemade for testing) it is fine, but on dedicated linux it crashes.


Quote:

Originally Posted by EFFx (Post 2606372)
I was getting sometimes as well, try this one:

Going to test this now.

Update:
Thanks for the fix, it is working now :)

HamletEagle 08-14-2018 06:20

Re: Impulse Grenade
 
1.g_offEvent: I said to use real offset names so people understand what the code is going. The right name is m_usEvent. I did not come up with it, that's how the offset is named in game's code.
2.Since you are using Ham_TakeDamage you can get rid of manually calling deathmsg by changing DMG_BLAST to DMG_GRENADE in TakeDamage call.

EFFx 08-14-2018 07:39

Re: Impulse Grenade
 
Done.

HamletEagle 08-14-2018 07:44

Re: Impulse Grenade
 
You need to define DMG_GRENADE, IIRC it's 1 << 24.

EFFx 08-14-2018 08:00

Re: Impulse Grenade
 
I compiled fine with 1.8.3, forget to define < 1.8.2.

ifx 11-25-2018 12:09

Re: Impulse Grenade
 
its just crash server when throw :(
all files on server ok
amxmodx 190-5229, metamod 1.21p37
----
ah, ok, this workin fine - https://forums.alliedmods.net/showpo...2&postcount=19

luciaus18 11-26-2018 14:22

Re: Impulse Grenade
 
Hi! Can you make this code to be for flashbang? Thank you!

Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
#include <engine>
#include <fakemeta>
#include <xs>

#define PLUGIN "Impulse Grenade"
#define VERSION "1.3"
#define AUTHOR "EFFx"

#define explodeGrenade(%1)                set_pev(%1, pev_dmgtime, 0.0)
#define message_begin_fl(%1,%2,%3,%4)        engfunc(EngFunc_MessageBegin, %1, %2, %3, %4)
#define write_coord_fl(%1)                engfunc(EngFunc_WriteCoord, %1)
#define MAX_MONEY                        16000
#define MAX_PLAYERS                        32
#define LOG_FILE                        "ig_logfile.log"

const g_offEvent =                        114
const m_pPlayer =                        41
const OFFSET_LINUX_WEAPONS =                4

new g_iSmokeEventID
new bool:g_bIsPluginEnabled, bool:g_bIsImpactModeOn

new g_pCvarEnabled, g_pCvarSelfImpulse, g_pCvarImpulseMultiplier, g_pCvarRadius, g_pCvarFFA,
g_pCvarKillMoney, g_pCvarKillInfo, g_pCvarPlayerTrailColor, g_pCvarExplosionColor,
g_pCvarImpactMode

new g_iPlayerTrailSprite, g_iExplosionSprite
new g_mMessageDeathMsg, g_mMessageSayText

new const g_szViewModel[] =                "models/v_impulsegrenade.mdl"
new const g_szPlayerModel[] =                "models/p_impulsegrenade.mdl"
new const g_szWorldModel[] =                "models/w_impulsegrenade.mdl"

new const g_szExplodeSound[] =                "weapons/sbarrel1.wav"

public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        g_pCvarEnabled = register_cvar("impulsegrenade_on", "1")
        g_pCvarSelfImpulse = register_cvar("impulsegrenade_self_impulse", "1")
        g_pCvarImpulseMultiplier = register_cvar("impulsegrenade_multiplier", "3.8")
        g_pCvarRadius = register_cvar("impulsegrenade_radius", "300.0")
        g_pCvarFFA = register_cvar("impulsegrenade_ffa", "1")
        g_pCvarKillMoney = register_cvar("impulsegrenade_killmoney", "500")
        g_pCvarKillInfo = register_cvar("impulsegrenade_killinfo", "1")
        g_pCvarPlayerTrailColor = register_cvar("impulsegrenade_trailcolor", "255255255")
        g_pCvarExplosionColor = register_cvar("impulsegrenade_blastcolor", "255255255")
        g_pCvarImpactMode = register_cvar("impulsegrenade_impactmode", "1")

        g_mMessageDeathMsg = get_user_msgid("DeathMsg")
        g_mMessageSayText = get_user_msgid("SayText")
       
        g_iSmokeEventID = engfunc(EngFunc_PrecacheEvent, 1, "events/createsmoke.sc")
       
        register_logevent("logevent_roundStart", 2, "1=Round_Start")

        register_forward(FM_SetModel, "forward_SetModel")
        register_forward(FM_EmitSound, "forward_EmitSound")
        register_forward(FM_PlaybackEvent, "pfnPlaybackEvent", false)

        RegisterHam(Ham_Item_Deploy, "weapon_smokegrenade", "ham_SmokeDeploy_Post", 1)
        RegisterHam(Ham_Touch, "grenade", "ham_Touch_Post", 1)
}

public plugin_precache()
{
        g_iPlayerTrailSprite = precache_model("sprites/laserbeam.spr")
        g_iExplosionSprite = precache_model("sprites/shockwave.spr")
       
        precache_model(g_szViewModel)
        precache_model(g_szPlayerModel)
        precache_model(g_szWorldModel)
       
        precache_sound(g_szExplodeSound)
}

public logevent_roundStart()
{
        g_bIsPluginEnabled = bool:get_pcvar_num(g_pCvarEnabled)
        g_bIsImpactModeOn = bool:get_pcvar_num(g_pCvarImpactMode)
}

public pfnPlaybackEvent(Flags, id, m_usFireEvent, Float:Delay, Float:Origin[3], Float:Angles[3], Float:DirectionX, Float:DirectionY, PunchAngleX, PunchAngleY, bool:Dummy1, bool:Dummy2)
{
        if(g_iSmokeEventID == m_usFireEvent)
        {
                return FMRES_SUPERCEDE
        }
        return FMRES_IGNORED


public ham_Touch_Post(iGrenade, iTouched)
{
        if(g_bIsPluginEnabled && isSolid(iTouched) && isAvaliableGrenade(iGrenade) && g_bIsImpactModeOn)
        {
                explodeGrenade(iGrenade)
                                       
                entity_set_float(iGrenade, EV_FL_nextthink, get_gametime() + 0.001)
                entity_set_int(iGrenade, EV_INT_flags, entity_get_int(iGrenade, EV_INT_flags) | FL_ONGROUND)
        }
}

public ham_SmokeDeploy_Post(iWeapon)
{
        if(!g_bIsPluginEnabled)
                return
               
        static id; id = get_pdata_cbase(iWeapon, m_pPlayer, OFFSET_LINUX_WEAPONS)
        if(!is_user_connected(id))
                return
               
        set_pev(id, pev_viewmodel2, g_szViewModel)
        set_pev(id, pev_weaponmodel2, g_szPlayerModel)       
}

public forward_SetModel(iEnt, const szModel[])
{
        if(!pev_valid(iEnt) || !g_bIsPluginEnabled)
                return FMRES_IGNORED

        if(equal(szModel, "models/w_smokegrenade.mdl"))
        {
                engfunc(EngFunc_SetModel, iEnt, g_szWorldModel)
                return FMRES_SUPERCEDE
        }
        return FMRES_IGNORED
}

public forward_EmitSound(iEnt, channel, const szSample[])
{
        if(!g_bIsPluginEnabled)
                return FMRES_IGNORED
               
        if(!equal(szSample, "weapons/sg_explode.wav") || !pev_valid(iEnt))
        {
                return FMRES_IGNORED
        }
       
        new Float:fEntOrigin[3], Float:fPlayerOrigin[3], Float:fRadius = get_pcvar_float(g_pCvarRadius)
        pev(iEnt, pev_origin, fEntOrigin)
       
        createBlast(fEntOrigin)
        emit_sound(iEnt, CHAN_ITEM, g_szExplodeSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
       
        new iVictim = -1, iOwner = pev(iEnt, pev_owner)
        while((iVictim = engfunc(EngFunc_FindEntityInSphere, iVictim, fEntOrigin, fRadius)) != 0)
        {
                if(!is_user_alive(iVictim)
                || (pev(iVictim, pev_takedamage) == DAMAGE_NO)
                || (pev(iVictim, pev_flags) & FL_GODMODE)
                || (!get_pcvar_num(g_pCvarSelfImpulse) && (iVictim == iOwner))
                || (!get_pcvar_num(g_pCvarFFA) && get_user_team(iOwner) == get_user_team(iVictim)))
                        continue

                pev(iVictim, pev_origin, fPlayerOrigin)
                impulsePlayer(iVictim, iEnt, iOwner, (fRadius - (get_distance_f(fEntOrigin, fPlayerOrigin) * 0.0254)))
        }
        set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME)
        return FMRES_SUPERCEDE
}

createBlast(Float:fStartOrigin[3])
{
        new iColor[3]
        getRgbColor(iColor, get_pcvar_num(g_pCvarExplosionColor))

        message_begin_fl(MSG_PVS,SVC_TEMPENTITY, fStartOrigin, 0)
        write_byte(TE_BEAMCYLINDER)
        write_coord_fl(fStartOrigin[0])
        write_coord_fl(fStartOrigin[1])
        write_coord_fl(fStartOrigin[2])
        write_coord_fl(fStartOrigin[0])
        write_coord_fl(fStartOrigin[1])
        write_coord_fl(fStartOrigin[2] + get_pcvar_float(g_pCvarRadius))
        write_short(g_iExplosionSprite)
        write_byte(0)
        write_byte(0)
        write_byte(4)
        write_byte(50)
        write_byte(0)
        write_byte(iColor[0])
        write_byte(iColor[1])
        write_byte(iColor[2])
        write_byte(100)
        write_byte(0)
        message_end()
}

// Code took from Weapon Physics edited by me.
impulsePlayer(iVictim, iInflictor, iAttacker, Float:fDamage)
{
        static Float:fPlayerVelocity[3], Float:fPlayerOrigin[3], Float:fGrenadeOrigin[3], Float:fTemp[3]
        pev(iVictim, pev_velocity, fPlayerVelocity)
        pev(iVictim, pev_origin, fPlayerOrigin)
        pev(iInflictor, pev_origin, fGrenadeOrigin)
        xs_vec_sub(fPlayerOrigin, fGrenadeOrigin, fTemp)
        xs_vec_normalize(fTemp, fTemp)
        xs_vec_mul_scalar(fTemp, fDamage, fTemp)
        xs_vec_mul_scalar(fTemp, get_pcvar_float(g_pCvarImpulseMultiplier), fTemp)
        xs_vec_add(fPlayerVelocity, fTemp, fPlayerVelocity)
        set_pev(iVictim, pev_velocity, fPlayerVelocity)

        static Float:fPlayerAVelocity[3]
        fPlayerAVelocity[1] = random_float(-1000.0, 1000.0)
        set_pev(iVictim, pev_avelocity, fPlayerAVelocity)

        new iColor[3]
        getRgbColor(iColor, get_pcvar_num(g_pCvarPlayerTrailColor))
       
        message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
        write_byte(TE_BEAMFOLLOW)
        write_short(iVictim)
        write_short(g_iPlayerTrailSprite)
        write_byte(4)
        write_byte(3)
        write_byte(iColor[0])
        write_byte(iColor[1])
        write_byte(iColor[2])
        write_byte(100)
        message_end()

        new Float:fDamageTaken = (fDamage / 22.5)
        if(floatround(fDamageTaken) >= get_user_health(iVictim))
        {
                set_msg_block(g_mMessageDeathMsg, BLOCK_ONCE)
                make_deathmsg(iAttacker, iVictim, 0, "")

                new bool:bIsTeamKilled = bool:(get_user_team(iAttacker) == get_user_team(iVictim))
                new iCvarKillBonus = get_pcvar_num(g_pCvarKillMoney), iUserMoney = cs_get_user_money(iAttacker)
                new iMoney = bIsTeamKilled ? (iUserMoney - iCvarKillBonus) : (iUserMoney + iCvarKillBonus)
               
                cs_set_user_money(iAttacker, clamp(iMoney, 0, MAX_MONEY), 1)

                if(get_pcvar_num(g_pCvarKillInfo) && (iAttacker != iVictim))
                {
                        new szKillerName[MAX_PLAYERS], szVictimName[MAX_PLAYERS]
                        get_user_name(iAttacker, szKillerName, charsmax(szKillerName))
                        get_user_name(iVictim, szVictimName, charsmax(szVictimName))
               
                        log_to_file(LOG_FILE, "Player '%s' killed %s'%s' with the Impulse Grenade.", szKillerName, bIsTeamKilled ? "his teammate " : "", szVictimName)
                       
                        ChatColor(iAttacker, "^x04[Impulse Grenade]^x01: You %s^x04 %d$^x01 by killing^x04 %s^x01 with the^x04 Impulse Grenade.", bIsTeamKilled ? "lost" : "got", iCvarKillBonus, szVictimName)
                        ChatColor(iVictim, "^x04[Impulse Grenade]^x01:%s^x03 %s^x01 killed you with the^x04 Impulse Grenade.", bIsTeamKilled ? " Your teammates" : "", szKillerName)
                        ChatColor(0, "^x04[Impulse Grenade]^x01: Player^x04 %s^x01 killed^x04 %s^x01 with the^x04 Impulse Grenade.", szKillerName, szVictimName)
                }
        }

        ExecuteHam(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamageTaken, DMG_BLAST)
}

getRgbColor(iColor[3], iCvar)
{
        iColor[0] = (iCvar / 1000000)
        iCvar %= 1000000
        iColor[1] = (iCvar / 1000)
        iColor[2] = (iCvar % 1000)
}

ChatColor(id, szMessage[], any:...)
{
        new iPlayers[MAX_PLAYERS], iNum = 1
        static szMsg[191]
        vformat(szMsg, charsmax(szMsg), szMessage, 3)
 
        replace_all(szMsg, charsmax(szMsg), "!g", "^4")
        replace_all(szMsg, charsmax(szMsg), "!y", "^1")
        replace_all(szMsg, charsmax(szMsg), "!t", "^3")

        if(id) iPlayers[0] = id; else get_players(iPlayers, iNum, "ch")
       
        for(new i, iPlayer; i < iNum; i++)
        {
                message_begin(MSG_ONE_UNRELIABLE, g_mMessageSayText, .player = (iPlayer = iPlayers[i]))
                write_byte(iPlayer)
                write_string(szMsg)
                message_end()
        }
}

bool:isSolid(iEnt)
{
        return (iEnt ? ((pev(iEnt, pev_solid) > SOLID_TRIGGER) ? true : false ) : true )
}

isAvaliableGrenade(iEnt) 
{
        return (get_pdata_int(iEnt, g_offEvent) == g_iSmokeEventID)
}


RaZ_HU 01-12-2019 17:30

Re: Impulse Grenade
 
I have version 1.3, but I have downloaded it far sooner than you made the last changes. The server crashes if someone got a kill with it.
I have removed the pfnPlaybackEvent as you have in the latest code, but without that the smoke appears with the explosion effect. So I have put that in your latest version and now it works fine, but the server still crashes after the someone gets killed with this.

Edit2:
I have upgraded AMXX to latest build 5235 from 5229, now it works without a crash. It's magic :D
Furthermore I want to report if FFA is set to 0 then self impulse does not work, because victim has the same team as attacker.

EFFx 01-24-2019 14:59

Re: Impulse Grenade
 
So what's the problem? If the FFA cvar is 0 then you shouldn't impulse a teammate.

RaZ_HU 01-24-2019 16:28

Re: Impulse Grenade
 
That makes impulsegrenade_self_impulse cvar pointless.

EFFx 02-07-2019 20:55

Re: Impulse Grenade
 
Why pointless? It controls if you can impulse your teammates.

HamletEagle 02-08-2019 05:00

Re: Impulse Grenade
 
EFFx, I think he's saying something totally different.
impulsegrenade_self_impulse controls if you can impulse yourself, right?
FFA controls if you can impulse teammates, right?

Now think about this: FFA is 0 and impulsegrenade_self_impulse is 1. You should not impulse your teammates, and you should impulse yourself.
BUT, you will not be able to impulse yourself because FFA is 0 and your team is identical to your team. FFA makes impulsegrenade_self_impulse not count.

EFFx 02-26-2019 18:26

Re: Impulse Grenade
 
Oh yea, I've fixed it and also, added a code that kills the beam when the player touches the ground.

MrPickles 05-31-2023 00:17

Re: Impulse Grenade
 
that plugin needs a lot of optimization...


All times are GMT -4. The time now is 06:59.

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