Raised This Month: $ Target: $400
 0% 

Cluster Grenade that doesn't go behind walls


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 06-07-2022 , 00:41   Re: Cluster Grenade that doesn't go behind walls
Reply With Quote #1

OK, for the newer code
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < engine >
#include < fun >
#include < fakemeta >

#define TE_EXPLOSION 3
#define TE_WORLDDECAL 116

#define CLUSTERS 5

#define MAX_CLUSTER_DAMAGE 20
#define CLUSTER_DAMAGE_RADIUS 300

#define MIN_FLY_DISTANCE 200
#define MAX_FLY_DISTANCE 400

#define UPWARD_ARC 200

#define SCORCH 47

new explosion1explosion2grenade[32], last
new bool:enabled true
new bool:catchdeath false

public death_msg() {
    if ( 
catchdeath ) {
        
catchdeath false
        
return PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
}

public 
grenade_throw() {

    if ( 
get_msg_args() < ) return PLUGIN_HANDLED_MAIN

    
if ( get_msg_arg_int) == 12 && get_msg_arg_int) == )
        
add_grenade_ownerlast )

    return 
PLUGIN_CONTINUE
}

public 
fire_in_the_holeiddestent ) {
    if ( 
get_msg_args() != ) return PLUGIN_CONTINUE

    
new temp[17]
    
get_msg_arg_string5temp17 )

    if ( 
equalitemp"#Fire_in_the_hole" ) ) {
        new 
name[32]
        
entity_get_stringentEV_SZ_netnamename32 )

        
last find_player"a"name )
    }

    return 
PLUGIN_CONTINUE
}

public 
pfn_touchptrptd ) { 

    
//Gets the indentifying strings of each entity
    
new identify[15], compare[15], Float:origin[3]
    if ( 
ptr == identify "world"
    
else entity_get_stringptrEV_SZ_classnameidentify15 )
    if ( 
ptd == compare "world"
    
else if ( is_valid_entptd ) ) entity_get_stringptdEV_SZ_classnamecompare15 )

    
//Ensures that the grenade cluster argument is always the 'ptr'
    
if ( ptr == || equalicompare"grenade_cluster" ) ) return PLUGIN_HANDLED

    
//Checks to see if it is a grenade cluster hitting another object. If it is it explodes and deals damage
    
if ( equaliidentify"grenade_cluster" ) ) {
        
entity_get_vectorptrEV_VEC_originorigin )

        
//Deals radius damage to the spot of collision
        
new player[32], playerslocation[3], origin2[3], distanceFloat:multiplierownerFloat:origin3[3]
        
origin2[0] = floatroundorigin[0] )
        
origin2[1] = floatroundorigin[1] )
        
origin2[2] = floatroundorigin[2] )

        
owner entity_get_edictptrEV_ENT_owner )

        
get_playersplayerplayers"a" )
        for ( new 
0playersi++ ) {
            
get_user_originplayer[i], location )
            
entity_get_vectorplayer[i], EV_VEC_originorigin3 )
            
distance get_distanceorigin2location )
            if ( 
distance CLUSTER_DAMAGE_RADIUS && !is_wall_between_points(originorigin31)) {
                
multiplier floatdivfloatCLUSTER_DAMAGE_RADIUS distance ), floatCLUSTER_DAMAGE_RADIUS ) )
                
deal_grenade_damageplayer[i], ownerfloatmulmultiplierfloatMAX_CLUSTER_DAMAGE ) ) )
            }
        }

        
//Paints the explosion
        
message_beginMSG_BROADCASTSVC_TEMPENTITY 
        
write_byteTE_EXPLOSION 
        
write_coordfloatroundorigin[0] ) ) 
        
write_coordfloatroundorigin[1] ) ) 
        
write_coordfloatroundorigin[2] ) ) 
        
write_shortexplosion1 
        
write_byte50 
        
write_byte15 
        
write_byte)
        
message_end() 

        
message_beginMSG_BROADCASTSVC_TEMPENTITY 
        
write_byteTE_EXPLOSION 
        
write_coordfloatroundorigin[0] ) ) 
        
write_coordfloatroundorigin[1] ) ) 
        
write_coordfloatroundorigin[2] ) ) 
        
write_shortexplosion2 
        
write_byte50 
        
write_byte15 
        
write_byte)
        
message_end() 

        
//If the grenade hit the ground or a wall then this draws a land scar
        
if ( ptd == ) {
            
message_beginMSG_BROADCASTSVC_TEMPENTITY )
            
