Raised This Month: $32 Target: $400
 8% 

Teleporting issues.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-15-2017 , 13:34   Teleporting issues.
Reply With Quote #1

Hello, greetings.
Firstly, I am still new about calculation involving origins, vectors, and angles( though I had learnt about angles, I still confront difficulties on how to apply it in CS ). I took hours and days to understand origins and angles( as starting for my next involvement into vectors and velocity ), sadly, I can't get along very well as I just understand on how to get origins then set new origins and view angles of a player( pitch, yaw, roll ).
Sorry if this topic has been covered but I've searched all around the forum and still hasn't find any threads that is related to my issue. Hence, I made this thread.
Some of them;
https://forums.alliedmods.net/showthread.php?t=91474
https://forums.alliedmods.net/showth...light=teleport
https://forums.alliedmods.net/showth...light=teleport
https://forums.alliedmods.net/showth...light=teleport

and more...

My issue is simple, I believe it wouldn't involve any complicated calculations.
How do I teleport behind the aimed player properly? As at some points, I don't teleport behind them, sometimes, I teleport by his side and sometime on his front and the problems continues... any solution with explanation would be very helpful..

Thank you for your time... here the code that I made recently.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>

#define PLUGIN "BACKSTAB !!!"
#define VERSION "0.1"
#define AUTHOR "MuhdZaim"

new bool:g_icanBackstab33 ]

public 
plugin_init( ) 
{
    
register_pluginPLUGINVERSIONAUTHOR )
    
    
register_forwardFM_CmdStart"FM_Execute" )
    
    
register_clcmd"say /givemebackstab""youcanbackstab" )
}

public 
youcanbackstabid )
{
    if( !
is_user_aliveid ) ) return;
    
    if( !
g_icanBackstabid ] )
        
g_icanBackstabid ] = true;
    else
        
client_printidprint_chat"You already have your Backstab ability!" )
}

public 
FM_Executeiduc )
{
    if( !
is_user_aliveid ) && !g_icanBackstabid ] ) return;
    
    new 
buttonid2body;
    
    
button get_ucucUC_Buttons )
    
get_user_aimingidid2body )
    
    if( 
button IN_USE && id2 != && id2 <= get_maxplayers( ) &&  cs_get_user_teamid ) != cs_get_user_teamid2 ) )
    {
        
DoBackStabidid2 )
    }
}

DoBackStabattackerenemy )
{
    new 
Float:origin1], Float:origin2]//,
    //Float:vangle[ 3 ];
    
    
pevattackerpev_originorigin1 )
    
pevenemypev_originorigin2 )
    
//pev( enemy, pev_v_angle, vangle)
    
    
origin1] = origin2] - 30.0
    origin1
] = origin2]
    
origin1] = origin2] + 5.0
    
    set_pev
attackerpev_originorigin1 )
    
//set_pev( attacker, pev_v_angle, vangle )

PS : The pev_v_angle is still on doubt, I wanted to make the attacker view be exactly as the victim view as the attacker be on his back during the teleportation and he can instantly backstab the victim but that didn't happen..

Last edited by Kotoamatsukami; 03-15-2017 at 13:37.
Kotoamatsukami is offline
Schizz
New Member
Join Date: Mar 2017
Old 03-21-2017 , 20:25   Re: Teleporting issues.
Reply With Quote #2

Hmm, I remember I did exactly such a thing for my mod for Skyrim. There was a spell which teleports the NPC always behind the attacker.

So I opened The Creation Kit and took the script and transferred it to some kind of pseudo code.
I believe it might help you.


Code:
function teleportBehind(caster, enemy, distance, arc) // you should set arc to 180 if you want to teleport always right behind
		
		float telX = enemy.GetPositionX()
		float telY = enemy.GetPositionY()
		float telZ = enemy.GetPositionZ()
		
		float angleX = enemy.GetAngleX()
		float angleZ = enemy.GetAngleZ() + arc;

		telX = telX - sin(angleZ) * distance;
		telY = telY - cos(angleZ) * distance;
	
		caster.setPosition(telX,telY,telZ)
		caster.SetAngle(caster.GetAngleX(), caster.GetAngleY(), angleZ)		
		
endfunction

Last edited by Schizz; 03-21-2017 at 22:32.
Schizz is offline
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-22-2017 , 20:19   Re: Teleporting issues.
Reply With Quote #3

Hello, sir.

Thank you, I get the ideas and I will try to implement those in my code. Just for some clarification, can you tell me how exactly ( X,Y,Z ) origins works in Skyrim? In CS, X-origin, Y-origin, and Z-origin manipulates front/back, right/left, up/down positions respectively.
Kotoamatsukami is offline
Schizz
New Member
Join Date: Mar 2017
Old 03-23-2017 , 06:48   Re: Teleporting issues.
Reply With Quote #4

hmm, try this

PHP Code:

new Float:vectTemp
#define VectToAngles(%1,%2) vectTemp = floatsqroot(%1[0]*%1[0] + %1[1]*%1[1]);\
    
%2[1] = floatacos(%1[0]/vectTemp1)*(1-2*_:(%1[1]<0));\
    %
