AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Model animating confusion (https://forums.alliedmods.net/showthread.php?t=141219)

Lulu the hero 10-21-2010 00:06

Model animating confusion
 
Hi there!

I often find myself in the following situation while writing a plugin:

I load a model and place it in the map, then I need to set it's animation phases, so that the movement is smooth.
Try the code below:
PHP Code:

#define light_hiding_time 5.0
new const Float:light_collision_radius 15.0;

#define TASK_LIGHT 750

//models of the light
new const light_models[][] = { "models/light.mdl","models/lightt.mdl" }
new const 
alien_gibs[] = "models/agibs.mdl"

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>

public plugin_init(){
    
register_plugin("Creatures","1.0","Lulu the hero");
    
    
register_clcmd("say light","test");
    
    
//precache the...
    
new modelnum;
    
    
//light models
    
for(modelnum=0;modelnum<sizeof light_models;modelnum++)
        
engfunc(EngFunc_PrecacheModel,light_models[modelnum]);
        
    
engfunc(EngFunc_PrecacheModel,alien_gibs);
    
RegisterHam(Ham_Touch,"info_target","touched_light");
}

public 
plugin_precache(){
    
precache_model"models/fleshgibs.mdl" );

    
precache_sound"debris/bustflesh1.wav" );
    
precache_sound"debris/bustflesh2.wav" );

    
precache_sound"debris/flesh1.wav" );
    
precache_sound"debris/flesh2.wav" );
    
precache_sound"debris/flesh3.wav" );
    
precache_sound"debris/flesh5.wav" );
    
precache_sound"debris/flesh6.wav" );
    
precache_sound"debris/flesh7.wav" ); 
}

public 
test(id){
    new 
team get_user_team(id);
    
    if(
is_user_alive(id)&&is_user_connected(id)&&((team==1)||(team==2))){
    
        new 
origin[3],Float:f_origin[3];
        new 
tempid,Float:size1[3],Float:size2[3];
        
        
get_user_origin(id,origin,3);
        
f_origin[0] = float(origin[0]);
        
f_origin[1] = float(origin[1]);
        
f_origin[2] = float(origin[2]);
        
        
tempid engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"));
        
        if(
pev_valid(tempid)){
            
set_pev(tempid,pev_classname,"creature_light");
            
engfunc(EngFunc_SetModel,tempid,light_models[0]);
            
            
size1[0] = 0.0-light_collision_radius;
            
size1[1] = 0.0-light_collision_radius;
            
size1[2] = 0.0;
            
            
size2[0] = light_collision_radius;
            
size2[1] = light_collision_radius;
            
size2[2] = light_collision_radius;
            
            
set_pev(tempid,pev_solid,SOLID_BBOX);
            
            
engfunc(EngFunc_SetSize,tempid,size1,size2);
            
            
set_pev(tempid,pev_movetype,MOVETYPE_NONE);
            
            
set_pev(tempid,pev_sequence,0);
            
set_pev(tempid,pev_gaitsequence,0);
            
set_pev(tempid,pev_frame,0);
            
set_pev(tempid,pev_framerate,1.0);
            
            
set_pev(tempid,pev_euser1,3);
            
            
//lighting(f_origin,200,200,100,1);
            //DispatchKeyValue(tempid,"material","3");
            //DispatchKeyValue(tempid,"health","100");
            
            //set_pev(tempid,pev_health,100.0);
            
            
engfunc(EngFunc_SetOrigin,tempid,f_origin);
            
DispatchSpawn(tempid);
        }
    }
    return 
PLUGIN_HANDLED;
}

public 
touched_light(ent,other){
    new 
classname[32];
    
pev(ent,pev_classname,classname,31);
    if(!
equal(classname,"creature_light")) return HAM_IGNORED;

    new 
team get_user_team(other);
    if(
is_user_alive(other)&&is_user_connected(other)&&((team==1)||(team==2))){
        new 
st pev(ent,pev_euser1);
        new 
params[1];
        
params[0] = ent;
        if(
st>=2){
            
withdraw_light(params);
        }else if(
st==0){
            
remove_task(TASK_LIGHT+ent);
            
set_task(light_hiding_time,"deploy_light",TASK_LIGHT+ent,params,1);
        }
    }
    return 
HAM_HANDLED;
}

public 
withdraw_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,1);
    
    
set_pev(ent,pev_sequence,1);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,1);
    
set_pev(ent,pev_animtime,0.3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(0.3,"hidden_light",TASK_LIGHT+ent,params,1);
}

public 
deploy_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,2);
    
    
set_pev(ent,pev_sequence,2);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,2);
    
set_pev(ent,pev_animtime,1.3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(1.3,"normal_light",TASK_LIGHT+ent,params,1);
}

public 
normal_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,3);
    
    
set_pev(ent,pev_sequence,0);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,0);
}

public 
hidden_light(params[]){
    new 
ent params[0];
    
set_pev(ent,pev_euser1,0);
    
    
set_pev(ent,pev_sequence,3);
    
set_pev(ent,pev_frame,0);
    
set_pev(ent,pev_framerate,1.0);
    
    
set_pev(ent,pev_gaitsequence,3);
    
    
remove_task(TASK_LIGHT+ent);
    
set_task(light_hiding_time,"deploy_light",TASK_LIGHT+ent,params,1);



Then when I load the game and actually put a "light" creature in the game, there are animation problems. To be honest, I really don't know what gaitsequence is, or are the other animation settings work properly, so I would need a small tutorial or alike on how to play an animation for a model.

Eg. rewind animation to the beginning frame, loop animation, play it only once, or generally how does this work in HL?

Or more simply, why are the animation troubles on withdraw and deploy states?

Thank you very much for all the ideas, helps in advance, I would really like to know what do I need to take care of while animating, because I would need these much.

Arkshine 10-21-2010 19:55

Re: Model animating confusion
 
Just to be sure, for what game ? I've already tried something but I was wondering the game because in HL you have already such entity.

Lulu the hero 10-21-2010 20:33

Re: Model animating confusion
 
i would like to create plugins using this for cstrike. and maybe sven coop, ns or they hunger.

Arkshine 10-22-2010 07:47

Re: Model animating confusion
 
1 Attachment(s)
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.

Rirre 08-22-2012 10:36

Re: Model animating confusion
 
Orpheu's version crashing the server instantly when it gonna hide/deploy.
Or when spawning twice lights.
No error log.

Arkshine 08-22-2012 10:42

Re: Model animating confusion
 
Because of ResetSequenceInfo/StudioFrameAdvance, it doesn't work well. Tried in another plugin, and sometimes it crashes, sometimes not. You will have to implement the method in my first plugin.


All times are GMT -4. The time now is 10:25.

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