AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   CS 1.6 Custom 3rd Person View (https://forums.alliedmods.net/showthread.php?t=65427)

OneEyed 01-08-2008 07:04

CS 1.6 Custom 3rd Person View
 
1 Attachment(s)
Hey guys, I was messing around and made my own 3rd person camera. This camera has several different things compared with using set_view from engine module.

Differences:
- Precision where your aiming is better.
- Your model isn't alpha'd.
- Your model stutters a bit with this method.
- Doesn't require rocket.mdl (uses a weapon file from mod thats already precached)

Heres the code using ENGINE module. It can be converted to FAKEMETA tho.

Code:
//Call this wherever you want. Create_PlayerCamera( id ) {     new entid;     while( (entid = find_ent_by_class(entid, "PlayerCamera")) != 0)         if( entity_get_edict( entid, EV_ENT_owner ) == id )         {             attach_view( id, entid );             return;         }             entid = create_entity("info_target");             if(entid)     {         entity_set_string(entid,EV_SZ_classname,"PlayerCamera");         entity_set_model(entid,"models/w_usp.mdl");         entity_set_int( entid, EV_INT_solid, SOLID_TRIGGER);         entity_set_int( entid, EV_INT_movetype, MOVETYPE_FLY );                  //Set owner         entity_set_edict( entid, EV_ENT_owner, id );         //Don't draw         entity_set_int( entid, EV_INT_rendermode, kRenderTransTexture);         entity_set_float( entid, EV_FL_renderamt, 0.0);         //Attach our view to this entity.         attach_view( id, entid );         //Think!         entity_set_float( entid, EV_FL_nextthink, get_gametime() );     }    } //Requires registering a Think method for "PlayerCamera" entity. // OR you could save the camera's entity ID in the function above // and call this in client_PostThink or wherever that gets called alot. public Think_PlayerCamera( entid ) {     new id = entity_get_edict( entid, EV_ENT_owner );         //Kill our entity if we hit USE key     new buttons = entity_get_int( id, EV_INT_button );     if(buttons & IN_USE)     {         attach_view( id, id );         remove_entity(entid);         return;     }     new Float:origin[3], Float:angle[3], Float:vBack[3];     entity_get_vector( id, EV_VEC_origin, origin );     entity_get_vector( id, EV_VEC_v_angle, angle );     angle_vector( angle, ANGLEVECTOR_FORWARD, vBack );     origin[2] += 20.0; //So we're closer to the eyes.         //Move back to see ourself (150 units)     origin[0] += (-vBack[0] * 150.0);     origin[1] += (-vBack[1] * 150.0);     origin[2] += (-vBack[2] * 150.0);     entity_set_origin( entid, origin );     entity_set_vector( entid, EV_VEC_angles, angle );            //For thinking only     entity_set_float( entid, EV_FL_nextthink, get_gametime() ); }

That's it. You can change how the player can turn this off if you don't want to use my USE key method, just copy attach_view( id, id ); and remove_entity(entid); where you want to do it.

Here's a screenshot:

Alka 01-08-2008 07:53

Re: CS 1.6 Custom 3rd Person View
 
wow, this is so cool, and with fakemeta, this will be awesome. Good Job OneEyed. :wink:

Arkshine 01-08-2008 12:53

Re: CS 1.6 Custom 3rd Person View
 
Fakemeta way.

Code:
    #include <amxmodx>     #include <fakemeta>     new const g_sCamclass[] = "PlayerCamera";     public plugin_init()     {         register_clcmd( "say /cam", "cmdCam" );         register_forward( FM_Think, "Think_PlayerCamera" );     }     public cmdCam( id )         Create_PlayerCamera( id );     Create_PlayerCamera( id )     {         new iEnt; static const sClassname[] = "classname";         while( ( iEnt = engfunc( EngFunc_FindEntityByString, iEnt, sClassname, g_sCamclass ) ) != 0 )         {             if( pev( iEnt, pev_owner) == id )             {                 engfunc( EngFunc_SetView, id, iEnt );                 return;             }         }         static const sInfo_target[] = "info_target";         iEnt = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, sInfo_target ) )         if( !iEnt )             return;                 static const sCam_model[] = "models/w_usp.mdl";         set_pev( iEnt, pev_classname, g_sCamclass );         engfunc( EngFunc_SetModel, iEnt, sCam_model );         set_pev( iEnt, pev_solid, SOLID_TRIGGER );         set_pev( iEnt, pev_movetype, MOVETYPE_FLY );         set_pev( iEnt, pev_owner, id );         set_pev( iEnt, pev_rendermode, kRenderTransTexture );         set_pev( iEnt, pev_renderamt, 0.0 );         engfunc( EngFunc_SetView, id, iEnt );         set_pev( iEnt, pev_nextthink, get_gametime() );     }     public Think_PlayerCamera( iEnt )     {         static sClassname[32];         pev( iEnt, pev_classname, sClassname, sizeof sClassname - 1 );         if( !equal( sClassname, g_sCamclass ) )             return FMRES_IGNORED;         static iOwner;         iOwner = pev( iEnt, pev_owner );         if( !is_user_alive( iOwner ) )             return FMRES_IGNORED;         static iButtons;         iButtons = pev( iOwner, pev_button );         if( iButtons & IN_USE )         {             engfunc( EngFunc_SetView, iOwner, iOwner );             engfunc( EngFunc_RemoveEntity, iEnt );             return FMRES_IGNORED;         }         static Float:fOrigin[3], Float:fAngle[3];         pev( iOwner, pev_origin, fOrigin );         pev( iOwner, pev_v_angle, fAngle );         static Float:fVBack[3];         angle_vector( fAngle, ANGLEVECTOR_FORWARD, fVBack );         fOrigin[2] += 20.0;         fOrigin[0] += ( -fVBack[0] * 150.0 );         fOrigin[1] += ( -fVBack[1] * 150.0 );         fOrigin[2] += ( -fVBack[2] * 150.0 );         engfunc( EngFunc_SetOrigin, iEnt, fOrigin );         set_pev( iEnt, pev_angles, fAngle );         set_pev( iEnt, pev_nextthink, get_gametime() );         return FMRES_HANDLED;     }

XxAvalanchexX 01-08-2008 14:36

Re: CS 1.6 Custom 3rd Person View
 
I'm jealous that you were able to get attach_view to work. Good job!

mut2nt 09-24-2008 15:35

Re: CS 1.6 Custom 3rd Person View
 
and how can i set it to normal?

Emp` 09-24-2008 15:38

Re: CS 1.6 Custom 3rd Person View
 
engine:
Code:

        attach_view( id, id );
        remove_entity(entid);

fakemeta:
Code:

            engfunc( EngFunc_SetView, iOwner, iOwner );
            engfunc( EngFunc_RemoveEntity, iEnt );


mut2nt 09-24-2008 15:46

Re: CS 1.6 Custom 3rd Person View
 
i get it :*! 10x!

niFe 02-12-2009 01:04

Re: CS 1.6 Custom 3rd Person View
 
ohhh yes oneEyed!! :D

ot_207 04-17-2009 11:47

Re: CS 1.6 Custom 3rd Person View
 
Here is my method, improved some things :), the model doesn't shake anymore.

PHP Code:

#include <amxmodx>
#include <engine>

new const pl_cm_class[] = "PlayerCamera"

public plugin_init()
{
    
register_clcmd"say /cam""cmdCam" )
    
register_think(pl_cm_class,"Think_PlayerCamera")
}

public 
cmdCam(id)
    
Create_PlayerCamera(id)

Create_PlayerCamera(id)
{
    new 
ent = -1
    
while ((ent find_ent_by_class(ent,pl_cm_class)) != 0)
    {
        if (
entity_get_edict(ent,EV_ENT_owner) == id)
        {
            
attach_view(id ent)
            return
        }
    }
    
ent create_entity("info_target")
    
    if( !
ent )
        return;
    
    
entity_set_string(entEV_SZ_classnamepl_cm_class)
    
    
entity_set_model(ent"models/w_usp.mdl")
    
    
entity_set_byte(entEV_INT_solidSOLID_TRIGGER)
    
entity_set_int(entEV_INT_movetypeMOVETYPE_FLYMISSILE)
    
    
entity_set_edict(entEV_ENT_ownerid)
    
    
entity_set_int(ent,EV_INT_rendermodekRenderTransTexture)
    
entity_set_float(entEV_FL_renderamt0.0 )
    
    
attach_view(id,ent)
    
entity_set_float(entEV_FL_nextthinkget_gametime())
}

public 
Think_PlayerCamera(ent)
{
    static 
owner
    owner 
entity_get_edict(ent,EV_ENT_owner)
    
    static 
iButtons;
    
iButtons entity_get_int(ownerEV_INT_button)
    
    if( 
iButtons IN_USE  || !is_user_alive(owner))
    {
        
attach_view(owner,owner)
        
remove_entity(ent)
        return 
PLUGIN_CONTINUE;
    }
    
    
    static 
Float:origin[3], Float:fAngle[3],Float:origin2[3];
    
entity_get_vector(owner,EV_VEC_origin,origin)
    
entity_get_vector(owner,EV_VEC_v_angle,fAngle)
    
    
origin2[0] = origin[0]
    
origin2[1] = origin[1]
    
origin2[2] = origin[2]
    
    static 
Float:fVBack[3];
    
angle_vectorfAngleANGLEVECTOR_FORWARDfVBack );
    
    
origin[2] += 20.0;
    
    
origin[0] += ( -fVBack[0] * 150.0 );
    
origin[1] += ( -fVBack[1] * 150.0 );
    
origin[2] += ( -fVBack[2] * 150.0 );
    
    
trace_line(owner,origin2,origin,origin)
    
    
entity_set_vector(ent,EV_VEC_origin,origin)
    
    
entity_get_vector(owner,EV_VEC_velocity,origin2)
    
entity_set_vector(ent,EV_VEC_velocity,origin2)
    
    
entity_set_vector(ent,EV_VEC_angles,fAngle)
    
entity_set_float(entEV_FL_nextthinkget_gametime())
    
    return 
PLUGIN_CONTINUE;



Emp` 04-17-2009 14:39

Re: CS 1.6 Custom 3rd Person View
 
Quote:

Originally Posted by ot_207 (Post 807584)
Here is my method, improved some things :), the model doesn't shake anymore.

Is there a reason for changing MOVETYPE_FLY to MOVETYPE_FLYMISSILE?


All times are GMT -4. The time now is 18:27.

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