|
AMX Mod X Plugin Approver
|

10-22-2010
, 07:47
Re: Model animating confusion
|
#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 Float: XenPlantHideTime = 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_model( xenLightModel ); precache_model( xenLightModelT );
precache_model( xenLightGlowSprite ); }
public plugin_init() { register_plugin( "", "", "" ); register_clcmd( "say light", "ClientCommand_Light" );
register_think( xenPlantLightClassname, "CXenPLight_Think" ); register_touch( xenPlantLightClassname, "player", "CXenPLight_Touch" ); }
public ClientCommand_Light( const client ) { new aimOrigin[ 3 ], Float:aimOrigin_f[ 3 ];
get_user_origin( client, aimOrigin, 3 ); IVecFVec( aimOrigin, aimOrigin_f );
CXenPLight_Spawn( aimOrigin_f );
return PLUGIN_HANDLED; }
CXenPLight_Spawn( Float:origin[ 3 ] ) { new light = create_entity( "info_target" );
if( light ) { set_pev( light, pev_classname, xenPlantLightClassname );
set_pev( light, pev_movetype, MOVETYPE_NONE ); set_pev( light, pev_solid, SOLID_TRIGGER );
engfunc( EngFunc_SetModel, light, xenLightModel ); engfunc( EngFunc_SetSize, light, Float:{ -80.0, -80.0, 0.0 }, Float:{ 80.0, 80.0, 32.0 } ); engfunc( EngFunc_SetOrigin, light, origin );
SetActivity( light, LIGHT_IDLE );
set_pev( light, pev_nextthink, get_gametime() + 0.1 ); set_pev( light, pev_frame, random_num( 0, 255 ) );
set_pev( light, pev_rendercolor, Float:{ 232.0, 189.0, 21.0 } ); set_pev( light, pev_renderamt, 210.0 );
new Float:mins[ 3 ], Float:maxs[ 3 ];
pev( light, pev_mins, mins ); pev( light, pev_maxs, maxs );
origin[ 2 ] += ( mins[ 2 ] + maxs[ 2 ] ) * 0.5;
new glow = CSprite_SpriteCreate( xenLightGlowSprite, origin );
if( glow ) { set_pev( light, pev_glow, glow );
CSprite_SetTransparency( glow, light, kRenderGlow ); CSprite_SetAttachment( glow, light, 1 ); } } }
public CXenPLight_Think( const light ) { set_pev( light, pev_nextthink, get_gametime() + 0.1 );
switch( pev( light, pev_sequence ) ) { case LIGHT_RETRACT : { SetActivity( light, LIGHT_HIDE ); CXenPLight_LightOff( light ); } case LIGHT_HIDE : { static Float:nextStandTime; pev( light, pev_nextstandtime, nextStandTime );
if( get_gametime() > nextStandTime ) { SetActivity( light, LIGHT_DEPLOY ); CXenPLight_LightOn( light ); } } case LIGHT_DEPLOY : { SetActivity( light, LIGHT_IDLE ); } } }
public CXenPLight_Touch( const light, const player ) { if( is_user_alive( player ) ) { set_pev( light, pev_nextstandtime, get_gametime() + XenPlantHideTime );
switch( pev( light, pev_sequence ) ) { case LIGHT_IDLE, LIGHT_DEPLOY : { SetActivity( light, LIGHT_RETRACT ); } } } }
CXenPLight_LightOn( const light ) { new glow = pev( light, pev_glow ); set_pev( glow, pev_effects, pev( glow, pev_effects ) & ~EF_NODRAW ); }
CXenPLight_LightOff( const light ) { new glow = pev( light, pev_glow ); set_pev( glow, pev_effects, pev( glow, pev_effects ) | EF_NODRAW ); }
CSprite_SpriteCreate( const spriteName[], const Float:origin[ 3 ] ) { new sprite = create_entity( "env_sprite" );
if( sprite ) { set_pev( sprite, pev_model, spriteName ); set_pev( sprite, pev_origin, origin );
DispatchSpawn( sprite );
set_pev( sprite, pev_solid, SOLID_NOT ); set_pev( sprite, pev_movetype, MOVETYPE_NOCLIP ); }
return sprite; }
CSprite_SetTransparency( const sprite, const entity = 0, const renderMode = kRenderNormal, const Float:renderColor[ 3 ] = { 0.0, 0.0, 0.0 }, const renderAmt = 0, const renderFx = kRenderFxNone ) { if( entity ) { new Float:renderColor[ 3 ], Float:renderAmt;
pev( entity, pev_rendercolor, renderColor ); pev( entity, pev_renderamt, renderAmt );
set_pev( sprite, pev_rendermode, renderMode ); set_pev( sprite, pev_rendercolor, renderColor ); set_pev( sprite, pev_renderamt, renderAmt ); set_pev( sprite, pev_renderfx, pev( entity, pev_renderfx ) ); } else { set_pev( sprite, pev_rendermode, renderMode ); set_pev( sprite, pev_rendercolor, renderColor ); set_pev( sprite, pev_renderamt, renderAmt ); set_pev( sprite, pev_renderfx, renderFx ); } }
CSprite_SetAttachment( const sprite, const entity, const attachment ) { if( entity ) { set_pev( sprite, pev_skin, entity ); set_pev( sprite, pev_body, attachment ); set_pev( sprite, pev_aiment, entity ); set_pev( sprite, pev_movetype, MOVETYPE_FOLLOW ); } }
SetActivity( const entity, const activity ) { set_pev( entity, pev_sequence, activity ); set_pev( entity, pev_frame, 0 );
set_pev( entity, pev_animtime, get_gametime() ); set_pev( entity, pev_framerate, 1.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 Float: XenPlantHideTime = 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_model( xenLightModel ); precache_model( xenLightModelT );
precache_model( xenLightGlowSprite ); }
public plugin_init() { register_plugin( "", "", "" ); register_clcmd( "say light", "ClientCommand_Light" );
register_think( xenPlantLightClassname, "CXenPLight_Think" ); register_touch( xenPlantLightClassname, "player", "CXenPLight_Touch" );
handleFuncResetSequenceInfo = OrpheuGetFunction( "ResetSequenceInfo", "CBaseAnimating" ); handleFuncStudioFrameAdvance = OrpheuGetFunction( "StudioFrameAdvance", "CBaseAnimating" ); handleFuncSUB_UseTargets = OrpheuGetFunction( "SUB_UseTargets", "CBaseDelay" ); }
public ClientCommand_Light( const client ) { new aimOrigin[ 3 ], Float:aimOrigin_f[ 3 ];
get_user_origin( client, aimOrigin, 3 ); IVecFVec( aimOrigin, aimOrigin_f );
CXenPLight_Spawn( aimOrigin_f );
return PLUGIN_HANDLED; }
CXenPLight_Spawn( Float:origin[ 3 ] ) { new light = create_entity( "info_target" );
if( light ) { set_pev( light, pev_classname, xenPlantLightClassname );
set_pev( light, pev_movetype, MOVETYPE_NONE ); set_pev( light, pev_solid, SOLID_TRIGGER );
engfunc( EngFunc_SetModel, light, xenLightModel ); engfunc( EngFunc_SetSize, light, Float:{ -80.0, -80.0, 0.0 }, Float:{ 80.0, 80.0, 32.0 } ); engfunc( EngFunc_SetOrigin, light, origin );
SetActivity( light, LIGHT_IDLE );
set_pev( light, pev_nextthink, get_gametime() + 0.1 ); set_pev( light, pev_frame, random_num( 0, 255 ) );
set_pev( light, pev_rendercolor, Float:{ 232.0, 189.0, 21.0 } ); set_pev( light, pev_renderamt, 210.0 );
new Float:mins[ 3 ], Float:maxs[ 3 ];
pev( light, pev_mins, mins ); pev( light, pev_maxs, maxs );
origin[ 2 ] += ( mins[ 2 ] + maxs[ 2 ] ) * 0.5;
new glow = CSprite_SpriteCreate( xenLightGlowSprite, origin );
if( glow ) { set_pev( light, pev_glow, glow );
CSprite_SetTransparency( glow, light, kRenderGlow ); CSprite_SetAttachment( glow, light, 1 ); } } }
public CXenPLight_Think( const light ) { OrpheuCall( handleFuncStudioFrameAdvance, light, 0.0 ); set_pev( light, pev_nextthink, get_gametime() + 0.1 );
switch( pev( light, pev_sequence ) ) { case LIGHT_RETRACT : { if( get_pdata_int( light, m_fSequenceFinished, 4 ) ) { SetActivity( light, LIGHT_HIDE ); CXenPLight_LightOff( light ); } } case LIGHT_HIDE : { static Float:nextStandTime; pev( light, pev_nextstandtime, nextStandTime );
if( get_gametime() > nextStandTime ) { SetActivity( light, LIGHT_DEPLOY ); CXenPLight_LightOn( light ); } } case LIGHT_DEPLOY : { if( get_pdata_int( light, m_fSequenceFinished, 4 ) ) { SetActivity( light, LIGHT_IDLE ); } } } }
public CXenPLight_Touch( const light, const player ) { if( is_user_alive( player ) ) { set_pev( light, pev_nextstandtime, get_gametime() + XenPlantHideTime );
switch( pev( light, pev_sequence ) ) { case LIGHT_IDLE, LIGHT_DEPLOY : { SetActivity( light, LIGHT_RETRACT ); } } } }
CXenPLight_LightOn( const light ) { OrpheuCall( handleFuncSUB_UseTargets, light, light, USE_ON, 0.0 );
new glow = pev( light, pev_glow ); set_pev( glow, pev_effects, pev( glow, pev_effects ) & ~EF_NODRAW ); }
CXenPLight_LightOff( const light ) { OrpheuCall( handleFuncSUB_UseTargets, light, light, USE_OFF, 0.0 );
new glow = pev( light, pev_glow ); set_pev( glow, pev_effects, pev( glow, pev_effects ) | EF_NODRAW ); }
CSprite_SpriteCreate( const spriteName[], const Float:origin[ 3 ] ) { new sprite = create_entity( "env_sprite" );
if( sprite ) { set_pev( sprite, pev_model, spriteName ); set_pev( sprite, pev_origin, origin );
DispatchSpawn( sprite );
set_pev( sprite, pev_solid, SOLID_NOT ); set_pev( sprite, pev_movetype, MOVETYPE_NOCLIP ); }
return sprite; }
CSprite_SetTransparency( const sprite, const entity = 0, const renderMode = kRenderNormal, const Float:renderColor[ 3 ] = { 0.0, 0.0, 0.0 }, const renderAmt = 0, const renderFx = kRenderFxNone ) { if( entity ) { new Float:renderColor[ 3 ], Float:renderAmt;
pev( entity, pev_rendercolor, renderColor ); pev( entity, pev_renderamt, renderAmt );
set_pev( sprite, pev_rendermode, renderMode ); set_pev( sprite, pev_rendercolor, renderColor ); set_pev( sprite, pev_renderamt, renderAmt ); set_pev( sprite, pev_renderfx, pev( entity, pev_renderfx ) ); } else { set_pev( sprite, pev_rendermode, renderMode ); set_pev( sprite, pev_rendercolor, renderColor ); set_pev( sprite, pev_renderamt, renderAmt ); set_pev( sprite, pev_renderfx, renderFx ); } }
CSprite_SetAttachment( const sprite, const entity, const attachment ) { if( entity ) { set_pev( sprite, pev_skin, entity ); set_pev( sprite, pev_body, attachment ); set_pev( sprite, pev_aiment, entity ); set_pev( sprite, pev_movetype, MOVETYPE_FOLLOW ); } }
SetActivity( const entity, const activity ) { set_pev( entity, pev_sequence, activity ); set_pev( entity, pev_frame, 0 );
OrpheuCall( handleFuncResetSequenceInfo, entity ); }
Plugins and signatures are attached.
__________________
Last edited by Arkshine; 10-22-2010 at 13:30.
|
|