Raised This Month: $ Target: $400
 0% 

Model animating confusion


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-22-2010 , 07:47   Re: Model animating confusion
Reply With Quote #4

Here, two version, with and without orpheu. Of course, with the last one, you get a better result. ;)

For both, the light is not implemented, I don't think it's possible to use light or light_spot dynamically. Really, I don't know what to do. It's really too bad we can't make a light on the model. One half-solution to have light, is to have a map where such entities are already placed, then with a plugin you could trigger them.
( tested only for cs, orpheu signatures are for cs too )

Here a simple version without orpheu.

- There is a problem about the animation, it's played too fast, at least for the deploy one you see it clearly. I've tried to play with pev_framerate, it seems to not work for the deploy sequence, weird. Good luck if you want to fix that. ^^
- The real effect, it should have a small check to make sure the deploy and hide sequence are fully played. Here, no checks.

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

new const xenLightModel [] = "models/light.mdl";
new const 
xenLightModelT[] = "models/lightt.mdl";

new const 
xenLightGlowSprite[] = "sprites/flare3.spr";
new const 
xenPlantLightClassname[] = "xen_plant_light";

const 
FloatXenPlantHideTime 5.0;

enum /* Light model sequence */
{
    
LIGHT_IDLE 0,
    
LIGHT_RETRACT,
    
LIGHT_DEPLOY,
    
LIGHT_HIDE
};

const 
m_flFrameRate       36;
const 
m_fSequenceFinished 39;

#define pev_glow           pev_iuser1
#define pev_spotlight      pev_iuser2
#define pev_nextstandtime  pev_fuser1

public plugin_precache()
{
    
precache_modelxenLightModel );
    
precache_modelxenLightModelT );

    
precache_modelxenLightGlowSprite );
}

public 
plugin_init()
{
    
register_plugin"""""" );
    
register_clcmd"say light""ClientCommand_Light" );

    
register_thinkxenPlantLightClassname"CXenPLight_Think" );
    
register_touchxenPlantLightClassname"player""CXenPLight_Touch" );
}

public 
ClientCommand_Light( const client )
{
    new 
aimOrigin], Float:aimOrigin_f];

    
get_user_originclientaimOrigin);
    
IVecFVecaimOriginaimOrigin_f );

    
CXenPLight_SpawnaimOrigin_f );

    return 
PLUGIN_HANDLED;
}

CXenPLight_SpawnFloat:origin] )
{
    new 
light create_entity"info_target" );

    if( 
light )
    {
        
set_pevlightpev_classnamexenPlantLightClassname );

        
set_pevlightpev_movetypeMOVETYPE_NONE );
        
set_pevlightpev_solidSOLID_TRIGGER );

        
engfuncEngFunc_SetModellightxenLightModel );
        
engfuncEngFunc_SetSizelightFloat:{ -80.0, -80.00.0 }, Float:{ 80.080.032.0 } );
        
engfuncEngFunc_SetOriginlightorigin );

        
SetActivitylightLIGHT_IDLE );

        
set_pevlightpev_nextthinkget_gametime() + 0.1 );
        
set_pevlightpev_framerandom_num0255 ) );

        
set_pevlightpev_rendercolorFloat:{ 232.0189.021.0 } );
        
set_pevlightpev_renderamt210.0 );

        new 
Float:mins], Float:maxs];

        
pevlightpev_minsmins );
        
pevlightpev_maxsmaxs );

        
origin] += ( mins] + maxs] ) * 0.5;

        new 
glow CSprite_SpriteCreatexenLightGlowSpriteorigin );

        if( 
glow )
        {
            
set_pevlightpev_glowglow );

            
CSprite_SetTransparencyglowlightkRenderGlow );
            
CSprite_SetAttachmentglowlight);
        }
    }
}