write_byteTE_WORLDDECAL )
            
write_coordfloatroundorigin[0] ) ) 
            
write_coordfloatroundorigin[1] ) ) 
            
write_coordfloatroundorigin[2] ) ) 
            
write_byteSCORCH )
            
message_end()
        }

        
remove_entityptr //Removes the grenade cluster so that it does not enter an infinite loop

        
return PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
}

public 
grenade_explosion() {
    if (
get_msg_arg_int) == && get_msg_arg_int ) == 25 && get_msg_arg_int ) == 30 && enabled) {
        new 
pos[3]
        
pos[0] = floatroundget_msg_arg_float) )
        
pos[1] = floatroundget_msg_arg_float) )
        
pos[2] = floatroundget_msg_arg_float) )

        new 
clusterFloat:vAngle[3], Float:angles[3], Float:velocity[3], Rvelocity[3], Float:distanceFloat:actualDistanceFloat:multiplier

        
new Float:origin[3
        
origin[0] = floatpos[0] )
        
origin[1] = floatpos[1] )
        
origin[2] = floatpos[2] )

        new 
Float:minBox[3] = { -1.0, ... }
        new 
Float:maxBox[3] = { 1.0, ... }
        
        
//This will launch the above specified number of clusters
        
for (new 0CLUSTERSi++) {
            
//Create a random direction for the cluster to fly
            
velocity[0] = random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            if ( 
random_num0) == velocity[0] = floatmulvelocity[0], -1.0 )
            
velocity[1] = random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            if ( 
random_num0) == velocity[1] = floatmulvelocity[1], -1.0 )
            
velocity[2] = floatUPWARD_ARC )

            
Rvelocity[0] = pos[0] + floatroundvelocity[0] )
            
Rvelocity[1] = pos[1] + floatroundvelocity[1] )
            
Rvelocity[2] = pos[2] + floatroundvelocity[2] )

            
//Create the distance the cluster will fly
            
distance random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            
actualDistance floatget_distanceposRvelocity ) )
            
multiplier floatdivdistanceactualDistance )
            

            
velocity[0] = floatmulvelocity[0], multiplier )
            
velocity[1] = floatmulvelocity[1], multiplier )
            
velocity[2] = floatmulvelocity[2], multiplier )

            
//Create the angles for the facing of the cluster. PS: I have no idea how to do the angle thing really. This is a blind attempt.
            
vector_to_anglevelocityangles )
            
vector_to_anglevelocityvAngle )

            
//Create the entity of the cluster
            
cluster create_entity"info_target" )

            
//Set the identifying string of the cluster's entity
            
entity_set_stringclusterEV_SZ_classname"grenade_cluster"

            
//Set the model for the cluster's entity
            
entity_set_modelcluster"models/grenade.mdl" )     

            
//Set the bounds for the cluster's entity    
            
entity_set_vectorclusterEV_VEC_minsminBox)
            
entity_set_vectorclusterEV_VEC_maxsmaxBox)

            
//Set the origin for the cluster's entity (NOTE: The clusters will spawn in the same spot, but they will be set to ignore eachother
            
entity_set_originclusterorigin )

            
//Set the angles of the cluster's entity    
            
entity_set_vectorclusterEV_VEC_anglesangles )
            
entity_set_vectorclusterEV_VEC_v_anglevAngle )

            
//Set the behavior specific variables for the cluster's entity
            
entity_set_intclusterEV_INT_movetype//Has gravity and registers collisions
            
entity_set_intclusterEV_INT_solid//Collisions do not block

            //Record who the owner of this nade is
            
entity_set_edictclusterEV_ENT_ownerget_grenade_owner() )

            
//Make the cluster fly!
            
entity_set_vectorclusterEV_VEC_velocityvelocity 
        }
    }

    return 
PLUGIN_CONTINUE
}

public 
enable_cluster_grenadeid ) {
    new 
argument[1], number

    read_argv
1argument)
    
number str_to_numargument )

    if ( 
number == ) {
        
enabled false
    
}
    if ( 
number == ) {
        
enabled =true
    
}

    return 
PLUGIN_HANDLED
}

public 
plugin_init() {
    
register_plugin"Cluster Grenades""1.0beta""doomy" )

    
register_concmd"amx_cluster_grenade_enable""enable_cluster_grenade"ADMIN_KICK"Enable or disable cluster grenades (1 = enable, 0 = false)" )

    
register_message23"grenade_explosion" )
    
register_message77"fire_in_the_hole" )
    
