| bogdyuttzu |
08-23-2012 12:36 |
EngFunc_TraceLine problem
Hello.
I have a problem with EngFunc_TraceLine. I do not know how, but does not hit anything.
Here is the code:
PHP Code:
public CTripmine_OnBeamThink( const beam ) { static tripmine; tripmine = pev( beam, pev_owner ); static Float:vecSrc[3], Float:vecEnd[3]; pev( tripmine, pev_origin, vecSrc ); pev( tripmine, pev_vecdir, vecEnd ); static tr, Float:fraction; engfunc(EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, tripmine, tr); get_tr2(tr, TR_flFraction, fraction);
client_print(0 , print_chat,"fraction %f", fraction);
if(fraction < 1.0) { static pHit; pHit = get_tr2( tr, TR_pHit );
client_print(0 , print_chat,"hit %d", pHit);
if( 1 <= pHit <= g_iMaxClients ) { client_print(0 , print_chat,"Check hit %d", pHit); //ExecuteHamB( Ham_Killed, tripmine, tripmine, 0); } } set_pev(beam, pev_nextthink, get_gametime()+0.1); }
Every time TR_flFraction is 1.000000 and if I don't check if fraction < 1.0 TR_pHit is -1
Here is the full code:
PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx> #include <xs> #include <fun> #include <engine> #include <fakemeta> #include <hamsandwich>
#define PLUGIN "New Plug-In" #define VERSION "1.0.0" #define AUTHOR "bogdyutzu"
#define pev_vecdir pev_vuser1 #define pev_beamindex pev_iuser1
#pragma semicolon 1
enum tripmine_e { TRIPMINE_IDLE1 = 0, TRIPMINE_IDLE2, TRIPMINE_ARM1, TRIPMINE_ARM2, TRIPMINE_FIDGET, TRIPMINE_HOLSTER, TRIPMINE_DRAW, TRIPMINE_WORLD, TRIPMINE_GROUND, };
new CClassStringMine[] = "ent_tripmine"; new CClassStringBeam[] = "beam";
new g_iBeamAllocedString, g_iLaserAllocedString, g_iLaserModel, g_iMaxClients;
new const g_szMineModel [] = "models/v_tripmine.mdl"; new const g_szMineDeploy[] = "weapons/mine_deploy.wav"; new const g_szMineActivate[] = "weapons/mine_activate.wav"; new const g_szMineCharge[] = "weapons/mine_charge.wav"; new const g_szMineBeam[] = "sprites/laserbeam.spr";
public plugin_precache() { g_iLaserModel = precache_model(g_szMineBeam); precache_model(g_szMineModel); precache_model("models/computergibs.mdl"); precache_sound(g_szMineDeploy); precache_sound(g_szMineActivate); precache_sound(g_szMineCharge);
g_iLaserAllocedString = engfunc(EngFunc_AllocString, CClassStringMine); g_iBeamAllocedString = engfunc(EngFunc_AllocString, CClassStringBeam); precache_sound("buttons/spark5.wav"); precache_sound("buttons/spark6.wav"); }
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR); RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_c4", "CTripmine_OnAttack"); //RegisterHam(Ham_Killed, "info_target", "CTripmine_OnKilled", 1);
register_think(CClassStringMine, "CTripmine_OnThink"); register_think(CClassStringBeam, "CTripmine_OnBeamThink"); register_clcmd("mata", "suji"); g_iMaxClients = get_maxplayers(); }
public suji(id) give_item(id, "weapon_c4");
public CTripmine_OnAttack( const weapon ) { new playerid = UTIl_GetWeaponOwner( weapon ); if(!is_user_alive(playerid)) return HAM_IGNORED;
new Float:vAngle[3], Float:vPunch[3]; pev(playerid, pev_v_angle, vAngle); pev(playerid, pev_punchangle, vPunch); xs_vec_add(vAngle, vPunch, vAngle); engfunc(EngFunc_MakeVectors, vAngle); new Float:vecSrc[3], Float:vecAiming[3]; ExecuteHamB(Ham_Player_GetGunPosition, playerid, vecSrc); global_get(glb_v_forward, vecAiming); new tr; xs_vec_mul_scalar(vecAiming, 128.0, vecAiming); xs_vec_add(vecSrc, vecAiming, vecAiming); engfunc(EngFunc_TraceLine, vecSrc, vecAiming, IGNORE_MONSTERS, playerid, tr); new Float:fraction; get_tr2(tr, TR_flFraction, fraction); if (fraction < 1.0) { new Float:vPlaneNormal[3], Float:vEndPos[3]; get_tr2(tr, TR_vecPlaneNormal, vPlaneNormal); engfunc(EngFunc_VecToAngles,vPlaneNormal, vAngle); get_tr2(tr, TR_vecEndPos, vEndPos); xs_vec_mul_scalar(vPlaneNormal, 8.0, vPlaneNormal); xs_vec_add(vPlaneNormal, vEndPos, vEndPos); CTripmine_OnSpawn(playerid, vEndPos, vAngle); } return HAM_IGNORED; }
CTripmine_OnSpawn( const playerid, const Float:Pos[3], const Float:Ang[3] ) { new mine = FX_Breakable( g_iLaserAllocedString, g_szMineModel, Pos, Float:{ -8.0, -8.0, -8.0 }, Float:{ 8.0, 8.0, 8.0 }, "6", "100" ); set_pev(mine, pev_angles, Ang); set_pev(mine, pev_owner, playerid); set_pev(mine, pev_frame, 0); set_pev(mine, pev_body, 3); set_pev(mine, pev_sequence, TRIPMINE_WORLD); set_pev(mine, pev_framerate, 0.0); //set_pev(mine, pev_takedamage, DAMAGE_YES); set_pev(mine, pev_solid, SOLID_NOT); set_pev(mine, pev_movetype, MOVETYPE_FLY); emit_sound(mine, CHAN_VOICE, g_szMineDeploy, VOL_NORM, ATTN_NORM, 0, PITCH_NORM); emit_sound(mine, CHAN_BODY, g_szMineCharge, 0.2, ATTN_NORM, 0, PITCH_NORM);
set_pev(mine, pev_nextthink, get_gametime()+2.5); }
public CTripmine_OnKilled(victim, attacker, shouldgib) { }
public CTripmine_OnThink( const tripmine ) { new Float:vecSrc[3], Float:vForward[3]; pev( tripmine, pev_origin, vecSrc );
UTIL_MakeAimVectors( tripmine ); global_get(glb_v_forward, vForward);
xs_vec_mul_scalar(vForward, 8192.0, vForward); xs_vec_add(vForward, vecSrc, vForward); new tr, Float:fraction; engfunc(EngFunc_TraceLine, vecSrc, vForward, IGNORE_MONSTERS, -1, tr); get_tr2(tr, TR_flFraction, fraction); if(fraction < 1.0) { get_tr2(tr, TR_vecEndPos, vForward); new beam = FX_BeamEntPoint(tripmine, vecSrc, vForward, 10.0, 255.0, 64.0, Float:{ 0.0, 214.0, 198.0 }); set_pev( tripmine, pev_vecdir, vForward ); set_pev( beam, pev_owner, tripmine ); set_pev( beam, pev_nextthink, get_gametime()+0.1); } set_pev(tripmine, pev_solid, SOLID_BBOX); emit_sound(tripmine, CHAN_VOICE, g_szMineActivate, VOL_NORM, ATTN_NORM, 0, PITCH_NORM); }
public CTripmine_OnBeamThink( const beam ) { static tripmine; tripmine = pev( beam, pev_owner ); static Float:vecSrc[3], Float:vecEnd[3]; pev( tripmine, pev_origin, vecSrc ); pev( tripmine, pev_vecdir, vecEnd ); static tr, Float:fraction; engfunc(EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, tripmine, tr); get_tr2(tr, TR_flFraction, fraction);
client_print(0 , print_chat,"fraction %f", fraction);
if(fraction < 1.0) { static pHit; pHit = get_tr2( tr, TR_pHit );
client_print(0 , print_chat,"hit %d", pHit);
if( 1 <= pHit <= g_iMaxClients ) { client_print(0 , print_chat,"Check hit %d", pHit); //ExecuteHamB( Ham_Killed, tripmine, tripmine, 0); } } set_pev(beam, pev_nextthink, get_gametime()+0.1); }
UTIL_MakeAimVectors( const id ) { static Float:flAngle[3]; pev(id, pev_angles, flAngle);
flAngle[0] = -flAngle[0]; engfunc(EngFunc_MakeVectors, flAngle); }
UTIl_GetWeaponOwner( const weapon ) { if(pev_valid(weapon) != 2) return 0; return get_pdata_cbase(weapon, 41, 4); }
FX_BeamEntPoint(const i_Ent, const Float:vf_Origin[], const Float:vf_End[], const Float:f_Width, const Float:f_Scrollrate, const Float:f_Brightness, const Float:vf_Color[] ) { static beam; beam = engfunc(EngFunc_CreateNamedEntity, g_iBeamAllocedString );
set_pev_string(beam, pev_classname, g_iBeamAllocedString ); set_pev(beam, pev_flags, pev(beam, pev_flags ) | FL_CUSTOMENTITY ); set_pev(i_Ent, pev_beamindex, beam );
set_pev(beam, pev_model, g_szMineBeam ); set_pev(beam, pev_modelindex, g_iLaserModel );
set_pev(beam, pev_body, 0 ); set_pev(beam, pev_scale, f_Width ); set_pev(beam, pev_animtime, f_Scrollrate ); set_pev(beam, pev_rendercolor, vf_Color ); set_pev(beam, pev_renderamt, f_Brightness );
set_pev(beam, pev_rendermode, TE_BEAMENTPOINT & 0x0F );
set_pev(beam, pev_skin,(i_Ent & 0x0FFF ) |(1 & 0xF000 ) << 12 ); set_pev(beam, pev_aiment, i_Ent );
UTIL_RelinkBeam(beam, vf_Origin, vf_End ); return beam; }
FX_Breakable( const classname, const model[], const Float:source[ 3 ], const Float:mins[ 3 ], const Float:maxs[ 3 ], const material[], const health[] ) { new entity = create_entity( "func_breakable" );
set_pev_string( entity, pev_classname, classname ); set_pev( entity, pev_model, model ); set_pev( entity, pev_health, health );
DispatchKeyValue( entity, "material", material ); DispatchKeyValue( entity, "health", health );
DispatchSpawn( entity );
engfunc( EngFunc_SetSize, entity, mins, maxs ); engfunc( EngFunc_SetOrigin, entity, source ); return entity; }
UTIL_RelinkBeam( const i_Beam, const Float:vf_Origin[], const Float:vf_End[] ) { static Float:vf_Mins[ 3 ], Float:vf_Maxs[ 3 ];
vf_Mins[ 0 ] = floatmin ( vf_End[ 0 ], vf_Origin[ 0 ] ) - vf_End[ 0 ]; vf_Mins[ 1 ] = floatmin ( vf_End[ 1 ], vf_Origin[ 1 ] ) - vf_End[ 1 ]; vf_Mins[ 2 ] = floatmin ( vf_End[ 2 ], vf_Origin[ 2 ] ) - vf_End[ 2 ];
vf_Maxs[ 0 ] = floatmax ( vf_End[ 0 ], vf_Origin[ 0 ] ) - vf_End[ 0 ]; vf_Maxs[ 1 ] = floatmax ( vf_End[ 1 ], vf_Origin[ 1 ] ) - vf_End[ 1 ]; vf_Maxs[ 2 ] = floatmax ( vf_End[ 2 ], vf_Origin[ 2 ] ) - vf_End[ 2 ];
engfunc ( EngFunc_SetSize, i_Beam, vf_Mins, vf_Maxs ); engfunc ( EngFunc_SetOrigin, i_Beam, vf_End ); }
PS: pev_solid also not work. Every time the entity is not-solid.
Thanks.
|