AlliedModders

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

Bos93 12-04-2011 13:37

fix animation
 
How to fix animation on the NPC, when animation at the beginning doesnt play well and than play as it should

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#include <xs>

#define TASK_COOLDOWN 7208
#define TASK_REMOVE 8072
#define ID_REMOVE (taskid - TASK_REMOVE)

const MAX_SPAWN 32
new g_cooldown
new g_spawncount
new g_dead[256]
new 
g_follow

new const g_NpcClassName[] = "ent_npc"

new const g_NpcModel[] = "models/npc.mdl"

new const g_NpcSoundPain[][] = 
{
    
"barney/ba_pain1.wav"
}

new const 
g_NpcSoundDeath[][] =
{
    
"barney/ba_die1.wav"
}

new 
spr_blood_dropspr_blood_spray

public plugin_precache()
{
    
spr_blood_drop precache_model("sprites/blood.spr")
    
spr_blood_spray precache_model("sprites/bloodspray.spr")
    
    new 
i
    
for(sizeof g_NpcSoundPain i++) precache_sound(g_NpcSoundPain[i]);
    for(
sizeof g_NpcSoundDeath i++) precache_sound(g_NpcSoundDeath[i]);
    
    
precache_model(g_NpcModel)
}

public 
plugin_init()
{
    
register_plugin("Bouncing Barney""1.0""Mazza")
    
    
register_clcmd("say /npc""clcmd_npc")
    
register_clcmd("say /follow""clcmd_follow")
    
    
RegisterHam(Ham_TakeDamage"info_target""npc_TakeDamage")
    
RegisterHam(Ham_Killed"info_target""npc_Killed")
    
RegisterHam(Ham_Think"info_target""npc_Think")
    
RegisterHam(Ham_TraceAttack"info_target""npc_TraceAttack")
}

public 
clcmd_npc(id)
{
    if(
g_cooldown) return PLUGIN_HANDLED;
    
    if(
g_spawncount >= MAX_SPAWN)
    {
        
client_print(idprint_chat"[EntTest] Max [%i] spawns has been reach."MAX_SPAWN)
        return 
PLUGIN_HANDLED;
    }
    
    
g_cooldown 1
    
    
new ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
    if(!
pev_valid(ent)) return PLUGIN_HANDLED;
    
    
set_pev(entpev_classnameg_NpcClassName)
    
set_pev(entpev_netname"Barney")
    new 
Floatorigin[3], Floatangle[3], Floatvelocity[3]
    
pev(idpev_originorigin)
    
origin[2] += 80.0
    engfunc
(EngFunc_SetOriginentorigin)
    
pev(idpev_anglesangle)
    
angle[0] = 0.0
    set_pev
(entpev_anglesangle)
    
set_pev(entpev_takedamage1.0)
    
set_pev(entpev_health100.0)
    
set_pev(entpev_gravity1.0)
    
set_pev(entpev_movetypeMOVETYPE_PUSHSTEP)
    
set_pev(entpev_solidSOLID_SLIDEBOX)
    
set_pev(entpev_controller_1125)
    
set_pev(entpev_controller_2125)
    
set_pev(entpev_controller_3125)
    
engfunc(EngFunc_SetModelentg_NpcModel)
    
engfunc(EngFunc_SetSizeent, {-12.0, -12.00.0 }, { 12.012.075.0 })
    
velocity_by_aim(id800velocity)
    
set_pev(entpev_velocityvelocity)
    
    
g_spawncount += 1
    
    set_pev
(entpev_nextthinkget_gametime() + 0.01)
    
set_task(1.0"ResetCooldown"TASK_COOLDOWN)
    
    return 
PLUGIN_HANDLED;
}

public 
clcmd_follow(id)

    
g_follow id
    
    
return PLUGIN_HANDLED;


