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

Fix attach_view issue please


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SVC
Junior Member
Join Date: Mar 2021
Old 09-04-2022 , 18:44   Fix attach_view issue please
Reply With Quote #1

Hi, can someboy help me with the next code:

PHP Code:
#include    AMXMODX
#include    ENGINE

new bool:g_bInvertYaw;

public 
plugin_init()
{
    
register_clcmd("__weapon__""__give_weapon__");
    
register_clcmd("invert_angle""invert_angle");
}

public 
invert_angle() g_bInvertYaw = !g_bInvertYaw;

public 
__give_weapon__(const iPlayer)
{
    
// It's only for testing purpose; code can be improved a lot, I know :)...
    
    
new Float:fCoords[3];
    
entity_get_vector(iPlayerEV_VEC_originfCoords);
    
    
fCoords[2] += 35.0;
    
    new 
iWeapon create_entity("info_target");
    {
        
entity_set_origin(iWeaponfCoords);
        
entity_set_model(iWeapon"models/v_ak47.mdl");
        
        
entity_set_string(iWeaponEV_SZ_classname"__custom_weapon__");
        
entity_set_edict(iWeaponEV_ENT_owneriPlayer);
        
entity_set_float(iWeaponEV_FL_nextthink0.001);
    
set_rendering(iWeaponkRenderFxGlowShell2550255kRenderNormal5);
    
        
// I think doesn't necessary explain what it does..
        
attach_view(iPlayeriWeapon);
        
        
register_think("__custom_weapon__""__think_custom_weapon__");
    }
}

