Raised This Month: $ Target: $400
 0% 

How to increase the shake power of


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-10-2022 , 12:50   How to increase the shake power of
Reply With Quote #1

PHP Code:
/*
    [ZP] Extra Item: Concussion Grenade
    Copyright (C) 2009 by NiHiLaNTh

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    In addition, as a special exception, the author gives permission to
    link the code of this program with the Half-Life Game Engine ("HL
    Engine") and Modified Game Libraries ("MODs") developed by Valve,
    L.L.C ("Valve"). You must obey the GNU General Public License in all
    respects for all of the code used other than the HL Engine and MODs
    from Valve. If you modify this file, you may extend this exception
    to your version of the file, but you are not obligated to do so. If
    you do not wish to do so, delete this exception statement from your
    version.

    --- Introduction ---
    This plugin adds new weapon to zombie plague - concussion grenade.I took
    this idead from Team Fortress Classic.When grenade explodes it doesn't
    do any damage, but it starts to make hallucinations to players, such as
    screen shake, screen fade, recoil changes.
    
    --- CVARs ---
    zp_conc_nade_radius 500 -- Explosion radius
    zp_conc_nade_duration 7 -- Duration of hallucinations
    
    --- Credits ---
    NiHiLaNTh - Plugin
    dels/Shalun - Grenade model
    MeRcyLeZZ - Some useful code parts
    xPaw / Xellath - Code optimization
    
    --- Changelog ---
    v1.0 - Initial release 
    v1.1 - Optimized code ( Thanks xPaw and Xellath )
    v1.2 - Fixed bug when after explosion player were not affected
    v1.3 - Added p_ and w_ model support
         - Fixed run-time error
         - Made some minor improvements ( MeTaLiCroSS )
*/

#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < fun >
#include < zombieplague >

// Plugin version
#define VERSION "1.3"

// Defines
#define MAXPLAYERS     32
#define FCVAR_FLAGS     ( FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
#define OFFSET_PLAYER    41
#define OFFSET_ACTIVE    373
#define LINUX_DIFF    5
#define NADE_TYPE_CONC    7000
//#define UNIT_SECOND    (1<<12)
#define FFADE_IN    0x0000
//#define FFADE_OUT    0x0001
#define REPEAT        0.2 // Time when next screen fade/shake message is being sent
#define TASK_AFFECT    666
#define ID_AFFECT    ( taskid - TASK_AFFECT )

// Grenade cost
#define GRENADE_COST    15

// Grenade models
new const grenade_model_p [ ] = "models/p_grenade_conc.mdl"
new const grenade_model [ ] = "models/v_grenade_conc.mdl"
new const grenade_model_w [ ] = "models/w_grenade_conc.mdl"

// Sounds
new const explosion_sound [ ] = "zombie_plague/concgren_blast1.wav"
new const purchase_sound [ ] = "items/gunpickup2.wav"

// Cached sprite indexes
new m_iTrailm_iRing

// Item ID
new g_conc

// Player variable
new g_hasConc MAXPLAYERS ]

// Message ID's
new g_msgScreenFadeg_msgScreenShake

// CVAR pointers
new cvar_nade_radiuscvar_duration

// Precache
public plugin_precache ( )
{
    
// Precache grenade models
    
precache_model grenade_model_p )
    
precache_model grenade_model )
    
precache_model grenade_model_w )
    
    
// Precache sounds
    
precache_sound explosion_sound )
    
precache_sound purchase_sound )
    
    
// Precache sprites
    
m_iRing precache_model "sprites/shockwave.spr" )
    
m_iTrail precache_model "sprites/laserbeam.spr" )
}

// Plugin initialization
public plugin_init ( )
{
    
// New plugin
    
register_plugin "[ZP] Extra Item: Concussion Grenade"VERSION"NiHiLaNTh" )
    
    
// Add cvar to detect servers with this plugin
    
register_cvar "zp_concgren_version"VERSIONFCVAR_FLAGS )
    
    
// New extra item
    
g_conc zp_register_extra_item "Concussion Grenade"GRENADE_COSTZP_TEAM_ZOMBIE )
    
    
// Events
    
register_event "HLTV""Event_NewRound""a""1=0""2=0" )
    
register_event "DeathMsg""Event_DeathMsg""a" )
    
