AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Where player aim -> Same angle to object. (https://forums.alliedmods.net/showthread.php?t=82816)

xPaw 12-30-2008 13:28

Where player aim -> Same angle to object.
 
how to do that?

Dores 12-30-2008 14:24

Re: Where player aim -> Same angle to object.
 
What do you mean? Do you mean getting the aiming origin?
If so, use fakemeta_util's stock:
PHP Code:

stock fm_get_aimorigin(indexFloat:origin[3])
{
    new 
Float:start[3], Float:view_ofs[3];
    
pev(indexpev_originstart);
    
pev(indexpev_view_ofsview_ofs);
    
xs_vec_add(startview_ofsstart);
    
    new 
Float:dest[3];
    
pev(indexpev_v_angledest);
    
engfunc(EngFunc_MakeVectorsdest);
    
global_get(glb_v_forwarddest);
    
xs_vec_mul_scalar(dest9999.0dest);
    
xs_vec_add(startdestdest);
    
    
engfunc(EngFunc_TraceLinestartdest0index0);
    
get_tr2(0TR_vecEndPosorigin);
    
    return 
1;


If not, please explain exactly what you want.

xPaw 12-30-2008 14:28

Re: Where player aim -> Same angle to object.
 
yes i want get where player is watching, and in same view(angle) set the entity, i mean entity will rotate like a player, for example how it works with MOVETYPE_FOLLOW.

Hawk552 12-30-2008 14:34

Re: Where player aim -> Same angle to object.
 
You'd have to get the forward vector. Here's an example:

Code:
/* Assume id is passed to this function */ new Float:Origin[3],Float:Angle[3],Float:Forward[3],Float:Result[3] pev(id,pev_origin,Origin) pev(id,pev_v_angle,Angle)         engfunc(EngFunc_MakeVectors,Angle) global_get(glb_v_forward,Forward)         Result[0] = Origin[0] + Forward[0] * 100 Result[1] = Origin[1] + Forward[1] * 100 /* This will leave it on the same z axis,     but if you want it to go up and down,     uncomment the line after and comment     this one */ Result[2] = Origin[2] //Result[2] = Origin[2] + Forward[2] * 100 engfunc(EngFunc_SetOrigin,Index,Result)

You can also make it go to the right, up, etc, using glb_v_right and glb_v_up.

Dores 12-30-2008 14:46

Re: Where player aim -> Same angle to object.
 
Instead of the user's origin, I would suggest using the origin from his eyes:
PHP Code:

#include <amxmodx>
#include <fakemeta_util>

#define VERSION "1.0"

#define HEAD_POSITION    8
#define DESIRED_DISTANCE    100 // Change this to whatever.

new g_entid;

public 
plugin_init()
{
    
register_plugin"Moving an entity by the aim"VERSION"Dores" );
    
register_forwardFM_PlayerPreThink"Forward_PreThink" );
    
register_clcmd"say /ent""Cmd_Create" );
}

public 
Cmd_Createid )
{
    new 
Float:aimorigin];
    
fm_get_aim_originidaimorigin );
    
    
g_entid fm_create_entity"info_target" );
    
set_pevg_entidpev_classname"BlaBla" );
    
set_pevg_entidpev_movetypeMOVETYPE_FOLLOW );
    
set_pevg_entidpev_ownerid );
    
    
// ETC. - Create entity with your likings.
    
    
    
return PLUGIN_HANDLED;
}

public 
Forward_PreThinkid )
{
    if( !
is_user_aliveid ) )
        return 
FMRES_IGNORED;
    
    static 
Float:start], Float:Forward], Float:end];
    
engfuncEngFunc_GetBonePositionidHEAD_POSITIONstart );
    
pevidpev_v_angleForward );
    
engfuncEngFunc_MakeVectorsForward );
    
global_getglb_v_forwardForward );
    
end] = start] + Forward] * DESIRED_DISTANCE;
    
end] = start] + Forward] * DESIRED_DISTANCE;
    
end] = start]; // Height of the eyes.
    
engfuncEngFunc_SetOriging_entidend ); // Update the ent's origin.
    
    
return FMRES_IGNORED;



xPaw 12-30-2008 15:03

Re: Where player aim -> Same angle to object.
 
no guys thats not that. i want that entity will be rotating like my player model rotataing
if i'm watching to right, the entity will watch there too.

EDIT:
going try that
PHP Code:

new Float:vAngles[3];

pev(idpev_anglesvAngles);

//set the angles of the model to be the same as the player
set_pev(modelpev_anglesvAngles); 


Dores 12-30-2008 17:17

Re: Where player aim -> Same angle to object.
 
You can only do that if the model is an entity.

Maybe try view angles:
PHP Code:

new Float:flAngles] ; pevidpev_v_angleflAngles );
set_pevmodelpev_v_angleflAngles ); 


Hawk552 12-30-2008 18:35

Re: Where player aim -> Same angle to object.
 
I think you have to get the player's v_angles then set the entity's angle using that.

Dores 12-30-2008 19:31

Re: Where player aim -> Same angle to object.
 
Quote:

Originally Posted by Hawk552 (Post 735763)
I think you have to get the player's v_angles then set the entity's angle using that.

Sounds reasonable.

xPaw 12-31-2008 05:34

Re: Where player aim -> Same angle to object.
 
i used that what i posted above, and it worked perfect


All times are GMT -4. The time now is 09:11.

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