| 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_message( 23, "grenade_explosion" )
PHP Code:
public grenade_explosion() { if (get_msg_arg_int( 1 ) == 3 && get_msg_arg_int ( 6 ) == 25 && get_msg_arg_int ( 7 ) == 30) { new pos[3] pos[0] = floatround( get_msg_arg_float( 2 ) ) pos[1] = floatround( get_msg_arg_float( 3 ) ) pos[2] = floatround( get_msg_arg_float( 4 ) ) new cluster, Float:vAngle[3], Float:angles[3], Float:velocity[3], Rvelocity[3], Float:distance, Float:actualDistance, Float:multiplier new Float:origin[3] origin[0] = float( pos[0] ) origin[1] = float( pos[1] ) origin[2] = float( pos[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 i = 0; i < g_clusters[id]; i++) { //Create a random direction for the cluster to fly velocity[0] = random_float( float( MIN_FLY_DISTANCE ), float( MAX_FLY_DISTANCE ) ) if ( random_num( 0, 1 ) == 1 ) velocity[0] = floatmul( velocity[0], -1.0 ) velocity[1] = random_float( float( MIN_FLY_DISTANCE ), float( MAX_FLY_DISTANCE ) ) if ( random_num( 0, 1 ) == 1 ) velocity[1] = floatmul( velocity[1], -1.0 ) velocity[2] = float( UPWARD_ARC ) Rvelocity[0] = pos[0] + floatround( velocity[0] ) Rvelocity[1] = pos[1] + floatround( velocity[1] ) Rvelocity[2] = pos[2] + floatround( velocity[2] ) //Create the distance the cluster will fly distance = random_float( float( MIN_FLY_DISTANCE ), float( MAX_FLY_DISTANCE ) ) actualDistance = float( get_distance( pos, Rvelocity ) ) multiplier = floatdiv( distance, actualDistance ) velocity[0] = floatmul( velocity[0], multiplier ) velocity[1] = floatmul( velocity[1], multiplier ) velocity[2] = floatmul( velocity[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_angle( velocity, angles ) vector_to_angle( velocity, vAngle ) //Create the entity of the cluster cluster = create_entity( "info_target" ) //Set the identifying string of the cluster's entity entity_set_string( cluster, EV_SZ_classname, "grenade_cluster") //Set the model for the cluster's entity entity_set_model( cluster, "models/grenade.mdl" ) //Set the bounds for the cluster's entity entity_set_vector( cluster, EV_VEC_mins, minBox) entity_set_vector( cluster, EV_VEC_maxs, maxBox) //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_origin( cluster, origin ) //Set the angles of the cluster's entity entity_set_vector( cluster, EV_VEC_angles, angles ) entity_set_vector( cluster, EV_VEC_v_angle, vAngle ) //Set the behavior specific variables for the cluster's entity entity_set_int( cluster, EV_INT_movetype, 6 ) //Has gravity and registers collisions entity_set_int( cluster, EV_INT_solid, 1 ) //Collisions do not block //Record who the owner of this nade is entity_set_edict( cluster, EV_ENT_owner, get_grenade_owner() ) //Make the cluster fly! entity_set_vector( cluster, EV_VEC_velocity, velocity ) } } return PLUGIN_CONTINUE }
PHP Code:
stock get_grenade_owner() { new which = grenade[0] for ( new i = 1; i < 32; i++ ) { grenade[i - 1] = grenade[i] } grenade[31] = 0 return which }
|