2[0] =-floatatan(%1[2]/vectTemp1);\
    %
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]



public teleportBehind(idtarget){
    new 
Float:vec[3], Float:origin[3], Float:fractionFloat:vecTemp[3], Float:vecTemp2[3], Float:vecTemp3[3], Float:vecTemp4[3], Float:len2trij
    
    velocity_by_aim
(target1vec)
    new 
Float:len floatsqroot(vec[0]*vec[0]+vec[1]*vec[1])
    
    
pev(targetpev_originorigin)
    
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=0j<20j++){
        if(
j<15){
            
VectorSet(vecTempvecTemp3)
        }else{
            
VectorSet(vecTempvecTemp4)
        }
        for(
i=0i<100i++){      //check if there is a valid position to avoid teleporting inside a wall or something;
            
engfunc(EngFunc_TraceHullvecTempvecTemp0HULL_HUMAN0tr)
            if(
get_tr2(trTR_StartSolid) || get_tr2(trTR_AllSolid)){
                
VectorAddScalar(vecTemprandom_float(-10.010.0))
                continue
            }   
            
engfunc(EngFunc_TraceLineoriginvecTempIGNORE_MONSTERS0tr)
            
get_tr2(trTR_flFractionfraction)
            break
        }
        if(
fraction == 1.0){
            
VectorSet(vecTemp2vecTemp)    
            
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(idprint_console"Error: Wrong position!")
        return
    }
    
    
set_pev(idpev_originvecTemp)
    
    
VectorSet(vecTemp, -vecTemp)        
    
VectorAdd(vecTemporigin)
    
VectToAngles(vecTempvecTemp)    
    
    
set_pev(idpev_anglesvecTemp)
    
set_pev(idpev_fixangle1)


Last edited by Schizz; 03-23-2017 at 06:49.
Schizz is offline
Old 03-24-2017, 19:42
Kotoamatsukami
This message has been deleted by Kotoamatsukami. Reason: Update
Kotoamatsukami
Member
Join Date: Jan 2017
Location: Malaysia
Old 03-25-2017 , 08:29   Re: Teleporting issues.
Reply With Quote #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]/vectTemp1)*(1-2*_:(%1[1]<0));\
%
2[0] =-floatatan(%1[2]/vectTemp1);\
%
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.00.01.0}, {0.00.0, -1.0}, {0.01.00.0}, {0.0, -1.00.0}, {1.00.00.0}, {-1.00.00.0}, {-1.01.01.0}, {1.01.01.0}, {1.0, -1.01.0}, {1.01.0, -1.0}, {-1.0, -1.01.0}, {1.0, -1.0, -1.0}, {-1.01.0, -1.0}, {-1.0, -1.0, -1.0},
    {
0.00.02.0}, {0.00.0, -2.0}, {0.02.00.0}, {0.0, -2.00.0}, {2.00.00.0}, {-2.00.00.0}, {-2.02.02.0}, {2.02.02.0}, {2.0, -2.02.0}, {2.02.0, -2.0}, {-2.0, -2.02.0}, {2.0, -2.0, -2.0}, {-2.02.0, -2.0}, {-2.0, -2.0, -2.0},
    {
0.00.03.0}, {0.00.0, -3.0}, {0.03.00.0}, {0.0, -3.00.0}, {3.00.00.0}, {-3.00.00.0}, {-3.03.03.0}, {3.03.03.0}, {3.0, -3.03.0}, {3.03.0, -3.0}, {-3.0, -3.03.0}, {3.0, -3.0, -3.0}, {-3.03.0, -3.0}, {-3.0, -3.0, -3.0},
    {
0.00.04.0}, {0.00.0, -4.0}, {0.04.00.0}, {0.0, -4.00.0}, {4.00.00.0}, {-4.00.00.0}, {-4.04.04.0}, {4.04.04.0}, {4.0, -4.04.0}, {4.04.0, -4.0}, {-4.0, -4.04.0}, {4.0, -4.0, -4.0}, {-4.04.0, -4.0}, {-4.0, -4.0, -4.0},
    {
0.00.05.0}, {0.00.0, -5.0}, {0.05.00.0}, {0.0, -5.00.0}, {5.00.00.0}, {-5.00.00.0}, {-5.05.05.0}, {5.05.05.0}, {5.0, -5.05.0}, {5.05.0, -5.0}, {-5.0, -5.05.0}, {5.0, -5.0, -5.0}, {-5.05.0, -5.0}, {-5.0, -5.0, -5.0}
}

new 
bool:i_Hiraishin33 ]
new 
cvar_cooldowncvar_moneycvar_one_roundg_Max
new Float:g_iLastUseHiraishin33 ]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
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_forwardFM_CmdStart"DoHiraishin" )
    
    
g_Max get_maxplayers( )
}

public 
RoundEnd( )
{
    if( 
get_pcvar_numcvar_one_round ) )
    {
        for( new 
ig_Maxi++ )
        {
            if( 
i_Hiraishin] )
            {
                
i_Hiraishin] = false
                client_print
iprint_chat"[HIRAISHIN] You Hiraishin no Jutsu has expired!" )
            }
        }
    }
}

