Member
Join Date: Jan 2017
Location: Malaysia
|
03-25-2017
, 08:29
Re: Teleporting issues.
|
#5
|
Hello, again, sir.
You're the bomb, sir! The view offset works flawlessly!
But, the teleportation origin still isn't working. The teleportation still indeed stay the same as my code.
Anyway, thank you for your effort. I will look forward into the code, I will try to look for a better solution.
[EDIT]
Anyway, here the full code.
PHP Code:
#include <amxmodx> #include <fakemeta> #include <cstrike> #include <fun>
#define PLUGIN "Hiraishin no Jutsu" #define VERSION "0.1" #define AUTHOR "MuhdZaim"
new Float:vectTemp
#define VectToAngles(%1,%2) vectTemp = floatsqroot(%1[0]*%1[0] + %1[1]*%1[1]);\ %2[1] = floatacos(%1[0]/vectTemp, 1)*(1-2*_:(%1[1]<0));\ %2[0] =-floatatan(%1[2]/vectTemp, 1);\ %2[2] = 0.0
#define VectorAddScalar(%1,%2) %1[0]+=%2;%1[1]+=%2;%1[2]+=%2 #define VectorSet(%1,%2) %1[0]=%2[0];%1[1]=%2[1];%1[2]=%2[2] #define VectorAdd(%1,%2) %1[0]+=%2[0];%1[1]+=%2[1];%1[2]+=%2[2]
//credit to NL)Ramon(NL new const Float:size[][3] = { {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}, {0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {-1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, -1.0}, {-1.0, -1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, -1.0, -1.0}, {0.0, 0.0, 2.0}, {0.0, 0.0, -2.0}, {0.0, 2.0, 0.0}, {0.0, -2.0, 0.0}, {2.0, 0.0, 0.0}, {-2.0, 0.0, 0.0}, {-2.0, 2.0, 2.0}, {2.0, 2.0, 2.0}, {2.0, -2.0, 2.0}, {2.0, 2.0, -2.0}, {-2.0, -2.0, 2.0}, {2.0, -2.0, -2.0}, {-2.0, 2.0, -2.0}, {-2.0, -2.0, -2.0}, {0.0, 0.0, 3.0}, {0.0, 0.0, -3.0}, {0.0, 3.0, 0.0}, {0.0, -3.0, 0.0}, {3.0, 0.0, 0.0}, {-3.0, 0.0, 0.0}, {-3.0, 3.0, 3.0}, {3.0, 3.0, 3.0}, {3.0, -3.0, 3.0}, {3.0, 3.0, -3.0}, {-3.0, -3.0, 3.0}, {3.0, -3.0, -3.0}, {-3.0, 3.0, -3.0}, {-3.0, -3.0, -3.0}, {0.0, 0.0, 4.0}, {0.0, 0.0, -4.0}, {0.0, 4.0, 0.0}, {0.0, -4.0, 0.0}, {4.0, 0.0, 0.0}, {-4.0, 0.0, 0.0}, {-4.0, 4.0, 4.0}, {4.0, 4.0, 4.0}, {4.0, -4.0, 4.0}, {4.0, 4.0, -4.0}, {-4.0, -4.0, 4.0}, {4.0, -4.0, -4.0}, {-4.0, 4.0, -4.0}, {-4.0, -4.0, -4.0}, {0.0, 0.0, 5.0}, {0.0, 0.0, -5.0}, {0.0, 5.0, 0.0}, {0.0, -5.0, 0.0}, {5.0, 0.0, 0.0}, {-5.0, 0.0, 0.0}, {-5.0, 5.0, 5.0}, {5.0, 5.0, 5.0}, {5.0, -5.0, 5.0}, {5.0, 5.0, -5.0}, {-5.0, -5.0, 5.0}, {5.0, -5.0, -5.0}, {-5.0, 5.0, -5.0}, {-5.0, -5.0, -5.0} }
new bool:i_Hiraishin[ 33 ] new cvar_cooldown, cvar_money, cvar_one_round, g_Max new Float:g_iLastUseHiraishin[ 33 ]
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) cvar_cooldown = register_cvar( "hiraishin_cooldown", "15.0" ) cvar_money = register_cvar( "hiraishin_money", "4500" ) cvar_one_round = register_cvar( "hiraishin_one_round", "0" ) register_clcmd( "say /hiraishin", "BuyHiraishin" ) register_logevent( "RoundEnd", 2, "1=Round_End" ) register_forward( FM_CmdStart, "DoHiraishin" ) g_Max = get_maxplayers( ) }
public RoundEnd( ) { if( get_pcvar_num( cvar_one_round ) ) { for( new i; i < g_Max; i++ ) { if( i_Hiraishin[ i ] ) { i_Hiraishin[ i ] = false client_print( i, print_chat, "[HIRAISHIN] You Hiraishin no Jutsu has expired!" ) } } } }
public BuyHiraishin( id ) { if( !is_user_alive( id ) ) return; new money = cs_get_user_money( id ) if( money <= get_pcvar_num( cvar_money ) ) { client_print( id, print_chat, "[HIRAISHIN] You don't have enough money!" ) } else { cs_set_user_money( id, money - get_pcvar_num( cvar_money ) ) i_Hiraishin[ id ] = true; client_print( id, print_chat, "[HIRAISHIN] You now can do Hiraishin no Jutsu! ( Press E while aiming at an enemy )" ) } }
public DoHiraishin( id, uc_handle ) { if( !i_Hiraishin[ id ] || !is_user_alive( id ) || g_iLastUseHiraishin[ id ] > get_gametime( ) ) return; new button, aimid = 0, body button = get_uc( uc_handle, UC_Buttons ) get_user_aiming( id, aimid, body ) if( button & IN_USE && aimid <= get_maxplayers( ) && aimid != 0 && cs_get_user_team( aimid ) != cs_get_user_team( id ) ) { if( teleportBehind( id, aimid ) ) { set_task( 0.3, "CheckStuck", id ) g_iLastUseHiraishin[ id ] = get_gametime( ) + get_pcvar_float( cvar_cooldown ) set_task( get_pcvar_float( cvar_cooldown ), "ShowHiraishin", id ) } else { g_iLastUseHiraishin[ id ] = get_gametime( ) + 1.0 client_print( id, print_chat, "[HIRAISHIN] You are not able to teleport!" ) } } }
teleportBehind( id, target ) { new Float:vec[3], Float:origin[3], Float:fraction, Float:vecTemp[3], Float:vecTemp2[3], Float:vecTemp3[3], Float:vecTemp4[3], Float:len2, tr, i, j velocity_by_aim(target, 1, vec) new Float:len = floatsqroot(vec[0]*vec[0]+vec[1]*vec[1]) pev(target, pev_origin, origin) vecTemp3[0] = origin[0]-vec[0]*50.0/len vecTemp3[1] = origin[1]-vec[1]*50.0/len vecTemp3[2] = origin[2]+5.0
vecTemp4[0] = origin[0]-vec[0]*10.0/len vecTemp4[1] = origin[1]-vec[1]*10.0/len vecTemp4[2] = origin[2]+91.0 for(j=0; j<20; j++) { if(j<15) { VectorSet(vecTemp, vecTemp3) } else { VectorSet(vecTemp, vecTemp4) } for(i=0; i<100; i++) { //check if there is a valid position to avoid teleporting inside a wall or something; engfunc(EngFunc_TraceHull, vecTemp, vecTemp, 0, HULL_HUMAN, 0, tr) if(get_tr2(tr, TR_StartSolid) || get_tr2(tr, TR_AllSolid)) { VectorAddScalar(vecTemp, random_float(-10.0, 10.0)) continue } engfunc(EngFunc_TraceLine, origin, vecTemp, IGNORE_MONSTERS, 0, tr) get_tr2(tr, TR_flFraction, fraction) break } if(fraction == 1.0) { VectorSet(vecTemp2, vecTemp) VectorAdd(vecTemp2, -origin) len2 = len*floatsqroot(vecTemp2[0]*vecTemp2[0]+vecTemp2[1]*vecTemp2[1]+vecTemp2[2]*vecTemp2[2]) if(len2 > 100.0 || (vecTemp2[0]*vec[0]+vecTemp2[1]*vec[1])/len2 > 0.1) { fraction = 0.0 continue } break } }
if(fraction !=1.0) { client_print(id, print_console, "Error: Wrong position!") return PLUGIN_HANDLED; } set_pev(id, pev_origin, vecTemp) VectorSet(vecTemp, -vecTemp) VectorAdd(vecTemp, origin) VectToAngles(vecTemp, vecTemp) set_pev(id, pev_angles, vecTemp) set_pev(id, pev_fixangle, 1) return PLUGIN_CONTINUE; } /*bool:do_hiraishin( attacker, victim ) { new Float:OriginAttacker[ 3 ], Float:OriginEnemy[ 3 ], Float:AngleAttacker[ 3 ], Float:AngleEnemy[ 3 ] pev( victim, pev_angles, AngleEnemy ) pev( attacker, pev_origin, OriginAttacker ) pev( victim, pev_origin, OriginEnemy ) OriginAttacker[ 0 ] = OriginEnemy[ 0 ] - 30.0 OriginAttacker[ 1 ] = OriginEnemy[ 1 ] OriginAttacker[ 2 ] = OriginEnemy[ 2 ] + 5.0 set_pev( attacker, pev_origin, OriginAttacker ) set_pev( attacker, pev_angles, AngleEnemy ) //if( is_player_stuck( id, OriginUser ) ) //return false; return true; }*/ public ShowHiraishin( id ) { if( !is_user_alive( id ) ) return; client_print( id, print_chat, "[HIRAISHIN] Your jutsu is ready!" ) }
public CheckStuck( id3 ) { if( !is_user_alive( id3 ) ) return; static Float:origin[ 3 ], Float:mins[ 3 ], hull, Float:vec[ 3 ], o pev( id3, pev_origin, origin ) hull = pev( id3, pev_flags ) & FL_DUCKING ? HULL_HEAD : HULL_HUMAN if( !is_hull_vacant( origin, hull, id3 ) && !get_user_noclip( id3 ) && !(pev( id3, pev_solid ) & SOLID_NOT ) ) { pev( id3, pev_mins, mins ) vec[ 2 ] = origin[ 2 ] for( o=0; o < sizeof size; ++o ) { vec[ 0 ] = origin[ 0 ] - mins[ 0 ] * size[ o ][ 0 ] vec[ 1 ] = origin[ 1 ] - mins[ 1 ] * size[ o ][ 1 ] vec[ 2 ] = origin[ 2 ] - mins[ 2 ] * size[ o ][ 2 ] if( is_hull_vacant( vec, hull, id3 ) ) { engfunc( EngFunc_SetOrigin, id3, vec ) set_pev( id3, pev_velocity, { 0.0,0.0,0.0 } ) o = sizeof size } } } }
//credit to NL)Ramon(NL bool:is_hull_vacant(const Float:origin[3], hull, id) { static tr; engfunc(EngFunc_TraceHull, origin, origin, 0, hull, id, tr); if(!get_tr2(tr, TR_StartSolid) || !get_tr2(tr, TR_AllSolid)) return true; return false; }
/*stock is_player_stuck(id, Float:originF[3]) { engfunc(EngFunc_TraceHull, originF, originF, 0, (pev(id, pev_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN, id, 0) if (get_tr2(0, TR_StartSolid) || get_tr2(0, TR_AllSolid) || !get_tr2(0, TR_InOpen)) return true; return false; }*/
Last edited by Kotoamatsukami; 03-25-2017 at 08:31.
Reason: Code posted.
|
|