AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   NPC pain animation (https://forums.alliedmods.net/showthread.php?t=145378)

Mini_Midget 12-15-2010 09:51

NPC pain animation
 
Having a bit of a problem with having my NPC play any animation when it gets damage. It does emit the sound file (and makes the mouth move interestingly).

How can I play an animation then continue to do whatever animation it was doing before it got damaged?

PHP Code:

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

new const g_NpcClassName[] = "npc_barney";
new const 
g_NpcModel[] = "models/barney.mdl";
new const 
g_NpcSoundPain[] = "barney/ba_pain3.wav";

public 
plugin_init()
{
    
register_plugin("NPC Plugin""1.0""Mazza");
    
register_clcmd("say /npc""clcmd_npc");
    
register_cvar("test""4");
    
}

public 
plugin_precache()
{
    
precache_model(g_NpcModel)
    
precache_sound(g_NpcSoundPain)
}

public 
clcmd_npc(id)
{
    new 
ent create_entity("info_target");
    
    
entity_set_string(entEV_SZ_classnameg_NpcClassName);
    
    new 
Floatorigin[3], Floatangle[3];
    
entity_get_vector(idEV_VEC_originorigin);
    
entity_set_origin(entorigin);
    
origin[2] += 80.0;
    
entity_set_origin(idorigin);

    
entity_get_vector(idEV_VEC_anglesangle);
    
angle[0] = 0.0;
    
entity_set_vector(entEV_VEC_anglesangle);

    
set_pev(entpev_takedamage1.0);
    
set_pev(entpev_health1000.0);

    
entity_set_model(entg_NpcModel);
    
entity_set_int(entEV_INT_movetypeMOVETYPE_PUSHSTEP);
    
entity_set_int(entEV_INT_solidSOLID_BBOX);
    
    new 
Floatmins[3] = { -16.0, -16.00.0 };
    new 
Floatmaxs[3] = { 16.016.054.0    }
    
entity_set_size(entminsmaxs);
    
    
entity_set_byte(ent,EV_BYTE_controller1,125);
    
entity_set_byte(ent,EV_BYTE_controller2,125);
    
// entity_set_byte(ent,EV_BYTE_controller3,125);
    // entity_set_byte(ent,EV_BYTE_controller4,125);

    
entity_set_float(ent,EV_FL_animtime,2.0)
    
entity_set_float(ent,EV_FL_framerate1.0)
    
entity_set_int(ent,EV_INT_sequence4);
    
    
drop_to_floor(ent);
    
    
RegisterHamFromEntity(Ham_TakeDamageent"npc_TakeDamage"1);

    
entity_set_float(entEV_FL_nextthinkget_gametime() + 0.01)
}

public 
npc_TakeDamage(entinflictorattackerFloat:damagebits)
{
    
entity_set_float(ent,EV_FL_animtime,2.0)
    
entity_set_float(ent,EV_FL_framerate1.0)
    
entity_set_int(entEV_INT_sequence17 );

    
emit_sound(entCHAN_VOICEg_NpcSoundPain,  VOL_NORMATTN_NORM0PITCH_NORM)




xakintosh 12-15-2010 11:41

Re: NPC pain animation
 
Maybe emit_sound(ent, CHAN_VOICE, g_NpcSoundPain, 1.0, ATTN_NORM, 0, PITCH_NORM)
VOL_NORM to 1.0
emit_sound(id,CHAN_STATIC,"weapons/xbow_hit2.wav",1.0,ATTN_NORM,0,PITCH_NORM)

meTaLiCroSS 12-15-2010 12:03

Re: NPC pain animation
 
VOL_NORM = 1.0 lol wtf did you say.

Also, he asked for how to play an animation, not about the sound lol.

Mini_Midget 12-15-2010 21:36

Re: NPC pain animation
 
Quote:

Originally Posted by xakintosh (Post 1371596)
Maybe emit_sound(ent, CHAN_VOICE, g_NpcSoundPain, 1.0, ATTN_NORM, 0, PITCH_NORM)
VOL_NORM to 1.0
emit_sound(id,CHAN_STATIC,"weapons/xbow_hit2.wav",1.0,ATTN_NORM,0,PITCH_NORM)

... Did you even read my question or the title of this thread?

I'm asking how can I play any animation when my NPC gets damaged then have it play the same animation it was doing before it was hurt.

SaM.ThE.MaN 12-16-2010 03:20

Re: NPC pain animation
 
i think it could be done like this , when entity takes damage , play your animation ... you know : entity_set_float(ent,EV_FL_animtime,2.0)
entity_set_float(ent,EV_FL_framerate,1.0)
entity_set_int(ent,EV_INT_sequence,3);

then put a set_task after it and in that make it play your previous animation ...
it sounds like a stupid crazy idea -.-

Mini_Midget 12-16-2010 03:24

Re: NPC pain animation
 
The problem is that it wouldn't play the animation when it gets damaged at all.

PsYChOPaTiQuE 12-16-2010 04:14

Re: NPC pain animation
 
I had the same problem
Try that:

PHP Code:

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

new const g_NpcClassName[] = "npc_barney";
new const 
g_NpcModel[] = "models/barney.mdl";
new const 
g_NpcSoundPain[] = "barney/ba_pain3.wav";

public 
plugin_init()
    {
    
register_plugin("NPC Plugin""1.0""Mazza");
    
register_clcmd("say /npc""clcmd_npc");
    
register_cvar("test""4");
    
}

public 
plugin_precache()
    {
    
precache_model(g_NpcModel)
    
precache_sound(g_NpcSoundPain)
}

public 
clcmd_npc(id)
{
    new 
Float:CurrentTime get_gametime ()
    
    new 
ent create_entity("info_target");
    
    
entity_set_string(entEV_SZ_classnameg_NpcClassName);
    
    new 
Floatorigin[3], Floatangle[3];
    
entity_get_vector(idEV_VEC_originorigin);
    
entity_set_origin(entorigin);
    
origin[2] += 80.0;
    
entity_set_origin(idorigin);
    
    
entity_get_vector(idEV_VEC_anglesangle);
    
angle[0] = 0.0;
    
entity_set_vector(entEV_VEC_anglesangle);
    
    
set_pev(entpev_takedamage1.0);
    
set_pev(entpev_health1000.0);
    
    
entity_set_model(entg_NpcModel);
    
entity_set_int(entEV_INT_movetypeMOVETYPE_PUSHSTEP);
    
entity_set_int(entEV_INT_solidSOLID_BBOX);
    
    new 
Floatmins[3] = { -16.0, -16.00.0 };
    new 
Floatmaxs[3] = { 16.016.054.0    }
    
entity_set_size(entminsmaxs);
    
    
entity_set_byte(ent,EV_BYTE_controller1,125);
    
entity_set_byte(ent,EV_BYTE_controller2,125);
    
// entity_set_byte(ent,EV_BYTE_controller3,125);
    // entity_set_byte(ent,EV_BYTE_controller4,125);
    
    
set_pev(entpev_animtimeCurrentTime);
    
set_pev(entpev_frame0);
    
set_pev(entpev_framerate1.0);
    
set_pev(entpev_sequence4);
    
    
drop_to_floor(ent);
    
    
RegisterHamFromEntity(Ham_TakeDamageent"npc_TakeDamage"1);
    
    
entity_set_float(entEV_FL_nextthinkget_gametime() + 0.01)
}

public 
npc_TakeDamage(entinflictorattackerFloat:damagebits)
{
    new 
Float:CurrentTime get_gametime ();
    
    
set_pev(entpev_animtimeCurrentTime);
    
set_pev(entpev_frame0);
    
set_pev(entpev_framerate1.0);
    
set_pev(entpev_sequence17);
    
    
emit_sound(entCHAN_VOICEg_NpcSoundPain,  VOL_NORMATTN_NORM0PITCH_NORM)
    



Mini_Midget 12-16-2010 04:52

Re: NPC pain animation
 
Exactly what I was trying to do!
Thanks PsYChOPaTiQuE!

Is there any way to catch the duration of the animation so I can perfectly play the next animation?

I want to avoid the use of set_task and possibly have it think next on the length of the duration.

PsYChOPaTiQuE 12-16-2010 11:11

Re: NPC pain animation
 
I think it's the only way.


All times are GMT -4. The time now is 13:54.

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