public 
BuyHiraishinid )
{
    if( !
is_user_aliveid ) ) return;
    
    new 
money cs_get_user_moneyid )
    
    if( 
money <= get_pcvar_numcvar_money ) )
    {
        
client_printidprint_chat"[HIRAISHIN] You don't have enough money!" )
    }
    else
    {
        
cs_set_user_moneyidmoney get_pcvar_numcvar_money ) )
        
i_Hiraishinid ] = true;
        
client_printidprint_chat"[HIRAISHIN] You now can do Hiraishin no Jutsu! ( Press E while aiming at an enemy )" )
    }
}

public 
DoHiraishiniduc_handle )
{
    if( !
i_Hiraishinid ] || !is_user_aliveid ) || g_iLastUseHiraishinid ] > get_gametime( ) ) return;
    
    new 
buttonaimid 0body
    
    button 
get_ucuc_handleUC_Buttons )
    
    
get_user_aimingidaimidbody  )
    
    if( 
button IN_USE  && aimid <= get_maxplayers( ) && aimid != && cs_get_user_teamaimid ) != cs_get_user_teamid ) )
    {
        if( 
teleportBehindidaimid ) )
        {
            
set_task0.3"CheckStuck"id )
            
g_iLastUseHiraishinid ] = get_gametime( ) + get_pcvar_floatcvar_cooldown )
            
set_taskget_pcvar_floatcvar_cooldown ), "ShowHiraishin"id )
        }
        else
        {
            
g_iLastUseHiraishinid ] = get_gametime( ) + 1.0
        
            client_print
idprint_chat"[HIRAISHIN] You are not able to teleport!" )
        }
        
    }
}

teleportBehindidtarget )
{
    new 
Float:vec[3], Float:origin[3], Float:fractionFloat:vecTemp[3], Float:vecTemp2[3], Float:vecTemp3[3], Float:vecTemp4[3], Float:len2trij
    
    velocity_by_aim
(target1vec)
    new 
Float:len floatsqroot(vec[0]*vec[0]+vec[1]*vec[1])
    
    
pev(targetpev_originorigin)
    
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=0j<20j++)
    {
        if(
j<15)
        {
            
VectorSet(vecTempvecTemp3)
        }
        else
        {
            
VectorSet(vecTempvecTemp4)
        }
        
        for(
i=0i<100i++)
        {      
//check if there is a valid position to avoid teleporting inside a wall or something;
            
engfunc(EngFunc_TraceHullvecTempvecTemp0HULL_HUMAN0tr)
            
            if(
get_tr2(trTR_StartSolid) || get_tr2(trTR_AllSolid))
            {
                
VectorAddScalar(vecTemprandom_float(-10.010.0))
                continue
            }  
        
            
engfunc(EngFunc_TraceLineoriginvecTempIGNORE_MONSTERS0tr)
            
get_tr2(trTR_flFractionfraction)
            break
        }
        
        if(
fraction == 1.0)
        {
            
VectorSet(vecTemp2vecTemp)    
            
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(idprint_console"Error: Wrong position!")
        return 
PLUGIN_HANDLED;
    }
    
    
set_pev(idpev_originvecTemp)
    
    
VectorSet(vecTemp, -vecTemp)        
    
VectorAdd(vecTemporigin)
    
VectToAngles(vecTempvecTemp)    
    
    
set_pev(idpev_anglesvecTemp)
    
set_pev(idpev_fixangle1)
    
    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 ShowHiraishinid )
{
    if( !
is_user_aliveid ) ) return;
    
    
client_printidprint_chat"[HIRAISHIN] Your jutsu is ready!" )
}

public 
CheckStuckid3 )
{
    if( !
is_user_aliveid3 ) ) return;
    
    static 
Float:origin], Float:mins], hullFloat:vec], o
    pev
id3pev_originorigin )
    
hull pevid3pev_flags ) & FL_DUCKING HULL_HEAD HULL_HUMAN
    
    
if( !is_hull_vacantoriginhullid3 ) && !get_user_noclipid3 ) && !(pevid3pev_solid ) & SOLID_NOT ) )
    {
        
pevid3pev_minsmins )
        
vec] = origin]
        
        for( 
o=0sizeof size; ++)
        {
            
vec] = origin] - mins] * size][ ]
            
vec] = origin] - mins] * size][ ]
            
vec] = origin] - mins] * size][ ]
            
            if( 
is_hull_vacantvechullid3 ) )
            {
                
engfuncEngFunc_SetOriginid3vec )
                
set_pevid3pev_velocity, { 0.0,0.0,0.0 } )
                
sizeof size
            
}
        }
    }
}

//credit to NL)Ramon(NL
bool:is_hull_vacant(const Float:origin[3], hullid)
{
    static 
trengfunc(EngFunc_TraceHulloriginorigin0hullidtr);
    if(!
get_tr2(trTR_StartSolid) || !get_tr2(trTR_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.
Kotoamatsukami is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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