AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Setting an entity's bounds box (https://forums.alliedmods.net/showthread.php?t=25892)

beeker` 03-22-2006 21:58

Setting an entity's bounds box
 
Hi everyone. With the help of VEN (a lot of help from VEN) and many others from this community, i'm very close to finishing a plugin that makes HE grenades in Counter-Strike shootable with any weapon. It works by creating a new breakable entity everytime a grenade has been thrown, and once it is created, it is set to follow the thrown grenade. If the entity is shot and destroyed, it tells the grenade it is following to detonate. It works very well, however, i do have a problem with the bounding box of the new entity.

When i use entity_set_size() with the mins at { -40.0, -40.0, -40.0 } and maxs at { 40.0, 40.0, 40.0 }, the grenade is almost impossible to shoot. But, when i set the entity's size to { -3.5, -3.5, -3.5 } and { 3.5, 3.5, 3.5 }, it works pretty consistently but not every time, even if i shoot the grenade directly in the center. How come, even if i shoot the nade directly, it will not explode half the time? If I set the entity's size to a large number, shouldn't i be able to shoot anywhere around the nade and break the entity? Any advice is appreciated! here's the code for creating the entity, i use the FM_SetModel forward:

Code:
public Set_Grenade_Box( entity, model[] ) {         if( get_cvar_num( "ToggleValue" ) == 0 )         return PLUGIN_HANDLED;     if( !( is_valid_ent( entity ) ) ) {               return FMRES_IGNORED;       }       if(entity_get_edict( entity, EV_ENT_owner ) && equal( model, g_sHE_Nade_Model ) ) {               new eNade = entity;                 new Float:fNadeOrigin[3];                 entity_get_vector( eNade, EV_VEC_origin, fNadeOrigin );           entity_set_int( eNade, EV_INT_solid, SOLID_TRIGGER)             new eBox = create_entity( "func_breakable" );             entity_set_origin( eBox, fNadeOrigin );               entity_set_float( eBox, EV_FL_takedamage, 1.0 );           entity_set_float( eBox, EV_FL_health, 5.0 );               entity_set_string( eBox, EV_SZ_classname, g_sBoxClass );           entity_set_model( eBox, g_sHE_Nade_Model );           //        entity_set_int( eBox, EV_INT_movetype, MOVETYPE_BOUNCE)         entity_set_int( eBox, EV_INT_solid, SOLID_BBOX)                 new Float:mins[3] = { -3.5, -3.5, -3.5 };           new Float:maxs[3] = { 3.5, 3.5, 3.5 };         entity_set_size( eBox, mins, maxs );                 //        new Float:mins[3] = { -20.5, -20.5, -20.5 };           //        new Float:maxs[3] = { 20.5, 20.5, 20.5 };         //    entity_set_size( eBox, mins, maxs );             entity_set_edict( eBox, EV_ENT_aiment, eNade );           entity_set_int( eBox, EV_INT_movetype, MOVETYPE_FOLLOW )           entity_set_int( eBox, EV_INT_sequence, 0 );         }       return FMRES_IGNORED;   }

VEN 03-23-2006 11:33

In case you want to get a good answer you should post the whole code.

Quote:

How come, even if i shoot the nade directly, it will not explode half the time?
Miss? Recoil? Follow problem? (use my last debug version to debug ents origin).

Quote:

If I set the entity's size to a large number, shouldn't i be able to shoot anywhere around the nade and break the entity?
That method should work fine, i used it while debugging.

beeker` 03-23-2006 12:05

Hey VEN, how's it gion? Here's the whole code:

Code:
/* Plugin generated by AMXX-Studio */   #include <amxmodx>   #include <amxmisc>   #include <engine>   #include <fakemeta>   #define PLUGIN "New Plugin"   #define VERSION "1.0"   #define AUTHOR "Author"   new g_sHE_Nade_Model[] = "models/w_hegrenade.mdl";   new g_sBoxClass[] = "nade_box"; new Float:radius = 5.0; public plugin_init() {           register_plugin( "Shootable Grenades", "0.1", "beeker" );           register_forward( FM_SetModel, "Set_Grenade_Box" );       register_forward( FM_EmitSound, "forward_emit_sound" );         register_concmd( "amx_grenade", "NadeToggle", ADMIN_IMMUNITY, "<1 or 0> Toggle shootable grenades on or off" );     register_cvar( "ToggleValue", "1" );     }   public plugin_precache() {           precache_model( g_sHE_Nade_Model );         precache_sound("debris/bustglass1.wav");       precache_sound("debris/bustglass2.wav");       precache_sound("debris/bustglass3.wav");       precache_sound("debris/glass1.wav");       precache_sound("debris/glass2.wav");       precache_sound("debris/glass3.wav");       precache_sound("debris/glass4.wav");       } public NadeToggle( id, lvl, cid ) {         if( cmd_access( id, lvl, cid, 1 ) ) {                 if( get_cvar_num( "ToggleValue" ) == 1 ) {                     set_cvar_num( "ToggleValue", 0 );             console_print( id, "[AMXX] Shootable grenades disabled" );                         } else {                     set_cvar_num( "ToggleValue", 1 );             console_print( id, "[AMXX] Shootable grenades enabled" );                     }             }         return PLUGIN_HANDLED;     } public forward_emit_sound( eId ) {         if( get_cvar_num( "ToggleValue" ) == 0 )         return PLUGIN_HANDLED;     if( is_valid_ent( eId ) && ( entity_get_int( eId, EV_INT_effects) & EF_NODRAW ) ) {               new sClassname[9];             entity_get_string( eId, EV_SZ_classname, sClassname, 8 );               if( equal( sClassname, g_sBoxClass ) ) {                       new eCloseNade, Float:origin[3];                     entity_get_vector( eId, EV_VEC_origin, origin );             origin[0] += 1.0;                     while( ( eCloseNade = find_ent_in_sphere( eCloseNade, origin, radius ) ) != 0 ) {                             new sNadeClass[8];                 entity_get_string( eCloseNade, EV_SZ_classname, sNadeClass, 7 );                             if( is_valid_ent( eCloseNade ) && equal( sNadeClass, "grenade" ) ) {                                         remove_entity( eId );                     set_pdata_int( eCloseNade, 4, 127173264 );                                     }                         }                     return FMRES_SUPERCEDE;                   }               }       return FMRES_IGNORED;   }   public Set_Grenade_Box( entity, model[] ) {         if( get_cvar_num( "ToggleValue" ) == 0 )         return PLUGIN_HANDLED;     if( !( is_valid_ent( entity ) ) ) {               return FMRES_IGNORED;       }       if(entity_get_edict( entity, EV_ENT_owner ) && equal( model, g_sHE_Nade_Model ) ) {               new eNade = entity;                 new Float:fNadeOrigin[3];                 entity_get_vector( eNade, EV_VEC_origin, fNadeOrigin );           entity_set_int( eNade, EV_INT_solid, SOLID_TRIGGER)             new eBox = create_entity( "func_breakable" );             entity_set_origin( eBox, fNadeOrigin );               entity_set_float( eBox, EV_FL_takedamage, 1.0 );           entity_set_float( eBox, EV_FL_health, 5.0 );               entity_set_string( eBox, EV_SZ_classname, g_sBoxClass );           entity_set_model( eBox, g_sHE_Nade_Model );           //        entity_set_int( eBox, EV_INT_movetype, MOVETYPE_BOUNCE)         entity_set_int( eBox, EV_INT_solid, SOLID_BBOX)                 new Float:mins[3] = { -3.5, -3.5, -3.5 };           new Float:maxs[3] = { 3.5, 3.5, 3.5 };         entity_set_size( eBox, mins, maxs );                 //        new Float:mins[3] = { -20.5, -20.5, -20.5 };           //        new Float:maxs[3] = { 20.5, 20.5, 20.5 };         //    entity_set_size( eBox, mins, maxs );             entity_set_edict( eBox, EV_ENT_aiment, eNade );           entity_set_int( eBox, EV_INT_movetype, MOVETYPE_FOLLOW )           entity_set_int( eBox, EV_INT_sequence, 0 );         }       return FMRES_IGNORED;   }

For some reason, I tried using the debugged version you sent me, but the grenades will not explode no matter what. I had to use get_pdata_int and finally set_pdata_int for it to work.

beeker` 03-23-2006 20:43

bump

VEN 03-24-2006 02:30

Just debug it.
You know, i solved a lot of problems while working on the code. Why? Because of debug.

beeker` 03-26-2006 11:28

1 Attachment(s)
VEN, i used the debug version you gave me, and the origin of the new entity and the origin of the grenade are exactly the same. I wanted to see exactly how the entity would follow the grenade, so i changed it's model to a bag. Instead of the grenade lying exactly in the middle of the bag, it's on the very bottom, and only the upper half of the grenade lies inside the bag. It's hard to explain, so i posted a screenshot.

( edit: sorry, had to change picture to .jpg )

VEN 03-26-2006 12:39

What is the entities mins and maxs?

beeker` 03-26-2006 12:54

with the bag model, the mins are { -2.5, -2.5, -2.5 } and the maxs are { 2.5, 2.5, 2.5 }

VEN 03-26-2006 13:07

Hm, sorry to say, but actually this is "normal" - that's how entities follows (i.e. centers isn't coincides).

beeker` 03-26-2006 13:13

well i don't know if this would be the correct way to go about it, or if it would cause a ton of lag, but would i be able to create a task, set it to every 0.1 seconds, and have it update the poisiton of the entity?


All times are GMT -4. The time now is 16:36.

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