public 
CXenPLight_Think( const light )
{
    
set_pevlightpev_nextthinkget_gametime() + 0.1 );

    switch( 
pevlightpev_sequence ) )
    {
        case 
LIGHT_RETRACT :
        {
            
SetActivitylightLIGHT_HIDE );
            
CXenPLight_LightOfflight );
        }
        case 
LIGHT_HIDE :
        {
            static 
Float:nextStandTime;
            
pevlightpev_nextstandtimenextStandTime );

            if( 
get_gametime() > nextStandTime )
            {
                
SetActivitylightLIGHT_DEPLOY );
                
CXenPLight_LightOnlight );
            }
        }
        case 
LIGHT_DEPLOY :
        {
            
SetActivitylightLIGHT_IDLE );
        }
    }
}

public 
CXenPLight_Touch( const light, const player )
{
    if( 
is_user_aliveplayer ) )
    {
        
set_pevlightpev_nextstandtimeget_gametime() + XenPlantHideTime );

        switch( 
pevlightpev_sequence ) )
        {
            case 
LIGHT_IDLELIGHT_DEPLOY : { SetActivitylightLIGHT_RETRACT ); }
        }
    }
}

CXenPLight_LightOn( const light )
{
    new 
glow pevlightpev_glow );
    
set_pevglowpev_effectspevglowpev_effects ) & ~EF_NODRAW );
}

CXenPLight_LightOff( const light )
{
    new 
glow pevlightpev_glow );
    
set_pevglowpev_effectspevglowpev_effects ) | EF_NODRAW );
}

CSprite_SpriteCreate( const spriteName[], const Float:origin] )
{
    new 
sprite create_entity"env_sprite" );

    if( 
sprite )
    {
        
set_pevspritepev_modelspriteName );
        
set_pevspritepev_originorigin );

        
DispatchSpawnsprite );

        
set_pevspritepev_solidSOLID_NOT );
        
set_pevspritepev_movetypeMOVETYPE_NOCLIP );
    }

    return 
sprite;
}

CSprite_SetTransparency( const sprite, const entity 0, const renderMode kRenderNormal, const Float:renderColor] = { 0.00.00.0 }, const renderAmt 0, const renderFx kRenderFxNone )
{
    if( 
entity )
    {
        new 
Float:renderColor], Float:renderAmt;

        
peventitypev_rendercolorrenderColor );
        
peventitypev_renderamtrenderAmt );

        
set_pevspritepev_rendermoderenderMode );
        
set_pevspritepev_rendercolorrenderColor );
        
set_pevspritepev_renderamtrenderAmt );
        
set_pevspritepev_renderfxpeventitypev_renderfx ) );
    }
    else
    {
        
set_pevspritepev_rendermoderenderMode );
        
set_pevspritepev_rendercolorrenderColor );
        
set_pevspritepev_renderamtrenderAmt );
        
set_pevspritepev_renderfxrenderFx );
    }
}

CSprite_SetAttachment( const sprite, const entity, const attachment )
{
    if( 
entity )
    {
        
set_pevspritepev_skinentity );
        
set_pevspritepev_bodyattachment );
        
set_pevspritepev_aimententity );
        
set_pevspritepev_movetypeMOVETYPE_FOLLOW );
    }
}

SetActivity( const entity, const activity )
{
    
set_peventitypev_sequenceactivity );
    
set_peventitypev_frame);

    
set_peventitypev_animtimeget_gametime() );
    
set_peventitypev_framerate1.0 );


The orpheu version. The code is almost the same. The difference is we call ResetSequenceInfo() to reset properly and StudioFrameAdvance(). Both are the same as you can find in the HLSDK. Anyway, you get a better visual result.

- The animations are handled perfectly.
- There are the checks to let the deploy/hide sequence be fully played.

EDIT : I've improved the orpheu version. Now, it will trigger the plant target if it exists. This way, if you have a map with some lights already placed, you can associate them so the light plant can trigger on/off the lights.

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <orpheu>

/* CAN BE CHANGED */

    
const FloatXenPlantHideTime 5.0;