register_message83"death_msg" )
    
register_message99,"grenade_throw" )

    return 
PLUGIN_CONTINUE    
}

public 
plugin_precachce() {
    
precache_sound"sound/weapons/explode3.wav" )
    
explosion1 precache_model"sprites/zerogxplode.spr" )
    
explosion2 precache_model"sprites/explode1.spr" )
}

//MISCELLANEOUS FUNCTIONS

deal_grenade_damageattackedattackerFloat:damage ) {
    
//DeathMsg 85 -1 BYTE : killer index BYTE : victim index STRING : weapon 
    
if ( get_user_healthattacked ) - floatrounddamage ) <= ) {
        
//Stops the default death message from being displayed
        
catchdeath true
        user_kill
attacked )
        
        
//Displays who killed who
        
message_begin283 )
        
write_byteattacker )
        
write_byteattacked )
        
write_byte//No idea what this does
        
write_string"grenade" )
        
message_end()

        
//Adds a frag to the killer
        
set_user_fragsattackerget_user_fragsattacker ) + )
    }
    else
        
set_user_healthattackedget_user_healthattacked ) - floatrounddamage ) )
}

add_grenade_ownerowner ) {
    for ( new 
032i++ ) {
        if ( 
grenade[i] == ) {
            
grenade[i] = owner
            
return
        }
    }
}

stock get_grenade_owner() {
    new 
which grenade[0]
    for ( new 
132i++ ) {
        
grenade[1] = grenade[i]
    }
    
grenade[31] = 0

    
return which
}

stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    static 
ptr
    ptr 
create_tr2()

    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERSignore_entptr)
    
    static 
Float:EndPos[3]
    
get_tr2(ptrTR_vecEndPosEndPos)

    
free_tr2(ptr)
    return 
floatround(get_distance_f(endEndPos))

__________________
My plugin:
Celena Luna is offline
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 06-07-2022 , 00:47   Re: Cluster Grenade that doesn't go behind walls
Reply With Quote #2

Quote:
Originally Posted by Celena Luna View Post
OK, for the newer code
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < engine >
#include < fun >
#include < fakemeta >

#define TE_EXPLOSION 3
#define TE_WORLDDECAL 116

#define CLUSTERS 5

#define MAX_CLUSTER_DAMAGE 20
#define CLUSTER_DAMAGE_RADIUS 300

#define MIN_FLY_DISTANCE 200
#define MAX_FLY_DISTANCE 400

#define UPWARD_ARC 200

#define SCORCH 47

new explosion1explosion2grenade[32], last
new bool:enabled true
new bool:catchdeath false

public death_msg() {
    if ( 
catchdeath ) {
        
catchdeath false
        
return PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
}

public 
grenade_throw() {

    if ( 
get_msg_args() < ) return PLUGIN_HANDLED_MAIN

    
if ( get_msg_arg_int) == 12 && get_msg_arg_int) == )
        
add_grenade_ownerlast )

    return 
PLUGIN_CONTINUE
}

public 
fire_in_the_holeiddestent ) {
    if ( 
get_msg_args() != ) return PLUGIN_CONTINUE

    
new temp[17]
    
get_msg_arg_string5temp17 )

    if ( 
equalitemp"#Fire_in_the_hole" ) ) {
        new 
name[32]
        
entity_get_stringentEV_SZ_netnamename32 )

        
last find_player"a"name )
    }

    return 
PLUGIN_CONTINUE
}

public 
pfn_touchptrptd ) { 

    
//Gets the indentifying strings of each entity
    
new identify[15], compare[15], Float:origin[3]
    if ( 
ptr == identify "world"
    
else entity_get_stringptrEV_SZ_classnameidentify15 )
    if ( 
ptd == compare "world"
    
else if ( is_valid_entptd ) ) entity_get_stringptdEV_SZ_classnamecompare15 )

    
//Ensures that the grenade cluster argument is always the 'ptr'
    
if ( ptr == || equalicompare"grenade_cluster" ) ) return PLUGIN_HANDLED

    
//Checks to see if it is a grenade cluster hitting another object. If it is it explodes and deals damage
    
if ( equaliidentify"grenade_cluster" ) ) {
        
entity_get_vectorptrEV_VEC_originorigin )

        
//Deals radius damage to the spot of collision
        
new player[32], playerslocation[3], origin2[3], distanceFloat:multiplierownerFloat:origin3[3]
        
origin2[0] = floatroundorigin[0] )
        
origin2[1] = floatroundorigin[1] )
        
