При хостинг поддержке Интернет-сообщества VBIOS CS-Mapping.com.ua
Вернуться   CS-Mapping.com.ua > Forum > Разработка игр > Кодинг > Кодинг для Half-Life 2
Ник
Пароль
Регистрация Правила форума FAQ Пользователи Администрация Календарь Поиск За 24 часа Пометить все разделы прочитанными

Ответ
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.01.2013, 18:25  #1
TraNe
TraNe
Новобранец
Регистрация: 24.01.2013
Сообщения: 5


Предупреждение Проблема с NPC!

Всем привет, извиняюсь, если подобная тема уже была. Думаю, для вас это будет очень нубский вопрос, но я перешарил уже весь интренет,включая этот сайт и так и ничего не нашел.
Я создал своего NPC для мода, делал анимацию в программе"MilkShape 3D 1.8.4",компилил, все как полагается. NPC в игре работает, атакует и проигрывает анимацию. Но он полностью отказывается ходить... Анимация на ходьбу есть, простой монстр, который только и может, что ходить и атаковать, ничего более. Что только не пытался делать - все бесполезно. Ходить никак не собирается... Помогите, кто знает, в чем проблем. Не знаю, туда ли я тему впендюрил... Вот код .qc файла модели:

$cd "F:\Games\Steam\steamapps\sourcemods\---\models"
$modelname "creatures/closer.mdl"
$model "studio" "Zombie_reference.smd"
$poseparameter move_yaw -180.00 180.00
$cdmaterials "models\closer\"
$hboxset "default"
$hbox 0 "Pelvis" -14.241 -7.963 -10.691 30.494 7.691 10.692
$hbox 0 "Chest" 0.000 -6.500 -10.330 28.019 8.232 10.331
$hbox 0 "Head" -3.477 -7.140 -5.861 16.760 11.494 4.905
$hbox 0 "Face" 0.000 -6.764 -6.289 12.113 6.680 5.394
$hbox 0 "L_UpperArm" -23.743 -4.942 -4.474 7.922 4.311 4.922
$hbox 0 "L_ForeArm" -64.478 -11.688 -10.897 6.271 12.785 11.799
$hbox 0 "L_Hand" -29.911 -11.632 -10.897 4.176 12.837 11.799
$hbox 0 "L_Claw" -41.260 -2.684 -3.441 2.312 2.559 1.801
$hbox 0 "R_UpperArm" -7.987 -4.311 -4.922 23.743 4.942 4.474
$hbox 0 "R_ForeArm" -6.271 -12.785 -11.799 64.478 11.688 10.897
$hbox 0 "R_Hand" -4.176 -12.837 -11.799 29.911 11.632 10.897
$hbox 0 "R_Claw" -2.466 -2.559 -2.591 41.107 2.684 2.652
$hbox 0 "L_Thigh" -28.567 -5.283 -6.263 8.747 4.458 7.324
$hbox 0 "L_LowerLeg" -24.488 -2.562 -2.804 0.000 4.772 3.631
$hbox 0 "L_Foot" -15.508 -3.193 -2.429 1.584 4.557 2.397
$hbox 0 "R_Thigh" -8.747 -4.458 -7.324 28.567 5.283 6.263
$hbox 0 "R_LowerLeg" 0.000 -4.772 -3.625 24.488 2.562 2.804
$hbox 0 "R_Foot" -1.584 -4.557 -2.397 15.508 3.193 2.429
// Model uses material "closer.vmt"
$surfaceprop "flesh"
$eyeposition -0.000 0.000 64.000
$illumposition 6.562 -2.972 31.757
$sequence Idle01 "Idle01" loop ACT_IDLE 1 fps 45.00
$sequence a_walk2 "a_walk2" loop LX LY ACT_WALK 1 fps 35.00 {
{ event AE_ZOMBIE_SCUFF_LEFT 21 }
}

$sequence attackA "attackA" ACT_MELEE_ATTACK1 2 fps 15.00 {
{ event AE_ZOMBIE_ATTACK_SCREAM 6 }
{ event AE_ZOMBIE_ATTACK_RIGHT 6 }
}

