AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED]Get Grenade Owner From Event (https://forums.alliedmods.net/showthread.php?t=242971)

devilicioux 06-27-2014 14:20

[SOLVED]Get Grenade Owner From Event
 
Okay So i have these functions and Event hook i took from https://forums.alliedmods.net/showthread.php?p=77288 (Cluster Grenades) ..
What i am trying to do is .. Get who threw the He grenade using the stock .. Store the value returned by stock into the id..
That id is passed into a variable g_clusters[id] .. which decides the iterations of for loop.

But this all above doesnt seem to work right.. :3 because Nade Clusters should be According to value in g_clusters[id] but still i am getting a 0 clusters what so ever the value in g_clusters[id]
(Because i am still a learner and not a pro :|)

Debug Results :
1. Works when i play alone .. and Fails when there are more players or bots
2. Stock isnt able to return grenade owner id in the grenade_explosion function :|

So any suggestions or someone can explain or help me out with the understanding part specially the stock or some alternative ?

PHP Code:

register_message23"grenade_explosion" 

PHP Code:

public grenade_explosion() {
    if (
get_msg_arg_int) == && get_msg_arg_int ) == 25 && get_msg_arg_int ) == 30) {
        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, ... }
 
        new 
id=get_grenade_owner()
 
        
//This will launch the above specified number of clusters
        
for (new 0g_clusters[id]; i++) {
            
//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


PHP Code:

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



SpeeDeeR 06-27-2014 20:05

Re: Get Grenade Owner From Event
 
You could:
1. Hook CGrenade::Detonate3 and get pev_owner from grenade index.
2. Hook grenade think, check if it's HE, check pev_dmgtime < get_gametime, then get pev_owner from grenade index.

^SmileY 06-27-2014 22:36

Re: Get Grenade Owner From Event
 
You can use csx to detect grenade trow and store owner into a globar var. After this, you can detect explosions using other methods.


Excuse if I saying crap :p

devilicioux 06-28-2014 00:07

Re: Get Grenade Owner From Event
 
Quote:

Originally Posted by SpeeDeeR (Post 2158480)
You could:
1. Hook CGrenade::Detonate3 and get pev_owner from grenade index.
2. Hook grenade think, check if it's HE, check pev_dmgtime < get_gametime, then get pev_owner from grenade index.

Quote:

Originally Posted by ^SmileY (Post 2158507)
You can use csx to detect grenade trow and store owner into a globar var. After this, you can detect explosions using other methods.


Excuse if I saying crap :p

Okay ..before sleeping i did a little more debugging .. and the entire Grenade Explode function isnt working right (Not getting called for me atleast ..)
So these seems to be a really nice option :D i ll try them as soon as i get back home ..
Thank you both :D


All times are GMT -4. The time now is 21:09.

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