origin2[2] = floatroundorigin[2] )

        
owner entity_get_edictptrEV_ENT_owner )

        
get_playersplayerplayers"a" )
        for ( new 
0playersi++ ) {
            
get_user_originplayer[i], location )
            
entity_get_vectorplayer[i], EV_VEC_originorigin3 )
            
distance get_distanceorigin2location )
            if ( 
distance CLUSTER_DAMAGE_RADIUS && !is_wall_between_points(originorigin31)) {
                
multiplier floatdivfloatCLUSTER_DAMAGE_RADIUS distance ), floatCLUSTER_DAMAGE_RADIUS ) )
                
deal_grenade_damageplayer[i], ownerfloatmulmultiplierfloatMAX_CLUSTER_DAMAGE ) ) )
            }
        }

        
//Paints the explosion
        
message_beginMSG_BROADCASTSVC_TEMPENTITY 
        
write_byteTE_EXPLOSION 
        
write_coordfloatroundorigin[0] ) ) 
        
write_coordfloatroundorigin[1] ) ) 
        
write_coordfloatroundorigin[2] ) ) 
        
write_shortexplosion1 
        
write_byte50 
        
write_byte15 
        
write_byte)
        
message_end() 

        
message_beginMSG_BROADCASTSVC_TEMPENTITY 
        
write_byteTE_EXPLOSION 
        
write_coordfloatroundorigin[0] ) ) 
        
write_coordfloatroundorigin[1] ) ) 
        
write_coordfloatroundorigin[2] ) ) 
        
write_shortexplosion2 
        
write_byte50 
        
write_byte15 
        
write_byte)
        
message_end() 

        
//If the grenade hit the ground or a wall then this draws a land scar
        
if ( ptd == ) {
            
message_beginMSG_BROADCASTSVC_TEMPENTITY )
            
write_byteTE_WORLDDECAL )
            
write_coordfloatroundorigin[0] ) ) 
            
write_coordfloatroundorigin[1] ) ) 
            
write_coordfloatroundorigin[2] ) ) 
            
write_byteSCORCH )
            
message_end()
        }

        
remove_entityptr //Removes the grenade cluster so that it does not enter an infinite loop

        
return PLUGIN_HANDLED
    
}

    return 
PLUGIN_CONTINUE
}

public 
grenade_explosion() {
    if (
get_msg_arg_int) == && get_msg_arg_int ) == 25 && get_msg_arg_int ) == 30 && enabled) {
        new 
pos[3]
        
pos[0] = floatroundget_msg_arg_float) )
        
pos[1] = floatroundget_msg_arg_float) )
        
pos[2] = floatroundget_msg_arg_float) )

        new 
clusterFloat:vAngle[3], Float:angles[3], Float:velocity[3], Rvelocity[3], Float:distanceFloat:actualDistanceFloat:multiplier

        
new Float:origin[3
        
origin[0] = floatpos[0] )
        
origin[1] = floatpos[1] )
        
origin[2] = floatpos[2] )

        new 
Float:minBox[3] = { -1.0, ... }
        new 
Float:maxBox[3] = { 1.0, ... }
        
        
//This will launch the above specified number of clusters
        
for (new 0CLUSTERSi++) {
            
//Create a random direction for the cluster to fly
            
velocity[0] = random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            if ( 
random_num0) == velocity[0] = floatmulvelocity[0], -1.0 )
            
velocity[1] = random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            if ( 
random_num0) == velocity[1] = floatmulvelocity[1], -1.0 )
            
velocity[2] = floatUPWARD_ARC )

            
Rvelocity[0] = pos[0] + floatroundvelocity[0] )
            
Rvelocity[1] = pos[1] + floatroundvelocity[1] )
            
Rvelocity[2] = pos[2] + floatroundvelocity[2] )

            
//Create the distance the cluster will fly
            
distance random_floatfloatMIN_FLY_DISTANCE ), floatMAX_FLY_DISTANCE ) )
            
actualDistance floatget_distanceposRvelocity ) )
            
multiplier floatdivdistanceactualDistance )
            

            
velocity[0] = floatmulvelocity[0], multiplier )
            
velocity[1] = floatmulvelocity[1], multiplier )
            
velocity[2] = floatmulvelocity[2], multiplier )

            
//Create the angles for the facing of the cluster. PS: I have no idea how to do the angle thing really. This is a blind attempt.
            
vector_to_anglevelocityangles )
            
vector_to_anglevelocityvAngle )

            
//Create the entity of the cluster
            