$sequence attackB "attackB" ACT_MELEE_ATTACK1 2 fps 15.00 {
{ event AE_ZOMBIE_ATTACK_SCREAM 6 }
{ event AE_ZOMBIE_ATTACK_RIGHT 6 }
}

$sequence ragdoll "ragdoll" ACT_DIERAGDOLL 1 fps 30.00
$collisionjoints "phymodel.smd" {

$mass 100.0
$inertia 10.00
$damping 0.10
$rotdamping 3.00
$rootbone "pelvis"

$jointconstrain "r_thigh" x limit -35.00 15.00 0.00
$jointconstrain "r_thigh" y limit -100.00 30.00 0.00
$jointconstrain "r_thigh" z limit -30.00 30.00 0.00

$jointconstrain "r_lowerleg" x limit 0.00 0.00 0.00
$jointconstrain "r_lowerleg" y limit 0.00 0.00 0.00
$jointconstrain "r_lowerleg" z limit -125.00 0.00 0.00

$jointconstrain "l_thigh" x limit -35.00 15.00 0.00
$jointconstrain "l_thigh" y limit -100.00 30.00 0.00
$jointconstrain "l_thigh" z limit -30.00 30.00 0.00

$jointconstrain "l_lowerleg" x limit 0.00 0.00 0.00
$jointconstrain "l_lowerleg" y limit 0.00 0.00 0.00
$jointconstrain "l_lowerleg" z limit -125.00 0.00 0.00

$jointconstrain "l_foot" x limit -20.00 20.00 0.00
$jointconstrain "l_foot" y limit -20.00 20.00 0.00
$jointconstrain "l_foot" z limit -35.00 35.00 0.00

$jointconstrain "chest" x limit -30.00 30.00 0.00
$jointconstrain "chest" y limit -45.00 45.00 0.00
$jointconstrain "chest" z limit -50.00 21.00 0.00

$jointconstrain "r_upperarm" x limit -35.00 35.00 0.00
$jointconstrain "r_upperarm" y limit -135.00 30.00 0.00
$jointconstrain "r_upperarm" z limit -3.00 164.00 0.00

$jointconstrain "r_forearm" x limit 0.00 0.00 0.00
$jointconstrain "r_forearm" y limit -135.00 0.00 0.00
$jointconstrain "r_forearm" z limit 0.00 0.00 0.00

$jointconstrain "r_hand" x limit -10.00 10.00 0.00
$jointconstrain "r_hand" y limit -37.00 37.00 0.00
$jointconstrain "r_hand" z limit -12.00 12.00 0.00

$jointconstrain "l_upperarm" x limit -35.00 35.00 0.00
$jointconstrain "l_upperarm" y limit -135.00 30.00 0.00
$jointconstrain "l_upperarm" z limit -3.00 167.00 0.00

$jointconstrain "l_forearm" x limit 0.00 0.00 0.00
$jointconstrain "l_forearm" y limit -135.00 0.00 0.00
$jointconstrain "l_forearm" z limit 0.00 0.00 0.00

$jointconstrain "l_hand" x limit -10.00 10.00 0.00
$jointconstrain "l_hand" y limit -37.00 37.00 0.00
$jointconstrain "l_hand" z limit -10.00 10.00 0.00

$jointconstrain "l_claw" x limit 0.00 0.00 0.00
$jointconstrain "l_claw" y limit 0.00 0.00 0.00
$jointconstrain "l_claw" z limit 0.00 180.00 0.00

$jointconstrain "head" x limit -35.00 35.00 0.00
$jointconstrain "head" y limit -70.00 70.00 0.00
$jointconstrain "head" z limit -35.00 39.00 0.00

$jointconstrain "face" x limit -64.00 64.00 0.00
$jointconstrain "face" y limit -30.00 30.00 0.00
$jointconstrain "face" z limit -30.00 30.00 0.00

$jointconstrain "r_claw" x limit 0.00 0.00 0.00
$jointconstrain "r_claw" y limit 0.00 0.00 0.00
$jointconstrain "r_claw" z limit 0.00 180.00 0.00

$jointconstrain "r_foot" x limit -17.00 17.00 0.00
$jointconstrain "r_foot" y limit -19.00 19.00 0.00
$jointconstrain "r_foot" z limit -21.00 21.00 0.00
}