/* CONSTANTS */

    
new const xenLightModel [] = "models/light.mdl";
    new const 
xenLightModelT[] = "models/lightt.mdl";

    new const 
xenLightGlowSprite[] = "sprites/flare3.spr";
    new const 
xenPlantLightClassname[] = "xen_plant_light";

    
enum /* Light model sequence */
    
{
        
LIGHT_IDLE 0,
        
LIGHT_RETRACT,
        
LIGHT_DEPLOY,
        
LIGHT_HIDE
    
};

    
enum /* USE_TYPE */
    
{
        
USE_OFF,
        
USE_ON,
    };

/* OFFSETS */

    
const m_flFrameRate       36;
    const 
m_fSequenceFinished 39;

/* MACROS */

    #define pev_glow           pev_iuser1
    #define pev_spotlight      pev_iuser2
    #define pev_nextstandtime  pev_fuser1
    
/* ORPHEU HANDLE */

    
new OrpheuFunction:handleFuncResetSequenceInfo;
    new 
OrpheuFunction:handleFuncStudioFrameAdvance;
    new 
OrpheuFunction:handleFuncSUB_UseTargets;

public 
plugin_precache()
{
    
precache_modelxenLightModel );
    
precache_modelxenLightModelT );

    
precache_modelxenLightGlowSprite );
}

public 
plugin_init()
{
    
register_plugin"""""" );
    
register_clcmd"say light""ClientCommand_Light" );

    
register_thinkxenPlantLightClassname"CXenPLight_Think" );
    
register_touchxenPlantLightClassname"player""CXenPLight_Touch" );

    
handleFuncResetSequenceInfo  OrpheuGetFunction"ResetSequenceInfo""CBaseAnimating" );
    
handleFuncStudioFrameAdvance OrpheuGetFunction"StudioFrameAdvance""CBaseAnimating" );
    
handleFuncSUB_UseTargets     OrpheuGetFunction"SUB_UseTargets""CBaseDelay" );
}

public 
ClientCommand_Light( const client )
{
    new 
aimOrigin], Float:aimOrigin_f];

    
get_user_originclientaimOrigin);
    
IVecFVecaimOriginaimOrigin_f );

    
CXenPLight_SpawnaimOrigin_f );

    return 
PLUGIN_HANDLED;
}

CXenPLight_SpawnFloat:origin] )
{
    new 
light create_entity"info_target" );

    if( 
light )
    {
        
set_pevlightpev_classnamexenPlantLightClassname );

        
set_pevlightpev_movetypeMOVETYPE_NONE );
        
set_pevlightpev_solidSOLID_TRIGGER );

        
engfuncEngFunc_SetModellightxenLightModel );
        
engfuncEngFunc_SetSizelightFloat:{ -80.0, -80.00.0 }, Float:{ 80.080.032.0 } );
        
engfuncEngFunc_SetOriginlightorigin );

        
SetActivitylightLIGHT_IDLE );

        
set_pevlightpev_nextthinkget_gametime() + 0.1 );
        
set_pevlightpev_framerandom_num0255 ) );

        
set_pevlightpev_rendercolorFloat:{ 232.0189.021.0 } );
        
set_pevlightpev_renderamt210.0 );

        new 
Float:mins], Float:maxs];

        
pevlightpev_minsmins );
        
pevlightpev_maxsmaxs );

        
origin] += ( mins] + maxs] ) * 0.5;

        new 
glow CSprite_SpriteCreatexenLightGlowSpriteorigin );

        if( 
glow )
        {
            
set_pevlightpev_glowglow );

            
CSprite_SetTransparencyglowlightkRenderGlow );
            
CSprite_SetAttachmentglowlight);
        }
    }
}

public 
CXenPLight_Think( const light )
{
    
OrpheuCallhandleFuncStudioFrameAdvancelight0.0 );
    