cluster create_entity"info_target" )

            
//Set the identifying string of the cluster's entity
            
entity_set_stringclusterEV_SZ_classname"grenade_cluster"

            
//Set the model for the cluster's entity
            
entity_set_modelcluster"models/grenade.mdl" )     

            
//Set the bounds for the cluster's entity    
            
entity_set_vectorclusterEV_VEC_minsminBox)
            
entity_set_vectorclusterEV_VEC_maxsmaxBox)

            
//Set the origin for the cluster's entity (NOTE: The clusters will spawn in the same spot, but they will be set to ignore eachother
            
entity_set_originclusterorigin )

            
//Set the angles of the cluster's entity    
            
entity_set_vectorclusterEV_VEC_anglesangles )
            
entity_set_vectorclusterEV_VEC_v_anglevAngle )

            
//Set the behavior specific variables for the cluster's entity
            
entity_set_intclusterEV_INT_movetype//Has gravity and registers collisions
            
entity_set_intclusterEV_INT_solid//Collisions do not block

            //Record who the owner of this nade is
            
entity_set_edictclusterEV_ENT_ownerget_grenade_owner() )

            
//Make the cluster fly!
            
entity_set_vectorclusterEV_VEC_velocityvelocity 
        }
    }

    return 
PLUGIN_CONTINUE
}

public 
enable_cluster_grenadeid ) {
    new 
argument[1], number

    read_argv
1argument)
    
number str_to_numargument )

    if ( 
number == ) {
        
enabled false
    
}
    if ( 
number == ) {
        
enabled =true
    
}

    return 
PLUGIN_HANDLED
}

public 
plugin_init() {
    
register_plugin"Cluster Grenades""1.0beta""doomy" )

    
register_concmd"amx_cluster_grenade_enable""enable_cluster_grenade"ADMIN_KICK"Enable or disable cluster grenades (1 = enable, 0 = false)" )

    
register_message23"grenade_explosion" )
    
register_message77"fire_in_the_hole" )
    
register_message83"death_msg" )
    
register_message99,"grenade_throw" )

    return 
PLUGIN_CONTINUE    
}

public 
plugin_precachce() {
    
precache_sound"sound/weapons/explode3.wav" )
    
explosion1 precache_model"sprites/zerogxplode.spr" )
    
explosion2 precache_model"sprites/explode1.spr" )
}

//MISCELLANEOUS FUNCTIONS

deal_grenade_damageattackedattackerFloat:damage ) {
    
//DeathMsg 85 -1 BYTE : killer index BYTE : victim index STRING : weapon 
    
if ( get_user_healthattacked ) - floatrounddamage ) <= ) {
        
//Stops the default death message from being displayed
        
catchdeath true
        user_kill
attacked )
        
        
//Displays who killed who
        
message_begin283 )
        
write_byteattacker )
        
write_byteattacked )
        
write_byte//No idea what this does
        
write_string"grenade" )
        
message_end()

        
//Adds a frag to the killer
        
set_user_fragsattackerget_user_fragsattacker ) + )
    }
    else
        
set_user_healthattackedget_user_healthattacked ) - floatrounddamage ) )
}

add_grenade_ownerowner ) {
    for ( new 
032i++ ) {
        if ( 
grenade[i] == ) {
            
grenade[i] = owner
            
return
        }
    }
}

stock get_grenade_owner() {
    new 
which grenade[0]
    for ( new 
132i++ ) {
        
grenade[1] = grenade[i]
    }
    
grenade[31] = 0

    
return which
}

stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
    static 
ptr
    ptr 
create_tr2()

    
engfunc(EngFunc_TraceLinestartendIGNORE_MONSTERSignore_entptr)
    
    static 
Float:EndPos[3]
    
get_tr2(ptrTR_vecEndPosEndPos)

    
free_tr2(ptr)
    return 
floatround(get_distance_f(endEndPos))

wow you are great, such level of patience!

something is wrong with some offset or something? ( look at me trying to talk code)

the decal that renders after grenade and clusters explode is a literal number "5" now. hilarious

Edit: maybe don't waste your energy and time fixing this.
My main plugin is extra damage mod from V3X.

if you found yourself bored, consider checking the code and hint me on what could be the possible cause "hegrenades" sometimes go off without damage.

is actually that reason why i am using cluster grenades since is the only plugin i found that doesn't mess with scoreboard, doesn't fail applying damage, and actually works.

Last edited by Ark_Procession; 06-07-2022 at 00:48.
Ark_Procession 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 21:18.


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