Вот .cpp файл, назвал npc_closer.cpp,делал на основе зомбайна без гранаты. Компилит без ошибок.

#include "cbase.h"
#include "ai_basenpc.h"
#include "ai_default.h"
#include "ai_schedule.h"
#include "ai_hull.h"
#include "ai_motor.h"
#include "ai_memory.h"
#include "ai_route.h"
#include "ai_squad.h"
#include "soundent.h"
#include "game.h"
#include "npcevent.h"
#include "entitylist.h"
#include "ai_task.h"
#include "activitylist.h"
#include "engine/IEngineSound.h"
#include "npc_BaseZombie.h"
#include "movevars_shared.h"
#include "IEffects.h"
#include "props.h"
#include "physics_npc_solver.h"
#include "hl2_player.h"
#include "hl2_gamerules.h"
#include "ai_interactions.h"

#include "tier0/memdbgon.h"

enum
{
SQUAD_SLOT_CLOSER_SPRINT1 = LAST_SHARED_SQUADSLOT,
SQUAD_SLOT_CLOSER_SPRINT2,
};

#define MIN_SPRINT_TIME 3.5f
#define MAX_SPRINT_TIME 5.5f
#define MIN_SPRINT_DISTANCE 64.0f
#define MAX_SPRINT_DISTANCE 1024.0f
#define SPRINT_CHANCE_VALUE 10
#define SPRINT_CHANCE_VALUE_DARKNESS 50

int ACT_CLOSER_ATTACK_FAST;
int AE_CLOSER_PULLPIN;
extern bool IsAlyxInDarknessMode();
ConVar sk_closer_health( "sk_closer_health","0");

class CNPC_Closer : public CAI_BlendingHost<CNPC_BaseZombie>, public CDefaultPlayerPickupVPhysics{
DECLARE_DATADESC();
DECLARE_CLASS( CNPC_Closer, CAI_BlendingHost<CNPC_BaseZombie> );

public:

void Spawn( void );
void Precache( void );
void SetZombieModel( void );
virtual void PrescheduleThink( void );
virtual int SelectSchedule( void );
virtual void BuildScheduleTestBits( void );
virtual void HandleAnimEvent( animevent_t *pEvent );
virtual const char *GetLegsModel( void );
virtual const char *GetTorsoModel( void );
virtual const char *GetHeadcrabClassname( void );
virtual const char *GetHeadcrabModel( void );
virtual void PainSound( const CTakeDamageInfo &info );
virtual void DeathSound( const CTakeDamageInfo &info );
virtual void AlertSound( void );
virtual void IdleSound( void );
virtual void AttackSound(void);
virtual void AttackHitSound( void );
virtual void AttackMissSound( void );
virtual void FootstepSound( bool fRightFoot );
virtual void FootscuffSound( bool fRightFoot );
virtual void MoanSound( envelopePoint_t *pEnvelope, int iEnvelopeSize );
virtual void Event_Killed( const CTakeDamageInfo &info );
virtual void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr );
virtual void RunTask( const Task_t *pTask );
virtual int MeleeAttack1Conditions ( float flDot, float flDist );
virtual bool ShouldBecomeTorso( const CTakeDamageInfo &info, float flDamageThreshold );
virtual void OnScheduleChange ( void );
virtual bool CanRunAScriptedNPCInteraction( bool bForced );
virtual Activity NPC_TranslateActivity( Activity baseAct );
const char *GetMoanSound( int nSound );
bool AllowedToSprint( void );
void Sprint( bool bMadSprint = false );
void StopSprint( void );
bool IsSprinting( void ) { return m_flSprintTime > gpGlobals->curtime; }
int TranslateSchedule( int scheduleType );
void InputStartSprint ( inputdata_t &inputdata );

public:
DEFINE_CUSTOM_AI;

private:

float m_flSprintTime;
float m_flSprintRestTime;
float m_flSuperFastAttackTime;
protected:
static const char *pMoanSounds[];

};

LINK_ENTITY_TO_CLASS( npc_closer, CNPC_Closer );

BEGIN_DATADESC( CNPC_Closer )
DEFINE_FIELD( m_flSprintTime, FIELD_TIME ),
DEFINE_FIELD( m_flSprintRestTime, FIELD_TIME ),
DEFINE_FIELD( m_flSuperFastAttackTime, FIELD_TIME ),
DEFINE_INPUTFUNC( FIELD_VOID, "StartSprint", InputStartSprint ),
END_DATADESC()

//---------------------------------------------------------
//---------------------------------------------------------
const char *CNPC_Closer::pMoanSounds[] ={"ATV_engine_null",};

void CNPC_Closer::Spawn( void ){
Precache();

m_fIsTorso = true;
m_fIsHeadless = true;

SetBloodColor( BLOOD_COLOR_RED );

m_iHealth = 50;
SetMaxHealth( m_iHealth );

m_flFieldOfView = 0.2;

CapabilitiesClear();

BaseClass::Spawn();

m_flSprintTime = 0.0f;
m_flSprintRestTime = 0.0f;

m_flNextMoanSound = gpGlobals->curtime + random->RandomFloat( 1.0, 4.0 );
}

void CNPC_Closer:recache( void ){
BaseClass:recache();
PrecacheModel( "models/zombie/paperzombie.mdl" );
PrecacheModel( "models/zombie/classic_legs.mdl" );
PrecacheModel( "models/zombie/classic_torso.mdl" );
PrecacheScriptSound( "Zombie.FootstepRight" );
PrecacheScriptSound( "Zombie.FootstepLeft" );
PrecacheScriptSound( "Zombie.ScuffRight" );
PrecacheScriptSound( "Zombie.ScuffLeft" );
PrecacheScriptSound( "Zombie.AttackHit" );
PrecacheScriptSound( "Zombie.AttackMiss" );
PrecacheScriptSound( "Zombie.Pain" );
PrecacheScriptSound( "Zombie.Die" );
PrecacheScriptSound( "Zombie.Alert" );
PrecacheScriptSound( "Zombie.Idle" );
PrecacheScriptSound( "ATV_engine_null" );
PrecacheScriptSound( "Zombie.Charge" );
PrecacheScriptSound( "Zombie.Attack" );
}

void CNPC_Closer::SetZombieModel( void ){
SetModel( "models/zombie/paperzombie.mdl" );
SetHullType( HULL_HUMAN );
SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless );
SetHullSizeNormal( true );
SetDefaultEyeOffset();
SetActivity( ACT_IDLE );
}

void CNPC_Closer:rescheduleThink( void ){
if( gpGlobals->curtime > m_flNextMoanSound )
{
if( CanPlayMoanSound() )
{
// Classic guy idles instead of moans.
IdleSound();

m_flNextMoanSound = gpGlobals->curtime + random->RandomFloat( 10.0, 15.0 );
}
else
{
m_flNextMoanSound = gpGlobals->curtime + random->RandomFloat( 2.5, 5.0 );
}
}
BaseClass:rescheduleThink();
}

void CNPC_Closer::OnScheduleChange( void ){
if ( HasCondition( COND_CAN_MELEE_ATTACK1 ) && IsSprinting() == true )
{
m_flSuperFastAttackTime = gpGlobals->curtime + 1.0f;
}

BaseClass::OnScheduleChange();
}
bool CNPC_Closer::CanRunAScriptedNPCInteraction( bool bForced ){
return BaseClass::CanRunAScriptedNPCInteraction( bForced );
}

int CNPC_Closer::SelectSchedule( void ){
if ( GetHealth() <= 0 )
return BaseClass::SelectSchedule();

return BaseClass::SelectSchedule();
}

void CNPC_Closer::BuildScheduleTestBits( void ){
BaseClass::BuildScheduleTestBits();


}