register_event "CurWeapon""Event_CurrentWeapon""be""1=1""2=25" )
    
    
// Forwards
    
register_forward FM_SetModel"fw_SetModel" )
    
RegisterHam Ham_Think"grenade""fw_ThinkGrenade" )
    
register_forward FM_CmdStart"fw_CmdStart" )
    
    
// CVARs
    
cvar_nade_radius register_cvar "zp_conc_nade_radius""500" )
    
cvar_duration register_cvar "zp_conc_nade_duration""7" )
    
    
// Messages
    
g_msgScreenShake get_user_msgid "ScreenShake" )
    
g_msgScreenFade get_user_msgid "ScreenFade" )
}

// Someone decided to buy our an extra item
public zp_extra_item_selected PlayerItem )
{
    
// This is our grenade
    
if ( Item == g_conc )
    {
        
// Player already have it
        
if ( g_hasConc Player ] )
        {
            
// Notice him about that
            
client_print Playerprint_chat"[ZP] You already have this item" )
            return 
PLUGIN_HANDLED
        
}
        else
        {
            
// Now we have grenade
            
g_hasConc Player ] = true
            
            
// Give him flashbang
            
give_item Player"weapon_flashbang" )
            
            
// Play purchase sound
            
client_cmd Player"spk %s"purchase_sound )    
        }
    }
    return 
PLUGIN_CONTINUE
}
    
// Someone was infected    
public zp_user_infected_post PlayerInfector )
{
    
// We were affected by concussion grenade
    
if ( task_exists Player+TASK_AFFECT ) )
        
remove_task Player+TASK_AFFECT )
}    

// Someone were turned back to human
public zp_user_humanized_post PlayerSurvivor )
{
    
// We dont' have nade anymore
    
if ( g_hasConc Player ] )
        
g_hasConc Player ] = false
}

// New round started
public Event_NewRound ( )
{
    
// They loose conc.grenade
    
arrayset g_hasConcfalse33 )
        
    
// And they aren't affected by conc.grenade
    
remove_task TASK_AFFECT )    
}

// Someone died
public Event_DeathMsg ( )
{
    
// Get victim
    
new victim read_data )
    
    
// Some people had error without this check
    
if ( !is_user_connected victim ) )
        return 
    
    
// He had conc.grenade
    
if ( g_hasConc victim ] )
        
g_hasConc victim ] = false
    
else if ( task_exists victim+TASK_AFFECT ) ) // We were affected
        
remove_task victim+TASK_AFFECT )
}

// Current weapon player is holding
public Event_CurrentWeapon Player )
{
    
// Dead or not zombie or don't have conc. grenade
    
if ( !is_user_alive Player ) || !zp_get_user_zombie Player ) || !g_hasConc Player ] )
        return 
PLUGIN_CONTINUE
    
    
// Replace flashbang model with our ones
    
set_pev Playerpev_viewmodel2grenade_model )
    
set_pev Playerpev_weaponmodel2grenade_model_p )
    
    return 
PLUGIN_CONTINUE
}

// Set model
public fw_SetModel Entity, const Model [ ] )
{
    
// Prevent invalid ent messages
    
if ( !pev_valid Entity ) )
        return 
FMRES_IGNORED
        
    
// Grenade not thrown yet    
    
if ( pev Entitypev_dmgtime ) == 0.0 )
        return 
FMRES_IGNORED
        
    
// We are throwing concussion grenade    
    
if ( g_hasConc pev Entitypev_owner ) ] && equal Model [], "w_fl") )
    {
        
//Draw trail
        
message_begin MSG_BROADCASTSVC_TEMPENTITY )
        
write_byte TE_BEAMFOLLOW // Temp entity ID
        
write_short Entity // Entity to follow
        
write_short m_iTrail // Sprite index
        
write_byte 10 // Life
        
write_byte 10 // Line width
        
write_byte 255 // Red amount
        
write_byte 255 // Blue amount
        
write_byte // Blue amount
        
write_byte 255 // Alpha
        
message_end ( )
        
        
// Set grenade entity
        
set_pev Entitypev_flTimeStepSoundNADE_TYPE_CONC )
        
        
// Set world model
        
engfunc EngFunc_SetModelEntitygrenade_model_w )
        return 
