Raised This Month: $ Target: $400
 0% 

Using velocity_by_aim() to Get Other Directions


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 08-05-2010 , 21:30   Re: Using velocity_by_aim() to Get Other Directions
Reply With Quote #6

Code:
static cell AMX_NATIVE_CALL VelocityByAim(AMX *amx, cell *params) {     int iEnt = params[1];     int iVelocity = params[2];     cell *vRet = get_amxaddr(amx, params[3]);     Vector vVector = Vector(0, 0, 0);     edict_t *pEnt = NULL;     if (iEnt < 0 || iEnt > gpGlobals->maxEntities)     {         LogError(amx, AMX_ERR_NATIVE, "Entity out of range (%d)", iEnt);         return 0;     }     else     {         if (iEnt > 0 && iEnt <= gpGlobals->maxClients)         {             if (!GET_PLAYER_POINTER_I(iEnt)->ingame)             {                 LogError(amx, AMX_ERR_NATIVE, "Invalid player %d (not ingame)", iEnt);                 return 0;             }             pEnt = GET_PLAYER_POINTER_I(iEnt)->pEdict;         } else {             pEnt = INDEXENT(iEnt);         }     }     if (!pEnt)     {         LogError(amx, AMX_ERR_NATIVE, "Invalid entity %d (nullent)", iEnt);         return 0;     }     MAKE_VECTORS(pEnt->v.v_angle);     vVector = gpGlobals->v_forward * iVelocity;     vRet[0] = FloatToCell(vVector.x);     vRet[1] = FloatToCell(vVector.y);     vRet[2] = FloatToCell(vVector.z);     return 1; }

I tried to do a modified version which supports these directions:

PHP Code:
#include <engine>
#include <fakemeta>
#include <xs>

enum Direction
{
    
DIRECTION_UP 0,
    
DIRECTION_RIGHT,
    
DIRECTION_FORWARD,
    
DIRECTION_DOWN,
    
DIRECTION_LEFT,
    
DIRECTION_BACKWARD
}

stock velocity_by_direction(iEntDirection:iWhere DIRECTION_FORWARD /* the default one */Float:flVelocityFloat:flRetVector[3])
{
    new 
Float:flBuffer[3]
    
entity_get_vector(iEntEV_VEC_v_angleflBuffer)
    
engfunc(EngFunc_MakeVectorsflBuffer)
    
    switch(
iWhere)
    {
        case 
DIRECTION_UPDIRECTION_DOWNget_global_vector(GL_v_upflBuffer)
        case 
DIRECTION_RIGHTDIRECTION_LEFTget_global_vector(GL_v_rightflBuffer)
        case 
DIRECTION_FORWARDDIRECTION_BACKWARDget_global_vector(GL_v_forwardflBuffer)
    }
    
    
xs_vec_mul_scalar(flBuffer_:iWhere <= flVelocity : -flVelocityflBuffer)
    
xs_vec_copy(flBufferflRetVector)

    return 
1

__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
 



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 00:18.


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