AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   How can I do that...? (https://forums.alliedmods.net/showthread.php?t=315386)

EFFx 04-05-2019 13:12

How can I do that...?
 
I found that stock some weeks ago but I couldn't find it anymore. What I want to know is how can I force an entity/player aim at a certain origin?

thEsp 04-05-2019 13:34

Re: How can I do that...?
 
PHP Code:

entity_set_vector(index,EV_VEC_angles,angle[3])
entity_set_int(index,EV_INT_fixangle,1

PHP Code:

set_pev(index,pev_v_angle,dest

Not sure about the first, I found it in a post a long time ago, and re-found it again (May be wrong post..)
EDIT: First one works just fine, but you need to convert aiming vector/float to angle.

EFFx 04-05-2019 14:07

Re: How can I do that...?
 
I think you misunderstood what I said, lemme give more details:

I have the end position of where I'm aiming at, I just wanna make another player aim where my end position from my crosshair is.

Natsheh 04-05-2019 14:19

Re: How can I do that...?
 
PHP Code:

stock LookAtOrigin(const id, const Float:fOrigin_dest[3])
{
    static 
Float:fOrigin[3];
    
pev(idpev_originfOrigin);
    
    if(
fOrigin[0] == fOrigin_dest[0] && // center
        
fOrigin[1] == fOrigin_dest[1]) // center
            
return;
    
    static 
Float:fLook[3];
    
xs_vec_sub(fOrigin_destfOriginfOrigin);
    
xs_vec_normalize(fOriginfOrigin);
    
vector_to_angle(fOriginfLook);
    
    
set_pev(idpev_anglesfLook);
    
set_pev(idpev_fixangle1);



EFFx 04-05-2019 14:33

Re: How can I do that...?
 
I dunno if either the stock is wrong or the way it works with that plugin is wrong. But when I'd spray with the AK or any weapon with recoil, the camera goes crazy.

The reason I asked for such stock is that I might fix the wrong aim problem by making the player follow the end origin that the camera is looking at, but somehow it didn't work correctly, what could be wrong?

PHP Code:

#include <amxmodx> 
#include <fakemeta> 
#include <fakemeta_util> 
#include <hamsandwich> 
#include <xs> 

#define VERSION "0.0.2" 

#define MAX_PLAYERS    32 
#define USE_TOGGLE 3 

new CAMERA_FORWARD
new CAMERA_RIGHT 
new CAMERA_UP
new CAMERA_FRACTION

new g_iPlayerCamera[MAX_PLAYERS+1

new 
g_iMaxPlayers 

public plugin_init() 

    
register_plugin("Camera View AUTOMATIC"VERSION"ConnorMcLeod"
    
    
CAMERA_FORWARD register_cvar("camera_forward""-100.0")
    
CAMERA_RIGHT register_cvar("camera_right""0.0")
    
CAMERA_UP register_cvar("camera_up""25.0")
    
CAMERA_FRACTION register_cvar("camera_fraction""-35.0")
    
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn_Post"1
    
register_forward(FM_SetView"SetView"
    
RegisterHam(Ham_Think"trigger_camera""Camera_Think"
    
    
g_iMaxPlayers get_maxplayers() 


public 
CBasePlayer_Spawn_Post(id

    if(!
is_user_alive(id)) 
    { 
        return 
    } 
    
    new 
iEnt g_iPlayerCamera[id
    if(!
pev_valid(iEnt)) 
    { 
        static 
iszTriggerCamera 
        
if(!iszTriggerCamera
        { 
            
iszTriggerCamera engfunc(EngFunc_AllocString"trigger_camera"
        } 
        
iEnt engfunc(EngFunc_CreateNamedEntityiszTriggerCamera
        
set_kvd(0KV_ClassName"trigger_camera"
        
set_kvd(0KV_fHandled0
        
set_kvd(0KV_KeyName"wait"
        
set_kvd(0KV_Value"999999"
        
dllfunc(DLLFunc_KeyValueiEnt0
        
        
set_pev(iEntpev_spawnflagsSF_CAMERA_PLAYER_TARGET|SF_CAMERA_PLAYER_POSITION
        
set_pev(iEntpev_flagspev(iEntpev_flags) | FL_ALWAYSTHINK
        
        
dllfunc(DLLFunc_SpawniEnt
        
        
g_iPlayerCamera[id] = iEnt 
        
        
new Float:flMaxSpeediFlags pev(idpev_flags
        
pev(idpev_maxspeedflMaxSpeed
        
        
ExecuteHam(Ham_UseiEntididUSE_TOGGLE1.0
        
        
set_pev(idpev_flagsiFlags
        
engfunc(EngFunc_SetClientMaxspeedidflMaxSpeed
        
set_pev(idpev_maxspeedflMaxSpeed
    } 


public 
SetView(idiEnt

    if(
is_user_alive(id)) 
    { 
        new 
iCamera g_iPlayerCamera[id
        if(
iCamera && iEnt != iCamera
        { 
            new 
szClassName[16
            
pev(iEntpev_classnameszClassNamecharsmax(szClassName)) 
            if(!
equal(szClassName"trigger_camera")) // should let real cams enabled 
            

                
engfunc(EngFunc_SetViewidiCamera// shouldn't be always needed 
                
return FMRES_SUPERCEDE 
            

        } 
    } 
    return 
FMRES_IGNORED 


public 
client_disconnect(id

    new 
iEnt g_iPlayerCamera[id
    if(
pev_valid(iEnt)) 
    { 
        
engfunc(EngFunc_RemoveEntityiEnt
    } 
    
g_iPlayerCamera[id] = 


public 
client_putinserver(id

    
g_iPlayerCamera[id] = 


public 
get_cam_owner(iEnt

    static 
id 
    
for(id 1id<=g_iMaxPlayersid++) 
    { 
        if(
g_iPlayerCamera[id] == iEnt
        { 
            return 
id 
        

    } 
    return 



public 
Camera_Think(iEnt

    static 
id 
    
if(!(id get_cam_owner(iEnt))) 
    { 
        return 
    } 
    
    static 
Float:fVecPlayerOrigin[3], Float:fVecCameraOrigin[3], Float:fVecAngles[3],  
    
Float:fVecForward[3], Float:fVecRight[3], Float:fVecUp[3]
    
    
pev(idpev_originfVecPlayerOrigin
    
pev(idpev_view_ofsfVecAngles
    
fVecPlayerOrigin[2] += fVecAngles[2
    
pev(idpev_v_anglefVecAngles
    
    
angle_vector(fVecAnglesANGLEVECTOR_FORWARDfVecForward
    
angle_vector(fVecAnglesANGLEVECTOR_RIGHTfVecRight
    
angle_vector(fVecAnglesANGLEVECTOR_UPfVecUp
    
    
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[0] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[0] * get_pcvar_float(CAMERA_UP
    
fVecCameraOrigin[1] = fVecPlayerOrigin[1] + fVecForward[1] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[1] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[1] * get_pcvar_float(CAMERA_UP
    
fVecCameraOrigin[2] = fVecPlayerOrigin[2] + fVecForward[2] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[2] * get_pcvar_float(CAMERA_RIGHT) + fVecUp[2] * get_pcvar_float(CAMERA_UP
    
    
engfunc(EngFunc_TraceLinefVecPlayerOriginfVecCameraOriginIGNORE_MONSTERSid0
    
    static 
Float:flFraction 
    get_tr2
(0TR_flFractionflFraction
    if(
flFraction != 1.0// adjust camera place if close to a wall 
    

        
flFraction *= get_pcvar_float(CAMERA_FRACTION)
        
        
//fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * flFraction + fVecRight[0] * flFraction + fVecUp[0] * flFraction 
        //fVecCameraOrigin[1] = fVecPlayerOrigin[1] + fVecForward[1] * flFraction + fVecRight[1] * flFraction + fVecUp[1] * flFraction 
        //fVecCameraOrigin[2] = fVecPlayerOrigin[2] + fVecForward[2] * flFraction + fVecRight[2] * flFraction + fVecUp[2] * flFraction 
        
        
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + (fVecForward[0] * flFraction
        
fVecCameraOrigin[1] = fVecPlayerOrigin[1] + (fVecForward[1] * flFraction
        
fVecCameraOrigin[2] = fVecPlayerOrigin[2] + (fVecForward[2] * flFraction
    } 
    
    
set_pev(iEntpev_originfVecCameraOrigin)
    
set_pev(iEntpev_anglesfVecAngles)
    
set_pev(idpev_anglesfVecAngles)
    
    new 
Float:fEntityEndPosition[3]
    
getAimEndPosition(iEntfEntityEndPosition)
    
lookAtOrigin(idfEntityEndPosition)
}  

getAimEndPosition(idFloat:fOrigin[3]) 
{
    new 
Float:fStart[3], Float:fViewOfs[3]
    
pev(idpev_originfStart)
    
pev(idpev_view_ofsfViewOfs)
    
xs_vec_add(fStartfViewOfsfStart)

    new 
Float:fDest[3]
    
pev(idpev_v_anglefDest)
    
engfunc(EngFunc_MakeVectorsfDest)
    
global_get(glb_v_forwardfDest)
    
xs_vec_mul_scalar(fDest9999.0fDest)
    
xs_vec_add(fStartfDestfDest)

    
engfunc(EngFunc_TraceLinefStartfDest0id0)
    
get_tr2(0TR_vecEndPosfOrigin)


lookAtOrigin(const id, const Float:fOrigin_dest[3])
{
    static 
Float:fOrigin[3]
    
pev(idpev_originfOrigin)
    
    if(
fOrigin[0] == fOrigin_dest[0] && fOrigin[1] == fOrigin_dest[1])
        return
    
    static 
Float:fLook[3]
    
xs_vec_sub(fOrigin_destfOriginfOrigin)
    
xs_vec_normalize(fOriginfOrigin)
    
vector_to_angle(fOriginfLook)
    
    
set_pev(idis_user_connected(id) ? pev_v_angle:pev_anglesfLook)
    
set_pev(idpev_fixangle1)




Edit: I've found this, but the player is not following the end position of the camera - https://forums.alliedmods.net/showpo...40&postcount=3

Natsheh 04-06-2019 15:57

Re: How can I do that...?
 
here you go after few tests...

PHP Code:

#include <amxmodx> 
#include <fakemeta> 
#include <fakemeta_util> 
#include <hamsandwich> 
#include <xs> 

#define VERSION "0.0.2" 

#define MAX_PLAYERS    32 
#define USE_TOGGLE 3 

new CAMERA_FORWARD
new CAMERA_RIGHT 
new CAMERA_UP
new CAMERA_FRACTION

new g_iPlayerCamera[MAX_PLAYERS+1

new 
g_iMaxPlayers;

new 
sprite_index;

public 
plugin_precache() sprite_index precache_model("sprites/laserbeam.spr");

public 
plugin_init() 

    
register_plugin("Camera View AUTOMATIC"VERSION"ConnorMcLeod"
    
    
CAMERA_FORWARD register_cvar("camera_forward""-100.0")
    
CAMERA_RIGHT register_cvar("camera_right""0.0")
    
CAMERA_UP register_cvar("camera_up""25.0")
    
CAMERA_FRACTION register_cvar("camera_fraction""-35.0")
    
    
RegisterHam(Ham_Spawn"player""CBasePlayer_Spawn_Post"1
    
register_forward(FM_SetView"SetView"
    
RegisterHam(Ham_Think"trigger_camera""Camera_Think")
    
    
g_iMaxPlayers get_maxplayers();
}

public 
CBasePlayer_Spawn_Post(id

    if(!
is_user_alive(id)) 
    { 
        return 
    } 
    
    new 
iEnt g_iPlayerCamera[id
    if(!
pev_valid(iEnt)) 
    { 
        static 
iszTriggerCamera 
        
if(!iszTriggerCamera
        { 
            
iszTriggerCamera engfunc(EngFunc_AllocString"trigger_camera"
        } 
        
iEnt engfunc(EngFunc_CreateNamedEntityiszTriggerCamera
        
set_kvd(0KV_ClassName"trigger_camera"
        
set_kvd(0KV_fHandled0
        
set_kvd(0KV_KeyName"wait"
        
set_kvd(0KV_Value"999999"
        
dllfunc(DLLFunc_KeyValueiEnt0
        
        
set_pev(iEntpev_spawnflagsSF_CAMERA_PLAYER_TARGET|SF_CAMERA_PLAYER_POSITION
        
set_pev(iEntpev_flagspev(iEntpev_flags) | FL_ALWAYSTHINK
        
        
dllfunc(DLLFunc_SpawniEnt
        
        
g_iPlayerCamera[id] = iEnt 
        
        
new Float:flMaxSpeediFlags pev(idpev_flags
        
pev(idpev_maxspeedflMaxSpeed
        
        
ExecuteHam(Ham_UseiEntididUSE_TOGGLE1.0
        
        
set_pev(idpev_flagsiFlags
        
engfunc(EngFunc_SetClientMaxspeedidflMaxSpeed
        
set_pev(idpev_maxspeedflMaxSpeed
    } 


public 
SetView(idiEnt

    if(
is_user_alive(id)) 
    { 
        new 
iCamera g_iPlayerCamera[id
        if(
iCamera && iEnt != iCamera
        { 
            new 
szClassName[16
            
pev(iEntpev_classnameszClassNamecharsmax(szClassName)) 
            if(!
equal(szClassName"trigger_camera")) // should let real cams enabled 
            

                
engfunc(EngFunc_SetViewidiCamera// shouldn't be always needed 
                
return FMRES_SUPERCEDE;
            } 
        } 
    } 
    return 
FMRES_IGNORED 


public 
client_disconnect(id

    new 
iEnt g_iPlayerCamera[id
    if(
pev_valid(iEnt)) 
    { 
        
engfunc(EngFunc_RemoveEntityiEnt
    }
    
    
g_iPlayerCamera[id] = 
}

public 
get_cam_owner(iEnt

    static 
id 
    
for(id 1id<=g_iMaxPlayersid++) 
    { 
        if(
g_iPlayerCamera[id] == iEnt
        { 
            return 
id 
        

    } 
    return 



public 
Camera_Think(iEnt

    static 
id 
    
if(!(id get_cam_owner(iEnt))) 
    { 
        return 
    } 
    
    static 
Float:fVecPlayerOrigin[3], Float:fVecCameraOrigin[3], Float:fVecAngles[3],  
    
Float:fVecForward[3], Float:fVecRight[3], Float:fVecUp[3]
    
    static 
iOrigin[3];
    
get_user_origin(idiOrigin1);
    
IVecFVec(iOriginfVecPlayerOrigin);
    
pev(idpev_v_anglefVecAngles
    
    
angle_vector(fVecAnglesANGLEVECTOR_FORWARDfVecForward
    
angle_vector(fVecAnglesANGLEVECTOR_RIGHTfVecRight
    
angle_vector(fVecAnglesANGLEVECTOR_UPfVecUp
    
    
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + fVecForward[0] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[0] * get_pcvar_float(CAMERA_RIGHT);
    
fVecCameraOrigin[1] = fVecPlayerOrigin[1] + fVecForward[1] * get_pcvar_float(CAMERA_FORWARD) + fVecRight[1] * get_pcvar_float(CAMERA_RIGHT); 
    
fVecCameraOrigin[2] = fVecPlayerOrigin[2] + fVecUp[2] * get_pcvar_float(CAMERA_UP) ;
    
    
engfunc(EngFunc_TraceLinefVecPlayerOriginfVecCameraOriginDONT_IGNORE_MONSTERSid0
    
    static 
Float:flFraction 
    get_tr2
(0TR_flFractionflFraction
    if(
flFraction != 1.0// adjust camera place if close to a wall 
    

        
flFraction *= get_pcvar_float(CAMERA_FRACTION)
        
        
fVecCameraOrigin[0] = fVecPlayerOrigin[0] + (fVecForward[0] * flFraction);
        
fVecCameraOrigin[1] = fVecPlayerOrigin[1] + (fVecForward[1] * flFraction)
        
fVecCameraOrigin[2] = fVecPlayerOrigin[2] + (fVecForward[2] * flFraction
    } 
    
    
set_pev(iEntpev_originfVecCameraOrigin)
    
    static 
Float:fEntityEndPosition[3];
    
    
getAimEndPosition(idfEntityEndPosition)
    
lookAtOrigin(iEntfEntityEndPosition)
    
    
beam_bet_2origin(fVecPlayerOriginfEntityEndPosition);
}

beam_bet_2origin(Float:fOrigin1[3], Float:fOrigin2[3])
{
    
message_begin(MSG_ALLSVC_TEMPENTITY_0)
    
write_byte(TE_BEAMPOINTS)
    
engfunc(EngFunc_WriteCoordfOrigin1[0])
    
engfunc(EngFunc_WriteCoordfOrigin1[1])
    
engfunc(EngFunc_WriteCoordfOrigin1[2])
    
engfunc(EngFunc_WriteCoordfOrigin2[0])
    
engfunc(EngFunc_WriteCoordfOrigin2[1])
    
engfunc(EngFunc_WriteCoordfOrigin2[2])
    
write_short(sprite_index
    
write_byte(0
    
write_byte(10
    
write_byte(1
    
write_byte(5
    
write_byte(1
    
write_byte(0)
    
write_byte(255)
    
write_byte(0)
    
write_byte(255)
    
write_byte(1)
    
message_end()
}

getAimEndPosition(idFloat:fOrigin[3]) 
{
    static 
Float:fStart[3], Float:fDest[3], tr2;
    
pev(idpev_originfStart);
    
pev(idpev_view_ofsfDest);
    
xs_vec_add(fStartfDestfStart);   

    
pev(idpev_v_anglefDest)
    
angle_vector(fDestANGLEVECTOR_FORWARDfDest);
    
xs_vec_mul_scalar(fDest4000.0fDest);
    
    
tr2 create_tr2();
    
engfunc(EngFunc_TraceLinefStartfDestIGNORE_MONSTERSidtr2);
    
get_tr2(tr2TR_vecEndPosfOrigin);
    
free_tr2(tr2);


lookAtOrigin(const id, const Float:fOrigin_dest[3])
{
    static 
Float:fOrigin[3]
    
pev(idpev_originfOrigin)
    
    if( 
<= id && id <= 32 )
    {
        static 
Float:fVec[3];
    
pev(idpev_view_ofsfVec);
    
xs_vec_add(fOriginfVecfOrigin);
    }
    
    static 
Float:fLook[3], Float:fLen;
    
xs_vec_sub(fOrigin_destfOriginfOrigin
    
fLen xs_vec_len(fOrigin);
    
    
fOrigin[0] /= fLen;
    
fOrigin[1] /= fLen;
    
fOrigin[2] /= fLen;
    
    
vector_to_angle(fOriginfLook)
    
    
fLook[0] *= -1;
    
    
set_pev(idpev_anglesfLook);
    
set_pev(idpev_fixangle1);


just the bullets decals are invalid but the traceattacks are quite right you need to redirect the bullets hole decals, i failed to do it since the decals are client side but u can block them and make new ones but im not sure how.

EFFx 04-06-2019 21:04

Re: How can I do that...?
 
Nah, it isn't just the bullet decals. When I'd shoot a player right at him it doesn't hit. You're only creating the beam between the camera view to the end position, but it is not the same aiment of the player's. Also, the pev_fixangle makes the camera weird so many times.

I think I just need a code that makes the camera follow the player's aim end position, so doesn't matter which position I set it, it'll still follow exactly where i'm aimint at.

Natsheh 04-06-2019 23:29

Re: How can I do that...?
 
In getAimEndPosition replace the trace flag with DONT_IGNORE_MONSTERS See if this solve the problem.

Also in camera think replace get_user_origin with with pev_origin then add to the origin player view of...


But I can assure that the camera aims where at the players aiming the problem' just with the bullet decals.

EFFx 04-07-2019 07:08

Re: How can I do that...?
 
The camera moves automatically due the pev_fixangle, so I need to fix where i'm aiming at everytime. Like, if i'm aiming close to an enemy and he starts going to my crosshair, the camera instantly changes the angle to the enemy. Looks like an aimbot.

Anyway, I tested and it actually just make the bullet decals wrong, but the shoots goes right. I've blocked the bullet decal but it stills making the sparkles which I've removed with FM_UpdateClientData, but looks like I'll need to recreate all weapon's sound animations.

thEsp 04-27-2019 17:21

Re: How can I do that...?
 
Quote:

Originally Posted by EFFx (Post 2646652)
The camera moves automatically due the pev_fixangle, so I need to fix where i'm aiming at everytime. Like, if i'm aiming close to an enemy and he starts going to my crosshair, the camera instantly changes the angle to the enemy. Looks like an aimbot.

Anyway, I tested and it actually just make the bullet decals wrong, but the shoots goes right. I've blocked the bullet decal but it stills making the sparkles which I've removed with FM_UpdateClientData, but looks like I'll need to recreate all weapon's sound animations.

Could you please show the code you used to block bullet decals and other properties (sounds,animation) :) ?


All times are GMT -4. The time now is 10:41.

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