FMRES_SUPERCEDE
    
}
    return 
FMRES_IGNORED
}

// Grenade is getting to explode
public fw_ThinkGrenade Entity )
{
    
// Prevent invalid ent messages
    
if ( !pev_valid Entity ) )
        return 
HAM_IGNORED
    
    
// Get damage time
    
static Float:dmg_time
    pev 
Entitypev_dmgtimedmg_time )
    
    
// maybe it is time to go off
    
if ( dmg_time get_gametime ( ) )
        return 
HAM_IGNORED
        
    
// Our grenade    
    
if ( pev Entitypev_flTimeStepSound ) == NADE_TYPE_CONC )
    {
        
// Force to explode
        
concussion_explode Entity )
        return 
HAM_SUPERCEDE
    
}
    return 
HAM_IGNORED
}

// Command start
public fw_CmdStart PlayerUC_HandleSeed )
{
    
// Dead, zombie or not affected
    
if ( !is_user_alive Player ) || zp_get_user_zombie Player ) || !task_exists Player+TASK_AFFECT ) )
        return 
FMRES_IGNORED
    
    
// Get buttons
    
new buttons get_uc UC_HandleUC_Buttons )
    
    
// We are firing
    
if ( buttons IN_ATTACK )
    {
        
// We are holding an active weapon
        
if ( get_pdata_cbase PlayerOFFSET_ACTIVELINUX_DIFF ) )
        {
            
// New recoil
            
set_pev Playerpev_punchangleFloat:{3.03.04.0} )
        }
    }
    return 
FMRES_HANDLED
}
            

// Grenade explode
public concussion_explode Entity )
{
    
// Invalid entity ?
    
if ( !pev_valid Entity  ) )
        return
    
    
// Get entities origin
    
static Float:origin ]
    
pev Entitypev_originorigin )
    
    
// Draw ring
    
UTIL_DrawRing (origin )
    
    
// Explosion sound
    
emit_sound EntityCHAN_WEAPONexplosion_soundVOL_NORMATTN_NORM0PITCH_NORM )
    
    
// Collisions
    
static victim 
    victim 
= -1
    
    
// Find radius
    
static Float:radius
    radius 
get_pcvar_float cvar_nade_radius )
    
    
// Find all players in a radius
    
while ( ( victim engfunc EngFunc_FindEntityInSpherevictimoriginradius ) ) != )
    {
        
// Dead or zombie
        
if ( !is_user_alive victim ) || zp_get_user_zombie victim ) )
            continue
            
        
// Victim isn't affected yet    
        
if ( !task_exists victim+TASK_AFFECT ) ) 
        {
            
// Get duration
            
new duration get_pcvar_num cvar_duration )
            
            
// Calculate affect times
            
new affect_count floatround duration REPEAT )
            
            
// Continiously affect them
            
set_task REPEAT"affect_victim"victim+TASK_AFFECT__"a"affect_count )
        }
    }
    
    
// We dont' have grenade anymore
    
static owner owner pev Entitypev_owner )
    
g_hasConc owner ] = false
    
    
// Remove entity from ground
    
engfunc EngFunc_RemoveEntityEntity )
}

// We are going to affect you
public affect_victim taskid )
{
    
// Dead
    
if ( !is_user_alive ID_AFFECT ) )
        return
        
    
// Make a screen fade
    
message_begin MSG_ONE_UNRELIABLEg_msgScreenFade, {0,0,0}, ID_AFFECT )
    
write_short 1<<13 // Duration
    
write_short 1<<14 // Hold Time
    
write_short FFADE_IN // Fade type
    
write_byte random_num 50200 ) ) // Red amount
    
write_byte random_num 50200 ) ) // Green amount
    
write_byte random_num 50200 ) ) // Blue amount
    
write_byte random_num 50200 ) ) // Alpha
    
message_end ( )
        
    
// Make a screen shake
    
message_begin MSG_ONE_UNRELIABLEg_msgScreenShake, {0,0,0}, ID_AFFECT )
    
write_short 0xFFFF // Amplitude
    
write_short 1<<13 // Duration
    
write_short 0xFFFF // Frequency
    
message_end ( )
    
    
// Remove task after all
    
remove_task ID_AFFECT )
}