set_pevlightpev_nextthinkget_gametime() + 0.1 );

    switch( 
pevlightpev_sequence ) )
    {
        case 
LIGHT_RETRACT :
        {
            if( 
get_pdata_intlightm_fSequenceFinished) )
            {
                
SetActivitylightLIGHT_HIDE );
                
CXenPLight_LightOfflight );
            }
        }
        case 
LIGHT_HIDE :
        {
            static 
Float:nextStandTime;
            
pevlightpev_nextstandtimenextStandTime );

            if( 
get_gametime() > nextStandTime )
            {
                
SetActivitylightLIGHT_DEPLOY );
                
CXenPLight_LightOnlight );
            }
        }
        case 
LIGHT_DEPLOY :
        {
            if( 
get_pdata_intlightm_fSequenceFinished) )
            {
                
SetActivitylightLIGHT_IDLE );
            }
        }
    }
}

public 
CXenPLight_Touch( const light, const player )
{
    if( 
is_user_aliveplayer ) )
    {
        
set_pevlightpev_nextstandtimeget_gametime() + XenPlantHideTime );

        switch( 
pevlightpev_sequence ) )
        {
            case 
LIGHT_IDLELIGHT_DEPLOY : { SetActivitylightLIGHT_RETRACT ); }
        }
    }
}

CXenPLight_LightOn( const light )
{
    
OrpheuCallhandleFuncSUB_UseTargetslightlightUSE_ON0.0 );

    new 
glow pevlightpev_glow );
    
set_pevglowpev_effectspevglowpev_effects ) & ~EF_NODRAW );
}

CXenPLight_LightOff( const light )
{
    
OrpheuCallhandleFuncSUB_UseTargetslightlightUSE_OFF0.0 );

    new 
glow pevlightpev_glow );
    
set_pevglowpev_effectspevglowpev_effects ) | EF_NODRAW );
}

CSprite_SpriteCreate( const spriteName[], const Float:origin] )
{
    new 
sprite create_entity"env_sprite" );

    if( 
sprite )
    {
        
set_pevspritepev_modelspriteName );
        
set_pevspritepev_originorigin );

        
DispatchSpawnsprite );

        
set_pevspritepev_solidSOLID_NOT );
        
set_pevspritepev_movetypeMOVETYPE_NOCLIP );
    }

    return 
sprite;
}

CSprite_SetTransparency( const sprite, const entity 0, const renderMode kRenderNormal, const Float:renderColor] = { 0.00.00.0 }, const renderAmt 0, const renderFx kRenderFxNone )
{
    if( 
entity )
    {
        new 
Float:renderColor], Float:renderAmt;

        
peventitypev_rendercolorrenderColor );
        
peventitypev_renderamtrenderAmt );

        
set_pevspritepev_rendermoderenderMode );
        
set_pevspritepev_rendercolorrenderColor );
        
set_pevspritepev_renderamtrenderAmt );
        
set_pevspritepev_renderfxpeventitypev_renderfx ) );
    }
    else
    {
        
set_pevspritepev_rendermoderenderMode );
        
set_pevspritepev_rendercolorrenderColor );
        
set_pevspritepev_renderamtrenderAmt );
        
set_pevspritepev_renderfxrenderFx );
    }
}

CSprite_SetAttachment( const sprite, const entity, const attachment )
{
    if( 
entity )
    {
        
set_pevspritepev_skinentity );
        
set_pevspritepev_bodyattachment );
        
set_pevspritepev_aimententity );
        
set_pevspritepev_movetypeMOVETYPE_FOLLOW );
    }
}

SetActivity( const entity, const activity )
{
    
set_peventitypev_sequenceactivity );
    
set_peventitypev_frame);

    
OrpheuCallhandleFuncResetSequenceInfoentity );

Plugins and signatures are attached.
Attached Files
File Type: zip [signatures]xen_plant_light.zip (5.4 KB, 122 views)
__________________

Last edited by Arkshine; 10-22-2010 at 13:30.
Arkshine 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 10:25.


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