Raised This Month: $12 Target: $400
 3% 

Entity moving in front of player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 08-22-2021 , 23:51   Entity moving in front of player
Reply With Quote #1

I am trying to make a entity that move in front of player with Z-cord always on the ground.
This is I got so far. But there are few problem:
- I could use drop_to_floor but idk if calling it every 0.1s is too much for the server to handle.
- If player aim to the group, the entity might just fall into the void
- If put specific Z first (like +100.0 up) then drop to the ground, it might stuck into a wall or object.

PHP Code:
public Item_think(ent)
{
    static 
owner;owner pev(entpev_owner)
    static 
Float:StartPos[3];
    
get_position(id100.00.00.0StartPos); //100.0 just for testing, might be smaller

    
set_pev(entpev_nextthinkget_gametime()+0.1)
}

stock get_position(id,Float:forwFloat:rightFloat:upFloat:vStart[])
{
    static 
Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    
    
pev(idpev_originvOrigin)
    
pev(idpev_view_ofsvUp//for player
    
xs_vec_add(vOriginvUpvOrigin)
    
pev(idpev_v_anglevAngle// if normal entity ,use pev_angles
    
    
angle_vector(vAngle,ANGLEVECTOR_FORWARDvForward//or use EngFunc_AngleVectors
    
angle_vector(vAngle,ANGLEVECTOR_RIGHTvRight)
    
angle_vector(vAngle,ANGLEVECTOR_UPvUp)
    
    
vStart[0] = vOrigin[0] + vForward[0] * forw vRight[0] * right vUp[0] * up
    vStart
[1] = vOrigin[1] + vForward[1] * forw vRight[1] * right vUp[1] * up
    vStart
[2] = vOrigin[2] + vForward[2] * forw vRight[2] * right vUp[2] * up

__________________
My plugin:

Last edited by Celena Luna; 08-23-2021 at 00:47.
Celena Luna is offline
DeMNiX
Veteran Member
Join Date: Nov 2011
Location: Russia
Old 08-23-2021 , 01:50   Re: Entity moving in front of player
Reply With Quote #2

Code:
    new Float:flOrigin[3], Float:flAngles[3], Float:flVec[3];

    get_entvar(id, var_origin, flOrigin);
    get_entvar(id, var_v_angle, flAngles);

    angle_vector(flAngles, ANGLEVECTOR_FORWARD, flVec);

    flOrigin[0] += flVec[0] * flDistance;
    flOrigin[1] += flVec[1] * flDistance;
    flOrigin[2] += flVec[2] * flDistance;

    set_entvar(iEntity, var_origin, flOrigin);
    get_entvar(id, var_angles, flAngles);
    flAngles[0] = 0.0;
    set_entvar(iEntity, var_angles, flAngles);

    if (!engfunc(EngFunc_WalkMove, iEntity, 0.0, 0.0, WALKMOVE_NORMAL))
    {
        // cant place here
        rg_set_ent_render(iEntity, kRenderFxGlowShell, 200, 0, 0, kRenderTransAdd, 15);
    }
    else
    {
         // will automatically apply best position
         rg_set_ent_render(iEntity, kRenderFxGlowShell, 235, 224, 14, kRenderTransAdd, 15);
    }
__________________
My channel with test codes
https://www.youtube.com/user/demnix03

Zombie Riot [Scenario & bots-zombie 11.11.2023]
https://youtu.be/8ZZan-aq2sc
DeMNiX is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-23-2021 , 05:06   Re: Entity moving in front of player
Reply With Quote #3

Here this should be more reliable !

PHP Code:
stock shift_entity_position(entFloat:forwFloat:rightFloat:up)
{
    static 
Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vEnd[3];
    
    
pev(entpev_originvOrigin);
    
pev(entpev_anglesvAngle);
    
    
angle_vector(vAngle,ANGLEVECTOR_FORWARDvForward); //or use EngFunc_AngleVectors
    
angle_vector(vAngle,ANGLEVECTOR_RIGHTvRight);
    
    
vEnd[0] = vOrigin[0] + (vForward[0] * forw) + (vRight[0] * right);
    
vEnd[1] = vOrigin[1] + (vForward[1] * forw) + (vRight[1] * right);
    
vEnd[2] = vOrigin[2] + up;

    static 
iTr2iTr2 create_tr2();
    
engfunc(EngFunc_TraceLinevOriginvEndDONT_IGNORE_MONSTERSentiTr2);
    
get_tr2(iTr2TR_vecEndPosvEnd);
    
free_tr2(iTr2);

    
set_pev(entpev_originvEnd);
}

public 
Item_think(ent)
{
    static 
ownerFloat:fStartPos[3], Float:fvOFS[3], Float:fAngles[3];
    
owner pev(entpev_owner);
    
    
// How to use ?
    
pev(ownerpev_originfStartPos);
    
pev(ownerpev_view_ofsfvOFS);
    
pev(ownerpev_v_anglefAngles);
    
Float:fAngles[0] = 0.0;
    
fStartPos[2] += fvOFS[2];
    
set_pev(entpev_originfStartPos);
    
set_pev(entpev_anglesfAngles);
    
shift_entity_position(ent100.00.00.0); //100.0 just for testing, might be smaller

    
set_pev(entpev_nextthinkget_gametime()+0.1);

can you confirm this works?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-23-2021 at 10:15.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-23-2021 , 09:50   Re: Entity moving in front of player
Reply With Quote #4

Trace a line down from the player current origin and you'll get the "on ground" position.

Code:
new Float:start[3], Float:end[3]
pev(id, pev_origin, start)
end[0] = start[0]
end[1] = start[1]
end[2] = start[2] - 8192.0

// with IGNORE_MONSTERS, the trace will ignore players
// you may want to replace with DONT_IGNORE_MONSTERS
engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, id, 0)

new Float:fraction
get_tr2(0, TR_flFraction, fraction)

if (fraction != 1.0)
	get_tr2(0, TR_vecEndPos, end)


// end[] is now the position on ground
// do something...
And to get the origin in front of the player:

Code:
new Float:start[3], Float:viewOfs[3]

pev(id, pev_origin, start)
pev(id, pev_view_ofs, viewOfs)
start[0] += viewOfs[0]
start[1] += viewOfs[1]
start[2] += viewOfs[2]

new Float:velocity[3], Float:end[3]

// replace 250 with the desired distance
velocity_by_aim(id, 250, velocity)

end[0] = start[0] + velocity[0]
end[1] = start[1] + velocity[1]
end[2] = start[2] + velocity[2]

engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, id, 0)

new Float:fraction
get_tr2(0, TR_flFraction, fraction)

if (fraction != 1.0)
	get_tr2(0, TR_vecEndPos, end)

// end[] is now the position in front of the player
// do something...
In both cases the entity may end up getting stuck. If that happens, get TR_vecPlaneNormal, multiply by scalar X, where X is an arbitrary given value, you'll have to test to determine what's the proper value, start with 15.0, then add the result to end[].
__________________









Last edited by CrazY.; 08-23-2021 at 10:05.
CrazY. is offline
Celena Luna
Veteran Member
Join Date: Aug 2013
Location: Nagazora
Old 08-25-2021 , 04:01   Re: Entity moving in front of player
Reply With Quote #5

Thank you guys, sorry for late reply.
I can't actually test the code right now so I will post after I can test it.
__________________
My plugin:
Celena Luna is offline
NOVA GAMING
Member
Join Date: Apr 2020
Old 08-25-2021 , 08:21   Re: Entity moving in front of player
Reply With Quote #6

this is the Code i Used in my Old Plugin..

PHP Code:
if(pev_valid(ent)) 
    {
        
        new 
Float:vNewOrigin[3],Float:vNormal[3],Float:vTraceDirection[3], Float:vTraceEnd[3], Float:vOrigin[3]
        
        
pev(idpev_originvOrigin)
        
vOrigin[2]+=25
        
        velocity_by_aim
(id50vTraceDirection)
        
        
xs_vec_add(vTraceDirectionvOriginvTraceEnd)
        
        
engfunc(EngFunc_TraceLinevOriginvTraceEndDONT_IGNORE_MONSTERSid0)
        
        
get_tr2(0TR_vecEndPosvTraceEnd)
        
        new 
Float:TrAc[3]
        
TrAc[0]=vTraceEnd[0]
        
TrAc[1]=vTraceEnd[1]
        
TrAc[2]=-1000.0
        engfunc
(EngFunc_TraceLinevTraceEndTrAcDONT_IGNORE_MONSTERSid0)
        
        new 
Float:fFraction
        get_tr2
(0TR_flFractionfFraction)
        if(
fFraction 1.0)
        {
            
            
get_tr2(0TR_vecEndPosvTraceEnd);
            
get_tr2(0TR_vecPlaneNormalvNormal);
            
            
        }
        
        
xs_vec_add(vTraceEndvNormalvNewOrigin)
        
set_pev(entpev_originvNewOrigin );
        
    } 
here is the Video ( No advertising ..)

__________________
NOVA GAMING 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 01:39.


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