// Draw explosion ring ( from zombie_plague40.sma )
stock UTIL_DrawRing ( const Float:origin ] )
{
    
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0)
    
write_byte(TE_BEAMCYLINDER// TE id
    
engfunc(EngFunc_WriteCoordorigin[0]) // x
    
engfunc(EngFunc_WriteCoordorigin[1]) // y
    
engfunc(EngFunc_WriteCoordorigin[2]) // z
    
engfunc(EngFunc_WriteCoordorigin[0]) // x axis
    
engfunc(EngFunc_WriteCoordorigin[1]) // y axis
    
engfunc(EngFunc_WriteCoordorigin[2]+555.0// z axis
    
write_shortm_iRing // sprite
    
write_byte(0// startframe
    
write_byte(0// framerate
    
write_byte(4// life
    
write_byte(60// width
    
write_byte(0// noise
    
write_byte(200// red
    
write_byte(200// green
    
write_byte(200// blue
    
write_byte(200// brightness
    
write_byte(0// speed
    
message_end()

Hello.

I want to increase the amplitude the screen is shaking at, but i don't know how.

I suspect this is the code i have to modify:

PHP Code:
    // Make a screen shake
    
message_begin MSG_ONE_UNRELIABLEg_msgScreenShake, {0,0,0}, ID_AFFECT )
    
write_short 0xFFFF // Amplitude
    
write_short 1<<13 // Duration
    
write_short 0xFFFF // Frequency
    
message_end ( ) 
However, i don't understand the values and i don't know how to change them.

If i want to increase or decrease the amplitude and the frequency, what do i have to replace "0xFFFF" with? What is this "FFFF" supposed to mean? Is it a value? Are there other letters that can increase or decrease the amplitude? I expected the value to consist of numbers, not letters.

Can someone explain to me how to increase or decrease the values?

Last edited by GlobalPlague; 03-10-2022 at 12:52.
GlobalPlague is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 03-10-2022 , 17:30   Re: How to increase the shake power of
Reply With Quote #2

0xFFFF is hexadecimal value. it is already maximum value short can store so you can't really increase it
jimaway is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-10-2022 , 23:39   Re: How to increase the shake power of
Reply With Quote #3

Side trick you can add multiple punch angles so it look like shaking.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 03-10-2022 at 23:39.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-11-2022 , 07:13   Re: How to increase the shake power of
Reply With Quote #4

Quote:
Originally Posted by jimaway View Post
0xFFFF is hexadecimal value. it is already maximum value short can store so you can't really increase it
I remember there was a plugin that was able to produce much stronger and aggressive shaking. So, why can't shaking be increasing in this plugin, too?

Is hexadecimal value the only possible value for this plugin, or can other kinds of values be used, too? What other values can increase the shaking and how to replace the hexadecimal value with another value?

Quote:
Originally Posted by Natsheh View Post
Side trick you can add multiple punch angles so it look like shaking.
Would you give me an example of how to do it?

EDIT: I forgot to ask a question. How are the following two values different from each other:

PHP Code:
        message_begin(MSG_ONEgMsgScreenShake, {0,0,0} ,id)
        
write_short1<<14 );
        
write_short1<<14 );
        
write_short1<<14 );
        
message_end(); 
PHP Code:
    write_short 0xFFFF // Amplitude
    
write_short 1<<13 // Duration
    
write_short 0xFFFF // Frequency
    
message_end ( ) 
Which value can produce stronger shaking? And how to change the value?

Last edited by GlobalPlague; 03-11-2022 at 07:17.
GlobalPlague is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-11-2022 , 08:09   Re: How to increase the shake power of
Reply With Quote #5

Quote:
Originally Posted by jimaway View Post
0xFFFF is hexadecimal value. it is already maximum value short can store so you can't really increase it

......

I meant you to manapulate with pev_punchangle
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-11-2022 , 10:33   Re: How to increase the shake power of
Reply With Quote #6

Replace with this
Code:
const Float:amplitude = 5.0 // Make a screen shake message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT ) write_short ( FixedUnsigned16(amplitude, 1<<12) ) // Amplitude write_short ( 1<<13 ) // Duration write_short ( 0xFFFF ) // Frequency message_end ( )

And paste this function somewhere
Code:
FixedUnsigned16(Float:value, scale) {     new output = floatround(value * scale)     return clamp(output, 0, 0xFFFF) }

Play with the value of the const Float:amplitude
__________________








CrazY. is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-11-2022 , 12:56   Re: How to increase the shake power of
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
Replace with this
Code:
const Float:amplitude = 5.0 // Make a screen shake message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT ) write_short ( FixedUnsigned16(amplitude, 1<<12) ) // Amplitude write_short ( 1<<13 ) // Duration write_short ( 0xFFFF ) // Frequency message_end ( )

And paste this function somewhere
Code:
FixedUnsigned16(Float:value, scale) {     new output = floatround(value * scale)     return clamp(output, 0, 0xFFFF) }

Play with the value of the const Float:amplitude
Thanks for trying to help me. The code looks fine, expect it causes this error:

C:\mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(414) : error 017: undefined symbol "FixedUnsigned16"
GlobalPlague is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-11-2022 , 13:56   Re: How to increase the shake power of
Reply With Quote #8

You're getting the error because FixedUnsigned16 isn't defined, you probably forgot to paste the function in your plugin.

Quote:
And paste this function somewhere
Code:
FixedUnsigned16(Float:value, scale) {     new output = floatround(value * scale)     return clamp(output, 0, 0xFFFF) }
__________________








CrazY. is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-11-2022 , 15:36   Re: How to increase the shake power of
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
You're getting the error because FixedUnsigned16 isn't defined, you probably forgot to paste the function in your plugin.
It still doesn't work.

I got the following errors:

// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(399) : warning 209: function "affect_victim" should return a value
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(409) : error 017: undefined symbol "FixedUnsigned16"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(409) : error 017: undefined symbol "scale"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(411) : error 017: undefined symbol "value"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(412) : error 078: function uses both "return" and "return <value>"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(415) : warning 225: unreachable code
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(41 : warning 225: unreachable code
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(419) : error 017: undefined symbol "FixedUnsigned16"
// C:\Mod\cstrike\addons\amxmodx\scripting\zp_ex tra.sma(426) : warning 209: function "affect_victim" should return a value


What i did was to replace this:

PHP Code:
// Make a screen shake
message_begin MSG_ONE_UNRELIABLEg_msgScreenShake, {0,0,0}, ID_AFFECT )
write_short 0xFFFF // Amplitude
write_short 1<<13 // Duration
write_short 0xFFFF // Frequency
message_end ( ) 
With this:

PHP Code:
FixedUnsigned16(Float:valuescale)
{
new 
output floatround(value scale)
return 
clamp(output00xFFFF)
}

const 
Float:amplitude 5.0

// Make a screen shake
message_begin MSG_ONE_UNRELIABLEg_msgScreenShake, {0,0,0}, ID_AFFECT )
write_short FixedUnsigned16(amplitude1<<12) ) // Amplitude
write_short 1<<13 // Duration
write_short 0xFFFF // Frequency
message_end ( ) 

Last edited by GlobalPlague; 03-11-2022 at 17:21.
GlobalPlague is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-11-2022 , 16:33   Re: How to increase the shake power of
Reply With Quote #10



Code:
/*
    [ZP] Extra Item: Concussion Grenade
    Copyright (C) 2009 by NiHiLaNTh

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    In addition, as a special exception, the author gives permission to
    link the code of this program with the Half-Life Game Engine ("HL
    Engine") and Modified Game Libraries ("MODs") developed by Valve,
    L.L.C ("Valve"). You must obey the GNU General Public License in all
    respects for all of the code used other than the HL Engine and MODs
    from Valve. If you modify this file, you may extend this exception
    to your version of the file, but you are not obligated to do so. If
    you do not wish to do so, delete this exception statement from your
    version.

    --- Introduction ---
    This plugin adds new weapon to zombie plague - concussion grenade.I took
    this idead from Team Fortress Classic.When grenade explodes it doesn't
    do any damage, but it starts to make hallucinations to players, such as
    screen shake, screen fade, recoil changes.
    
    --- CVARs ---
    zp_conc_nade_radius 500 -- Explosion radius
    zp_conc_nade_duration 7 -- Duration of hallucinations
    
    --- Credits ---
    NiHiLaNTh - Plugin
    dels/Shalun - Grenade model
    MeRcyLeZZ - Some useful code parts
    xPaw / Xellath - Code optimization
    
    --- Changelog ---
    v1.0 - Initial release 
    v1.1 - Optimized code ( Thanks xPaw and Xellath )
    v1.2 - Fixed bug when after explosion player were not affected
    v1.3 - Added p_ and w_ model support
         - Fixed run-time error
         - Made some minor improvements ( MeTaLiCroSS )
*/

#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < fun >
#include < zombieplague >

// Plugin version
#define VERSION "1.3"

// Defines
#define MAXPLAYERS     32
#define FCVAR_FLAGS     ( FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
#define OFFSET_PLAYER    41
#define OFFSET_ACTIVE    373
#define LINUX_DIFF    5
#define NADE_TYPE_CONC    7000
//#define UNIT_SECOND    (1<<12)
#define FFADE_IN    0x0000
//#define FFADE_OUT    0x0001
#define REPEAT        0.2 // Time when next screen fade/shake message is being sent
#define TASK_AFFECT    666
#define ID_AFFECT    ( taskid - TASK_AFFECT )

// Grenade cost
#define GRENADE_COST    15

// Grenade models
new const grenade_model_p [ ] = "models/p_grenade_conc.mdl"
new const grenade_model [ ] = "models/v_grenade_conc.mdl"
new const grenade_model_w [ ] = "models/w_grenade_conc.mdl"

// Sounds
new const explosion_sound [ ] = "zombie_plague/concgren_blast1.wav"
new const purchase_sound [ ] = "items/gunpickup2.wav"

// Cached sprite indexes
new m_iTrail, m_iRing

// Item ID
new g_conc

// Player variable
new g_hasConc [ MAXPLAYERS + 1 ]

// Message ID's
new g_msgScreenFade, g_msgScreenShake

// CVAR pointers
new cvar_nade_radius, cvar_duration

// Precache
public plugin_precache ( )
{
    // Precache grenade models
    precache_model ( grenade_model_p )
    precache_model ( grenade_model )
    precache_model ( grenade_model_w )
    
    // Precache sounds
    precache_sound ( explosion_sound )
    precache_sound ( purchase_sound )
    
    // Precache sprites
    m_iRing = precache_model ( "sprites/shockwave.spr" )
    m_iTrail = precache_model ( "sprites/laserbeam.spr" )
}

// Plugin initialization
public plugin_init ( )
{
    // New plugin
    register_plugin ( "[ZP] Extra Item: Concussion Grenade", VERSION, "NiHiLaNTh" )
    
    // Add cvar to detect servers with this plugin
    register_cvar ( "zp_concgren_version", VERSION, FCVAR_FLAGS )
    
    // New extra item
    g_conc = zp_register_extra_item ( "Concussion Grenade", GRENADE_COST, ZP_TEAM_ZOMBIE )
    
    // Events
    register_event ( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )
    register_event ( "DeathMsg", "Event_DeathMsg", "a" )
    register_event ( "CurWeapon", "Event_CurrentWeapon", "be", "1=1", "2=25" )
    
    // Forwards
    register_forward ( FM_SetModel, "fw_SetModel" )
    RegisterHam ( Ham_Think, "grenade", "fw_ThinkGrenade" )
    register_forward ( FM_CmdStart, "fw_CmdStart" )
    
    // CVARs
    cvar_nade_radius = register_cvar ( "zp_conc_nade_radius", "500" )
    cvar_duration = register_cvar ( "zp_conc_nade_duration", "7" )
    
    // Messages
    g_msgScreenShake = get_user_msgid ( "ScreenShake" )
    g_msgScreenFade = get_user_msgid ( "ScreenFade" )
}

// Someone decided to buy our an extra item
public zp_extra_item_selected ( Player, Item )
{
    // This is our grenade
    if ( Item == g_conc )
    {
        // Player already have it
        if ( g_hasConc [ Player ] )
        {
            // Notice him about that
            client_print ( Player, print_chat, "[ZP] You already have this item" )
            return PLUGIN_HANDLED
        }
        else
        {
            // Now we have grenade
            g_hasConc [ Player ] = true
            
            // Give him flashbang
            give_item ( Player, "weapon_flashbang" )
            
            // Play purchase sound
            client_cmd ( Player, "spk %s", purchase_sound )    
        }
    }
    return PLUGIN_CONTINUE
}
    
// Someone was infected    
public zp_user_infected_post ( Player, Infector )
{
    // We were affected by concussion grenade
    if ( task_exists ( Player+TASK_AFFECT ) )
        remove_task ( Player+TASK_AFFECT )
}    

// Someone were turned back to human
public zp_user_humanized_post ( Player, Survivor )
{
    // We dont' have nade anymore
    if ( g_hasConc [ Player ] )
        g_hasConc [ Player ] = false
}

// New round started
public Event_NewRound ( )
{
    // They loose conc.grenade
    arrayset ( g_hasConc, false, 33 )
        
    // And they aren't affected by conc.grenade
    remove_task ( TASK_AFFECT )    
}

// Someone died
public Event_DeathMsg ( )
{
    // Get victim
    new victim = read_data ( 2 )
    
    // Some people had error without this check
    if ( !is_user_connected ( victim ) )
        return 
    
    // He had conc.grenade
    if ( g_hasConc [ victim ] )
        g_hasConc [ victim ] = false
    else if ( task_exists ( victim+TASK_AFFECT ) ) // We were affected
        remove_task ( victim+TASK_AFFECT )
}

// Current weapon player is holding
public Event_CurrentWeapon ( Player )
{
    // Dead or not zombie or don't have conc. grenade
    if ( !is_user_alive ( Player ) || !zp_get_user_zombie ( Player ) || !g_hasConc [ Player ] )
        return PLUGIN_CONTINUE
    
    // Replace flashbang model with our ones
    set_pev ( Player, pev_viewmodel2, grenade_model )
    set_pev ( Player, pev_weaponmodel2, grenade_model_p )
    
    return PLUGIN_CONTINUE
}

// Set model
public fw_SetModel ( Entity, const Model [ ] )
{
    // Prevent invalid ent messages
    if ( !pev_valid ( Entity ) )
        return FMRES_IGNORED
        
    // Grenade not thrown yet    
    if ( pev ( Entity, pev_dmgtime ) == 0.0 )
        return FMRES_IGNORED
        
    // We are throwing concussion grenade    
    if ( g_hasConc [ pev ( Entity, pev_owner ) ] && equal ( Model [7 ], "w_fl", 4 ) )
    {
        //Draw trail
        message_begin ( MSG_BROADCAST, SVC_TEMPENTITY )
        write_byte ( TE_BEAMFOLLOW ) // Temp entity ID
        write_short ( Entity ) // Entity to follow
        write_short ( m_iTrail ) // Sprite index
        write_byte ( 10 ) // Life
        write_byte ( 10 ) // Line width
        write_byte ( 255 ) // Red amount
        write_byte ( 255 ) // Blue amount
        write_byte ( 0 ) // Blue amount
        write_byte ( 255 ) // Alpha
        message_end ( )
        
        // Set grenade entity
        set_pev ( Entity, pev_flTimeStepSound, NADE_TYPE_CONC )
        
        // Set world model
        engfunc ( EngFunc_SetModel, Entity, grenade_model_w )
        return FMRES_SUPERCEDE
    }
    return FMRES_IGNORED
}

// Grenade is getting to explode
public fw_ThinkGrenade ( Entity )
{
    // Prevent invalid ent messages
    if ( !pev_valid ( Entity ) )
        return HAM_IGNORED
    
    // Get damage time
    static Float:dmg_time
    pev ( Entity, pev_dmgtime, dmg_time )
    
    // maybe it is time to go off
    if ( dmg_time > get_gametime ( ) )
        return HAM_IGNORED
        
    // Our grenade    
    if ( pev ( Entity, pev_flTimeStepSound ) == NADE_TYPE_CONC )
    {
        // Force to explode
        concussion_explode ( Entity )
        return HAM_SUPERCEDE
    }
    return HAM_IGNORED
}

// Command start
public fw_CmdStart ( Player, UC_Handle, Seed )
{
    // Dead, zombie or not affected
    if ( !is_user_alive ( Player ) || zp_get_user_zombie ( Player ) || !task_exists ( Player+TASK_AFFECT ) )
        return FMRES_IGNORED
    
    // Get buttons
    new buttons = get_uc ( UC_Handle, UC_Buttons )
    
    // We are firing
    if ( buttons & IN_ATTACK )
    {
        // We are holding an active weapon
        if ( get_pdata_cbase ( Player, OFFSET_ACTIVE, LINUX_DIFF ) )
        {
            // New recoil
            set_pev ( Player, pev_punchangle, Float:{3.0, 3.0, 4.0} )
        }
    }
    return FMRES_HANDLED
}
            

// Grenade explode
public concussion_explode ( Entity )
{
    // Invalid entity ?
    if ( !pev_valid ( Entity  ) )
        return
    
    // Get entities origin
    static Float:origin [ 3 ]
    pev ( Entity, pev_origin, origin )
    
    // Draw ring
    UTIL_DrawRing (origin )
    
    // Explosion sound
    emit_sound ( Entity, CHAN_WEAPON, explosion_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
    
    // Collisions
    static victim 
    victim = -1
    
    // Find radius
    static Float:radius
    radius = get_pcvar_float ( cvar_nade_radius )
    
    // Find all players in a radius
    while ( ( victim = engfunc ( EngFunc_FindEntityInSphere, victim, origin, radius ) ) != 0 )
    {
        // Dead or zombie
        if ( !is_user_alive ( victim ) || zp_get_user_zombie ( victim ) )
            continue
            
        // Victim isn't affected yet    
        if ( !task_exists ( victim+TASK_AFFECT ) ) 
        {
            // Get duration
            new duration = get_pcvar_num ( cvar_duration )
            
            // Calculate affect times
            new affect_count = floatround ( duration / REPEAT )
            
            // Continiously affect them
            set_task ( REPEAT, "affect_victim", victim+TASK_AFFECT, _, _, "a", affect_count )
        }
    }
    
    // We dont' have grenade anymore
    static owner ; owner = pev ( Entity, pev_owner )
    g_hasConc [ owner ] = false
    
    // Remove entity from ground
    engfunc ( EngFunc_RemoveEntity, Entity )
}

// We are going to affect you
public affect_victim ( taskid )
{
    // Dead
    if ( !is_user_alive ( ID_AFFECT ) )
        return
        
    // Make a screen fade
    message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenFade, {0,0,0}, ID_AFFECT )
    write_short ( 1<<13 ) // Duration
    write_short ( 1<<14 ) // Hold Time
    write_short ( FFADE_IN ) // Fade type
    write_byte ( random_num ( 50, 200 ) ) // Red amount
    write_byte ( random_num ( 50, 200 ) ) // Green amount
    write_byte ( random_num ( 50, 200 ) ) // Blue amount
    write_byte ( random_num ( 50, 200 ) ) // Alpha
    message_end ( )
        
    const Float:amplitude = 5.0

    // Make a screen shake
    message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT )
    write_short ( FixedUnsigned16(amplitude, 1<<12) ) // Amplitude
    write_short ( 1<<13 ) // Duration
    write_short ( 0xFFFF ) // Frequency
    message_end ( ) 
    
    // Remove task after all
    remove_task ( ID_AFFECT )
}

FixedUnsigned16(Float:value, scale)
{
    new output = floatround(value * scale)
    return clamp(output, 0, 0xFFFF)
}

// Draw explosion ring ( from zombie_plague40.sma )
stock UTIL_DrawRing ( const Float:origin [ 3 ] )
{
    engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
    write_byte(TE_BEAMCYLINDER) // TE id
    engfunc(EngFunc_WriteCoord, origin[0]) // x
    engfunc(EngFunc_WriteCoord, origin[1]) // y
    engfunc(EngFunc_WriteCoord, origin[2]) // z
    engfunc(EngFunc_WriteCoord, origin[0]) // x axis
    engfunc(EngFunc_WriteCoord, origin[1]) // y axis
    engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
    write_short( m_iRing ) // sprite
    write_byte(0) // startframe
    write_byte(0) // framerate
    write_byte(4) // life
    write_byte(60) // width
    write_byte(0) // noise
    write_byte(200) // red
    write_byte(200) // green
    write_byte(200) // blue
    write_byte(200) // brightness
    write_byte(0) // speed
    message_end()
}
__________________








CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:54.


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