Junior Member
|
08-05-2015
, 13:26
Entity touch problem
|
#1
|
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#include <engine>
#define PLUGIN "BoxBox"
#define VERSION "1.0"
#define AUTHOR "penguen"
#define MAX_BOX 1024
#define BOX_COUNT 5
#define NEXT_JUMP 2.0
new g_BoxCount;
new bool: NextJump[MAX_BOX];
new const BoxEntity[] = "entity_jumpbox";
new const BoxModel[] = "models/jumpbox.mdl";
new const BoxSound[] = "debris/pushbox1.wav";
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd( "say /jumpbox", "cmdboxMenu" );
register_touch( BoxEntity, "player", "fwd_box_touch" );
RegisterHam( Ham_Think, "info_target", "fwd_box_think" );
}
public plugin_precache()
{
precache_model( BoxModel );
precache_sound( BoxSound );
}
public cmdboxMenu( id )
{
new menu = menu_create( "\wJump Box", "cmdboxMenu_Handler" );
menu_additem( menu, "\wCreate Jump Box", "1" );
menu_additem( menu, "\wRemove Jump Box", "2" );
menu_additem( menu, "\wRemove All Boxs", "1" );
menu_display( id, menu );
}
public cmdboxMenu_Handler( id, menu, item )
{
if( item == MENU_EXIT )
return PLUGIN_HANDLED;
switch( item ) {
case 0: {
if( g_BoxCount < BOX_COUNT ) {
CreateBox( id );
client_print( id, print_chat, "A Box Created" );
}
}
case 1: {
if( !is_user_alive( id ) ) return PLUGIN_HANDLED;
new ent, Body, Class[32];
get_user_aiming( id, ent, Body );
if ( is_valid_ent( ent ) ) {
entity_get_string( ent, EV_SZ_classname, Class, charsmax( Class ) );
if ( equal( BoxEntity, Class ) ) {
remove_entity( ent );
g_BoxCount -= -1;
client_print( id, print_chat, "A Box Removed" );
}
}
}
case 2: {
remove_entity_name( BoxEntity );
g_BoxCount = 0;
client_print( id, print_chat, "Removed All Boxs" );
}
}
menu_destroy( menu );
return PLUGIN_HANDLED;
}
public fwd_box_touch( ent, id )
{
if( !is_user_alive( id ) ) return;
if( NextJump[ent] ) {
new Float: pVelocity[3];
entity_get_vector( id, EV_VEC_velocity, pVelocity );
pVelocity[ 2 ] += 400.0;
entity_set_vector( id, EV_VEC_velocity, pVelocity );
NextJump[ent] = false;
emit_sound( ent, CHAN_VOICE, BoxSound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
entity_set_float( ent, EV_FL_nextthink, get_gametime() + NEXT_JUMP );
}
}
public fwd_box_think( ent )
{
if( !is_valid_ent( ent ) )
return;
new Class[32];
entity_get_string( ent, EV_SZ_classname, Class, charsmax( Class ) );
if( equal( BoxEntity, Class ) ) {
if( !NextJump[ent] ) {
NextJump[ent] = true;
entity_set_float( ent, EV_FL_nextthink, get_gametime() + NEXT_JUMP );
return;
}
entity_set_float( ent, EV_FL_nextthink, get_gametime() + NEXT_JUMP );
}
}
public CreateBox( id )
{
if( !is_user_alive( id ) ) return PLUGIN_HANDLED;
new Float: Origin[ 3 ] = { 0.0, 0.0, 0.0 };
new Float: Angle[ 3 ] = { 0.0, 0.0, 0.0 };
new ent = create_entity( "info_target" );
entity_set_string( ent, EV_SZ_classname, BoxEntity );
get_user_hitpoint( id, Origin );
Origin[ 2 ] += 70.0;
entity_set_origin( ent, Origin );
entity_get_vector( id, EV_VEC_angles, Angle );
Angle[0] = 0.0;
entity_set_vector( ent, EV_VEC_angles, Angle );
entity_set_model( ent, BoxModel );
entity_set_int( ent, EV_INT_movetype, MOVETYPE_TOSS );
entity_set_int( ent, EV_INT_solid, SOLID_BBOX );
new Float: mins[3] = {-10.0, -15.0, -10.0 }
new Float: maxs[3] = { 10.0, 15.0, 10.0 }
entity_set_size( ent, mins, maxs );
entity_set_float( ent, EV_FL_nextthink, get_gametime() + 0.1 );
drop_to_floor( ent );
return PLUGIN_CONTINUE;
}
stock get_user_hitpoint(id, Float:hOrigin[3]) {
if ( ! is_user_alive( id ))
return 0;
new Float:fOrigin[3], Float:fvAngle[3], Float:fvOffset[3], Float:fvOrigin[3], Float:feOrigin[3];
new Float:fTemp[3];
pev(id, pev_origin, fOrigin);
pev(id, pev_v_angle, fvAngle);
pev(id, pev_view_ofs, fvOffset);
xs_vec_add(fOrigin, fvOffset, fvOrigin);
engfunc(EngFunc_AngleVectors, fvAngle, feOrigin, fTemp, fTemp);
xs_vec_mul_scalar(feOrigin, 9999.9, feOrigin);
xs_vec_add(fvOrigin, feOrigin, feOrigin);
engfunc(EngFunc_TraceLine, fvOrigin, feOrigin, 0, id);
global_get(glb_trace_endpos, hOrigin);
return 1;
}
When i touched box nothing happened. I don't know where is the problem. i tried change origin,
PHP Code:
new Float: pOrigin[3];
entity_get_vector( id, EV_VEC_velocity, pOrigin );
pVelocity[ 2 ] += 70.0;
entity_set_vector( id, EV_VEC_velocity, pOrigin );
it worked but,
PHP Code:
new Float: pVelocity[3];
entity_get_vector( id, EV_VEC_velocity, pVelocity );
pVelocity[ 2 ] += 400.0;
entity_set_vector( id, EV_VEC_velocity, pVelocity );
this is not working.
__________________
i seems happy :')
|
|