Activity CNPC_Closer::NPC_TranslateActivity( Activity baseAct ){
if ( baseAct == ACT_MELEE_ATTACK1 )
{
if ( m_flSuperFastAttackTime > gpGlobals->curtime)
{
return (Activity)ACT_CLOSER_ATTACK_FAST;
}
}

return BaseClass::NPC_TranslateActivity( baseAct );
}

int CNPC_Closer::MeleeAttack1Conditions ( float flDot, float flDist ){
int iBase = BaseClass::MeleeAttack1Conditions( flDot, flDist );

return iBase;
}


int CNPC_Closer::TranslateSchedule( int scheduleType ) {
return BaseClass::TranslateSchedule( scheduleType );
}

void CNPC_Closer::Event_Killed( const CTakeDamageInfo &info ){
BaseClass::Event_Killed( info );
}

void CNPC_Closer::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr )
{BaseClass::TraceAttack( info, vecDir, ptr );}

void CNPC_Closer::HandleAnimEvent( animevent_t *pEvent ){
if ( pEvent->event == AE_CLOSER_PULLPIN )
{
Vector vecStart;
QAngle angles;
}
return;
}

bool CNPC_Closer::AllowedToSprint( void ){
if ( IsOnFire() )
return false;

//If you're sprinting then there's no reason to sprint again.
if ( IsSprinting() )
return false;

int iChance = SPRINT_CHANCE_VALUE;

CHL2_Player *pPlayer = dynamic_cast <CHL2_Player*> ( AI_GetSinglePlayer() );

if ( pPlayer )
{
if ( HL2GameRules()->IsAlyxInDarknessMode() && pPlayer->FlashlightIsOn() == false )
{
iChance = SPRINT_CHANCE_VALUE_DARKNESS;
}

//Bigger chance of this happening if the player is not looking at the zombie
if ( pPlayer->FInViewCone( this ) == false )
{
iChance *= 2;
}
}
if ( ( GetHealth() > GetMaxHealth() * 0.5f ) )
{
if ( IsStrategySlotRangeOccupied( SQUAD_SLOT_CLOSER_SPRINT1, SQUAD_SLOT_CLOSER_SPRINT2 ) == true )
return false;

if ( random->RandomInt( 0, 100 ) > iChance )
return false;

if ( m_flSprintRestTime > gpGlobals->curtime )
return false;
}

float flLength = ( GetEnemy()->WorldSpaceCenter() - WorldSpaceCenter() ).Length();

if ( flLength > MAX_SPRINT_DISTANCE )
return false;

return true;
}

void CNPC_Closer::StopSprint( void ){
GetNavigator()->SetMovementActivity( ACT_WALK );

m_flSprintTime = gpGlobals->curtime;
m_flSprintRestTime = m_flSprintTime + random->RandomFloat( 2.5f, 5.0f );
}

void CNPC_Closer::Sprint( bool bMadSprint ){
if ( IsSprinting() )
return;

OccupyStrategySlotRange( SQUAD_SLOT_CLOSER_SPRINT1, SQUAD_SLOT_CLOSER_SPRINT2 );
GetNavigator()->SetMovementActivity( ACT_RUN );

float flSprintTime = random->RandomFloat( MIN_SPRINT_TIME, MAX_SPRINT_TIME );

m_flSprintTime = gpGlobals->curtime + flSprintTime;

//Don't sprint for this long after I'm done with this sprint run.
m_flSprintRestTime = m_flSprintTime + random->RandomFloat( 2.5f, 5.0f );

EmitSound( "Zombie.Charge" );
}

void CNPC_Closer::RunTask( const Task_t *pTask ){
switch ( pTask->iTask )
{
case TASK_WAIT_FOR_MOVEMENT_STEP:
case TASK_WAIT_FOR_MOVEMENT:
{
BaseClass::RunTask( pTask );

if ( IsOnFire() && IsSprinting() )
{
StopSprint();
}
if ( GetEnemy() )
{
if ( AllowedToSprint() == true )
{
Sprint( ( GetHealth() <= GetMaxHealth() * 0.5f ) );
return;
}

if ( GetNavigator()->GetMovementActivity() != ACT_WALK )
{
if ( IsSprinting() == false )
{
GetNavigator()->SetMovementActivity( ACT_WALK );
}
}
}
else
{
GetNavigator()->SetMovementActivity( ACT_WALK );
}

break;
}
default:
{
BaseClass::RunTask( pTask );
break;
}
}
}