public 
npc_TraceAttack(iEntattackerFloatdamageFloatdirection[3], tracedamageBits)
{
    if(!
pev_valid(iEnt)) return;
    
    new 
className[32]
    
pev(iEntpev_classnameclassNamecharsmax(className))
    
    if(!
equali(classNameg_NpcClassName)) return;
    
    new 
Floatend[3]
    
get_tr2(traceTR_vecEndPosend)
    
    
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
    
write_byte(TE_BLOODSPRITE)
    
engfunc(EngFunc_WriteCoordend[0])
    
engfunc(EngFunc_WriteCoordend[1])
    
engfunc(EngFunc_WriteCoordend[2])
    
write_short(spr_blood_spray)
    
write_short(spr_blood_drop)
    
write_byte(247// color index
    
write_byte(random_num(15)) // size
    
message_end()
}

public 
npc_TakeDamage(iEntinflictorattackerFloat:damagebits)
{
    new 
className[32]
    
pev(iEntpev_classnameclassNamecharsmax(className))
    
    if(!
equali(classNameg_NpcClassName)) return;
    
    
Util_PlayAnimation(iEntrandom_num(1317), 1.25)
    
    
emit_sound(iEntCHAN_VOICEg_NpcSoundPain[random(sizeof g_NpcSoundPain)],  VOL_NORMATTN_NORM0PITCH_NORM)
}

public 
npc_Killed(iEnt)
{
    new 
className[32]
    
pev(iEntpev_classnameclassNamecharsmax(className))
    
    if(!
equali(classNameg_NpcClassName)) return HAM_IGNORED;
    
    
g_dead[iEnt] = 1
    
    Util_PlayAnimation
(iEntrandom_num(2530))
    
    
set_pev(iEntpev_solidSOLID_NOT)
    
    
emit_sound(iEntCHAN_VOICEg_NpcSoundDeath[random(sizeof g_NpcSoundDeath)],  VOL_NORMATTN_NORM0PITCH_NORM)
    
    
set_task(2.0"RemoveDeadEntity"iEnt+TASK_REMOVE)
    
    return 
HAM_SUPERCEDE;
}

public 
npc_Think(iEnt)
{
    if(!
pev_valid(iEnt)) return;
    
    static 
className[32]
    
pev(iEntpev_classnameclassNamecharsmax(className))
    
    if(!
equali(classNameg_NpcClassName)) return;
    
    if(
g_dead[iEnt]) return;
    
    if(
is_user_alive(g_follow)) entity_set_aim(iEntg_follow);
    
    
set_pev(iEntpev_nextthinkget_gametime() + 0.01)
}

public 
ResetCooldown(taskid)
{
    
g_cooldown 0
}

public 
RemoveDeadEntity(taskid)
{
    if(!
pev_valid(ID_REMOVE)) return;
    
    
engfunc(EngFunc_RemoveEntityID_REMOVE)
    
    
g_spawncount -= 1
    g_dead
[ID_REMOVE] = 0
}

entity_set_aim(entplayer

    static 
Float:origin[3], Float:ent_origin[3], Float:angles[3
    
pev(playerpev_originorigin
    
pev(entpev_originent_origin
     
    
xs_vec_sub(originent_originorigin
    
xs_vec_normalize(originorigin
    
vector_to_angle(originangles
     
    
angles[0] = 0.0 
     
    set_pev
(entpev_anglesangles)
    
set_velocity(entangles)


set_velocity(entFloat:angles[3]) 

    static 
FloatDirection[3
    
angle_vector(anglesANGLEVECTOR_FORWARDDirection
    
xs_vec_mul_scalar(Direction130.0Direction// 215 speed
    
set_pev(entpev_velocityDirection)
    
    
// Run Sequence
    
if(pev(entpev_sequence) != 5Util_PlayAnimation(ent5);
}

Util_PlayAnimation(indexsequenceFloatframerate 1.0)
{
    
set_pev(indexpev_animtimeget_gametime())
    
set_pev(indexpev_framerate,  framerate)
    
set_pev(indexpev_frame0.0)
    
set_pev(indexpev_sequencesequence)




All times are GMT -4. The time now is 11:59.

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