public 
__think_custom_weapon__(const iEnt)
{
    new 
iOwner entity_get_edict(iEntEV_ENT_owner);

    static 
Float:fCoords[3];
    
entity_get_vector(iOwnerEV_VEC_originfCoords);

    
entity_set_origin(iEntfCoords);
    
    
/*
    Here I set custom-weapon's angles to the player's view-angles
    However even if I reverse they (more precisely the yaw-angle), the up/down view will be reverse "again"
    
    I can't explain better this, so when you test code you will see what i've saying
    */
    
    
static Float:fViewAngles[3];
    
entity_get_vector(iOwnerEV_VEC_v_anglefViewAngles);
    
    
// What I'm doing here is reverse the up/down angle (for testing) but doesn't not have effect
    
if (g_bInvertYaw)
        
fViewAngles[0] = -fViewAngles[0];
    
    
entity_set_vector(iEntEV_VEC_anglesfViewAngles);
    
entity_set_float(iEntEV_FL_nextthink0.001);

What I was looking for is trying to make a "fake-weapon" for testing purpouse, but I've a problem with weapon-angles

Sorry for my bad english, I really hope somebody helpme with this
SVC is offline
zXCaptainXz
Member
Join Date: May 2017
Old 09-05-2022 , 13:30   Re: Fix attach_view issue please
Reply With Quote #2

I apologize in advance for the spaghetti code but I really couldn't think of any other way to accomplish your goal... I created a duplicate entity, made it invisible, and made the attach_view follow that entity instead, so I inverted the yaw for the real entity and kept it the same for the invisible one...

PHP Code:
#include    AMXMODX
#include    ENGINE

new bool:g_bInvertYaw;

public 
plugin_init()
{
    
register_clcmd("__weapon__""__give_weapon__");
    
register_clcmd("invert_angle""invert_angle");
}

public 
invert_angle() g_bInvertYaw = !g_bInvertYaw;

public 
__give_weapon__(const iPlayer)
{
    
// It's only for testing purpose; code can be improved a lot, I know :)...
    
    
new Float:fCoords[3];
    
entity_get_vector(iPlayerEV_VEC_originfCoords);
    
    
fCoords[2] += 35.0;
    
    new 
iWeapon create_entity("info_target");
    {
        
entity_set_origin(iWeaponfCoords);
        
entity_set_model(iWeapon"models/v_ak47.mdl");
        
        
entity_set_string(iWeaponEV_SZ_classname"__custom_weapon__");
        
entity_set_edict(iWeaponEV_ENT_owneriPlayer);
        
entity_set_float(iWeaponEV_FL_nextthink0.001);
        
set_rendering(iWeaponkRenderFxGlowShell2550255kRenderNormal5);
        
        
register_think("__custom_weapon__""__think_custom_weapon__");
        
        new 
iWeapon2 create_entity("info_target"
        
entity_set_model(iWeapon2"models/v_ak47.mdl");
        
entity_set_origin(iWeapon2fCoords);        
        
        
entity_set_int(iWeapon2EV_INT_rendermodekRenderTransAlpha)
        
entity_set_int(iWeapon2EV_FL_renderamt0)

        
attach_view(iPlayeriWeapon2);

        
        
entity_set_int(iWeaponEV_INT_iuser1iWeapon2);
    }
}

public 
__think_custom_weapon__(const iEnt)
{
    static 
iOwner 
    iOwner 
entity_get_edict(iEntEV_ENT_owner);
    static 
iEnt2 
    iEnt2 
entity_get_int(iEntEV_INT_iuser1);
    static 
Float:fCoords[3];
    
entity_get_vector(iOwnerEV_VEC_originfCoords);

    
entity_set_origin(iEntfCoords);
    
entity_set_origin(iEnt2fCoords);
        
    static 
Float:fViewAngles[3];
    
entity_get_vector(iOwnerEV_VEC_v_anglefViewAngles);
    
    
    
entity_set_vector(iEnt2EV_VEC_anglesfViewAngles);
    
    
fViewAngles[0] = -fViewAngles[0];
    
entity_set_vector(iEntEV_VEC_anglesfViewAngles);

    
entity_set_float(iEntEV_FL_nextthink0.001);

zXCaptainXz is offline
SVC
Junior Member
Join Date: Mar 2021
Old 09-06-2022 , 10:21   Re: Fix attach_view issue please
Reply With Quote #3

Hi!.

Yeah, that fix is good. Even before i made above code i've think on that fix. But, originally i was trying to using the less entities possible.

And there is one issue with that: angles-view problem stills on, but now from the perspective of around players. I mean, if I have a custom-weapon and you see me, when i face up you will see the weapon on my hands go down and vice versa

I expected somebody have knowledge dealing with this. Anyway, thanks a lot man for you help man.
SVC is offline
zXCaptainXz
Member
Join Date: May 2017
Old 09-06-2022 , 14:52   Re: Fix attach_view issue please
Reply With Quote #4

Quote:
Originally Posted by SVC View Post
Hi!.

Yeah, that fix is good. Even before i made above code i've think on that fix. But, originally i was trying to using the less entities possible.

And there is one issue with that: angles-view problem stills on, but now from the perspective of around players. I mean, if I have a custom-weapon and you see me, when i face up you will see the weapon on my hands go down and vice versa

I expected somebody have knowledge dealing with this. Anyway, thanks a lot man for you help man.
This can be solved using AddToFullPack and editing the yaw from there for the owner only then instead of creating a new entity, let me know if you need help using that function.
zXCaptainXz is offline
SVC
Junior Member
Join Date: Mar 2021
Old 09-06-2022 , 15:47   Re: Fix attach_view issue please
Reply With Quote #5

Can you give me an example?

I remember i've done some similar thing with AddToFullPack but problem persists. Or maybe what you say is another way?.

One last thing I think i can do, is hide model from 3rd players but not for Owner, and still using weapon "playermodel" model.

In the end, if this works or not, doesn't matter for me, I just wanna test
SVC is offline
zXCaptainXz
Member
Join Date: May 2017
Old 09-06-2022 , 16:32   Re: Fix attach_view issue please
Reply With Quote #6

Apparently attach_view was still stubborn even when it comes to AddToFullPack, I wrote a hybrid solution between the two, so I created 2 entities, and only inverted the angle for the owner in AddToFullPack. This method is very sketchy I know, but until someone comes up with a better one I guess you're stuck with this for now :/

PHP Code:
#include    AMXMODX
#include    ENGINE
#include    FAKEMETA

public plugin_init()
{
    
register_clcmd("__weapon__""__give_weapon__");
    
register_forward(FM_AddToFullPack"fw_addtofullpack"1)
}

public 
fw_addtofullpack(es_handle,e,ent,host,hostflags,player,pSet)
{
    if(
player) return FMRES_IGNORED;      
    if(!
pev_valid(ent)) return FMRES_IGNORED;
    new 
classname[32]
    
pev(ent,pev_classname,classname,31)
    if(!
equali(classname,"__custom_weapon__")) return FMRES_IGNORED   

    
if(pev(entpev_owner)!=host) return FMRES_IGNORED
    
static Float:fViewAngles[3];
    
get_es(es_handleES_AnglesfViewAngles);
    
fViewAngles[0] = -fViewAngles[0]
    
set_es(es_handleES_AnglesfViewAngles);
    return 
FMRES_IGNORED;
}

public 
__give_weapon__(const iPlayer)
{
    new 
Float:fCoords[3];
    
entity_get_vector(iPlayerEV_VEC_originfCoords);
    
    
fCoords[2] += 35.0;
    
    new 
iWeapon create_entity("info_target");
    {
        
entity_set_origin(iWeaponfCoords);
        
entity_set_model(iWeapon"models/v_ak47.mdl");
        
        
entity_set_string(iWeaponEV_SZ_classname"__custom_weapon__");
        
entity_set_edict(iWeaponEV_ENT_owneriPlayer);
        
entity_set_float(iWeaponEV_FL_nextthink0.001);
        
set_rendering(iWeaponkRenderFxGlowShell2550255kRenderNormal5);
        
        
register_think("__custom_weapon__""__think_custom_weapon__");
        
        new 
iWeapon2 create_entity("info_target"
        
entity_set_model(iWeapon2"models/v_ak47.mdl");
        
entity_set_origin(iWeapon2fCoords);        
        
        
entity_set_int(iWeapon2EV_INT_rendermodekRenderTransAlpha)
        
entity_set_int(iWeapon2EV_FL_renderamt0)

        
attach_view(iPlayeriWeapon2);

        
        
entity_set_int(iWeaponEV_INT_iuser1iWeapon2);
    }
}

public 
__think_custom_weapon__(const iEnt)
{
    static 
iOwner 
    iOwner 
entity_get_edict(iEntEV_ENT_owner);
    static 
iEnt2 
    iEnt2 
entity_get_int(iEntEV_INT_iuser1);
    static 
Float:fCoords[3];
    
entity_get_vector(iOwnerEV_VEC_originfCoords);

    
entity_set_origin(iEntfCoords);
    
entity_set_origin(iEnt2fCoords);
        
    static 
Float:fViewAngles[3];
    
entity_get_vector(iOwnerEV_VEC_v_anglefViewAngles);
    
    
    
entity_set_vector(iEnt2EV_VEC_anglesfViewAngles);
    
    
entity_set_vector(iEntEV_VEC_anglesfViewAngles);

    
entity_set_float(iEntEV_FL_nextthink0.001);

zXCaptainXz is offline
SVC
Junior Member
Join Date: Mar 2021
Old 09-06-2022 , 17:08   Re: Fix attach_view issue please
Reply With Quote #7

I'm currently on work, but when i get home will test it.

Respect to AddToFullPack, i've 90% sure this is a problem from client-side view handlement. But unfortunately i don't have any open-source from where see how works.

Again, big thanks man, will test and tell you if works

PD: Well, seems it works good. Will test more days, if have any issues i'll post

Last edited by SVC; 09-07-2022 at 08:22.
SVC is offline
Reply


Thread Tools
Display Modes

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 04:31.


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