void CNPC_Closer::InputStartSprint ( inputdata_t &inputdata ){
Sprint();
}

const char *CNPC_Closer::GetMoanSound( int nSound ){
return pMoanSounds[ nSound % ARRAYSIZE( pMoanSounds ) ];
}

void CNPC_Closer::FootstepSound( bool fRightFoot ){
if( fRightFoot )
{
EmitSound( "Zombie.FootstepRight" );
}
else
{
EmitSound( "Zombie.FootstepLeft" );
}
}

void CNPC_Closer::AttackSound(void){
EmitSound( "Zombie.Attack" );
}

bool CNPC_Closer::ShouldBecomeTorso( const CTakeDamageInfo &info, float flDamageThreshold ){
return false;
}

void CNPC_Closer::FootscuffSound( bool fRightFoot ){
if( fRightFoot )
{
EmitSound( "Zombie.ScuffRight" );
}
else
{
EmitSound( "Zombie.ScuffLeft" );
}
}

void CNPC_Closer::AttackHitSound( void ){
EmitSound( "Zombie.AttackHit" );
}

void CNPC_Closer::AttackMissSound( void ){
EmitSound( "Zombie.AttackMiss" );
}

void CNPC_Closer:ainSound( const CTakeDamageInfo &info ){

if ( IsOnFire() )
{
return;
}

EmitSound( "Zombie.Pain" );
}

void CNPC_Closer:eathSound( const CTakeDamageInfo &info ) {
EmitSound( "Zombie.Die" );
}

void CNPC_Closer::AlertSound( void ){
EmitSound( "Zombie.Alert" );
m_flNextMoanSound += random->RandomFloat( 2.0, 4.0 );
}

void CNPC_Closer::IdleSound( void ){
if( GetState() == NPC_STATE_IDLE && random->RandomFloat( 0, 1 ) == 0 )
{
return;
}

if( IsSlumped() )
{
return;
}

EmitSound( "Zombie.Idle" );
MakeAISpookySound( 360.0f );
}

const char *CNPC_Closer::GetHeadcrabModel( void ){
return "models/headcrabclassic.mdl";
}

const char *CNPC_Closer::GetLegsModel( void ){
return "models/zombie/classic_legs.mdl";
}

const char *CNPC_Closer::GetTorsoModel( void ){
return "models/zombie/classic_torso.mdl";
}

void CNPC_Closer::MoanSound( envelopePoint_t *pEnvelope, int iEnvelopeSize ){
if( IsOnFire() )
{
BaseClass::MoanSound( pEnvelope, iEnvelopeSize );
}
}

const char *CNPC_Closer::GetHeadcrabClassname( void ){
return "npc_headcrab";
}

AI_BEGIN_CUSTOM_NPC( npc_closer, CNPC_Closer )
DECLARE_SQUADSLOT( SQUAD_SLOT_CLOSER_SPRINT1 )
DECLARE_SQUADSLOT( SQUAD_SLOT_CLOSER_SPRINT2 )
DECLARE_ACTIVITY( ACT_CLOSER_ATTACK_FAST )
DECLARE_ANIMEVENT( AE_CLOSER_PULLPIN )
AI_END_CUSTOM_NPC()

TraNe, подумав, добавил 24.01.2013 в 22:09
Неужели никто не сталкивался с подобной проблемой??? Люди добрые, помогите, я в этом деле еще новичок)

Последний раз редактировалось TraNe, 24.01.2013 в 22:09.
TraNe вне форума Ответить с цитированием
Ответ

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 11:07.


Designed by FT-502, [email protected] Originally by Ulric Spaak
Hosted by: VBIOS.COM, Powered by: vBulletin
copyright © 2002 - 2021 by CS-Mapping.com.ua Community