I'm trying to make a simple SNPC that chases nearby players and shoots at them. It's a pain in the ass.
My current ones don't seem to want to point their weapon when they shoot at players (which is odd since they do when i test on my local server, but nowhere else). I also tried to make them walk while shooting (to make them a little more challenging to kill) but I couldn't find a schedule for it (it has to be possible since the combine do it).
Here's the relevant code snippets. Some of this shit is pretty hacky. You have to manually make their weapon fire since they apparently don't do it themselves using valve's schedules.
[lua]
function ENT:Initialize()
self.Entity:SetHullSizeNormal()
self.Entity:SetHullType( HULL_HUMAN )
self.Entity:SetSolid( SOLID_BBOX )
self.Entity:SetMoveType( MOVETYPE_STEP )
self.Entity:SetMaxYawSpeed( 5000 )
self.Entity:SetHealth( 100 )
self.Entity:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_TURN_HEAD | CAP_USE_WEAPONS | CAP_AIM_GUN | CAP_WEAPON_RANGE_ATTACK1 | CAP_MOVE_SHOOT )
self.Entity:DropToFloor()
self.Entity:Give( "rad_npcgun" )
end
function ENT:Think()
if self.Entity:GetCurrentSchedule() == SCHED_RANGE_ATTACK1 then
local wep = self.Entity:GetActiveWeapon()
if ValidEntity( wep ) then
wep:PrimaryAttack()
end
end
end
function ENT:SelectSchedule()
local enemy = self.Entity:GetEnemy()
local sched = SCHED_IDLE_WANDER
if ValidEntity( enemy ) and enemy:GetPos():Distance( self.Entity:GetPos() ) < 2000 then
if self.Entity:HasCondition( 21 ) then // COND_CAN_RANGE_ATTACK1
sched = SCHED_RANGE_ATTACK1
else
sched = SCHED_CHASE_ENEMY
end
else
self.Entity:UpdateEnemy( self.Entity:FindEnemy() )
end
self.Entity:SetSchedule( sched )
self.Entity:SetCurrentSchedule( sched )
end
function ENT:SetCurrentSchedule( sched )
self.CurrSched = sched
end
function ENT:GetCurrentSchedule()
return self.CurrSched or SCHED_IDLE_WANDER
end[/lua]
Any suggestions on what i should do to make these SNPCs less retarded?
It would also be nice to have some enums for valve's conditions (ie. COND_CAN_RANGE_ATTACK1). As it is you have to use the numbers.
I don't think you can actually make them walk and shoot. I've never seen combine do it except sometimes they walk sideways a bit and shoot oddly.
I swear i remember combine running and firing when i played HL2.
[media]http://www.youtube.com/watch?v=rpg2oJWfsLQ[/media]
It would be nice to see the code behind combine soldiers.
As far as I know, the metrocop actually does that. He chases you when he has a mele weapon and shoots you when he has a gun. You could edit the scripts so he chases you while he has a gun...
The combines is coded in C++ though, i can grab the combine code in a second...
[editline]08:50AM[/editline]
Here, the condition list(i think its all)
[code]
//=========================================================
// These are the default shared conditions
//=========================================================
enum SCOND_t
{
COND_NONE, // A way for a function to return no condition to get
COND_IN_PVS,
COND_IDLE_INTERRUPT, // The schedule in question is a low priority idle, and therefore a candidate for translation into something else
COND_LOW_PRIMARY_AMMO,
COND_NO_PRIMARY_AMMO,
COND_NO_SECONDARY_AMMO,
COND_NO_WEAPON,
COND_SEE_HATE,
COND_SEE_FEAR,
COND_SEE_DISLIKE,
COND_SEE_ENEMY,
COND_LOST_ENEMY,
COND_ENEMY_WENT_NULL, // What most people think COND_LOST_ENEMY is: This condition is set in the edge case where you had an enemy last think, but don't have one this think.
COND_ENEMY_OCCLUDED, // Can't see m_hEnemy
COND_TARGET_OCCLUDED, // Can't see m_hTargetEnt
COND_HAVE_ENEMY_LOS,
COND_HAVE_TARGET_LOS,
COND_LIGHT_DAMAGE,
COND_HEAVY_DAMAGE,
COND_PHYSICS_DAMAGE,
COND_REPEATED_DAMAGE, // Damaged several times in a row
COND_CAN_RANGE_ATTACK1, // Hitscan weapon only
COND_CAN_RANGE_ATTACK2, // Grenade weapon only
COND_CAN_MELEE_ATTACK1,
COND_CAN_MELEE_ATTACK2,
COND_PROVOKED,
COND_NEW_ENEMY,
COND_ENEMY_TOO_FAR, // Can we get rid of this one!?!?
COND_ENEMY_FACING_ME,
COND_BEHIND_ENEMY,
COND_ENEMY_DEAD,
COND_ENEMY_UNREACHABLE, // Not connected to me via node graph
COND_SEE_PLAYER,
COND_LOST_PLAYER,
COND_SEE_NEMESIS,
COND_TASK_FAILED,
COND_SCHEDULE_DONE,
COND_SMELL,
COND_TOO_CLOSE_TO_ATTACK, // FIXME: most of this next group are meaningless since they're shared between all attack checks!
COND_TOO_FAR_TO_ATTACK,
COND_NOT_FACING_ATTACK,
COND_WEAPON_HAS_LOS,
COND_WEAPON_BLOCKED_BY_FRIEND, // Friend between weapon and target
COND_WEAPON_PLAYER_IN_SPREAD, // Player in shooting direction
COND_WEAPON_PLAYER_NEAR_TARGET, // Player near shooting position
COND_WEAPON_SIGHT_OCCLUDED,
COND_BETTER_WEAPON_AVAILABLE,
COND_HEALTH_ITEM_AVAILABLE, // There's a healthkit available.
COND_GIVE_WAY, // Another npc requested that I give way
COND_WAY_CLEAR, // I no longer have to give way
COND_HEAR_DANGER,
COND_HEAR_THUMPER,
COND_HEAR_BUGBAIT,
COND_HEAR_COMBAT,
COND_HEAR_WORLD,
COND_HEAR_PLAYER,
COND_HEAR_BULLET_IMPACT,
COND_HEAR_PHYSICS_DANGER,
COND_HEAR_MOVE_AWAY,
COND_HEAR_SPOOKY, // Zombies make this when Alyx is in darkness mode
COND_NO_HEAR_DANGER, // Since we can't use ~CONDITION. Mutually exclusive with COND_HEAR_DANGER
COND_FLOATING_OFF_GROUND,
COND_MOBBED_BY_ENEMIES, // Surrounded by a large number of enemies melee attacking me. (Zombies or Antlions, usually).
// Commander stuff
COND_RECEIVED_ORDERS,
COND_PLAYER_ADDED_TO_SQUAD,
COND_PLAYER_REMOVED_FROM_SQUAD,
COND_PLAYER_PUSHING,
COND_NPC_FREEZE, // We received an npc_freeze command while we were unfrozen
COND_NPC_UNFREEZE, // We received an npc_freeze command while we were frozen
// This is a talker condition, but done here because we need to handle it in base AI
// due to it's interaction with behaviors.
COND_TALKER_RESPOND_TO_QUESTION,
COND_NO_CUSTOM_INTERRUPTS, // Don't call BuildScheduleTestBits for this schedule. Used for schedules that must strictly control their interruptibility.
// ======================================
// IMPORTANT: This must be the last enum
// ======================================
LAST_SHARED_CONDITION
};[/code]
You may want to take a look at this
[url]http://npcaimod.googlecode.com/svn/trunk/NPC_AI[/url]
[QUOTE=Chancer;21189777]You may want to take a look at this
[url]http://npcaimod.googlecode.com/svn/trunk/NPC_AI[/url][/QUOTE]
that code/indentation makes me want to tear my eyes out of their sockets
[QUOTE=Rambo_9;21197297]that code/indentation makes me want to tear my eyes out of their sockets[/QUOTE]
Agreed.
Isn't there a way to force directional movement on NPC's? Why even make this an SNPC? Seems to me like you could solve most of these problems by making it a SENT.
first off it's "Agreed" not "Agree'd".
secondly, SNPCs are a variant of SENTs.
thirdly, why the hell would i make my SNPCs not use the AI base? That's a completely retarded idea.
[QUOTE=Rambo_9;21200582]firstoff it's "Agreed" not "Agree'd".
secondly, SNPCs are a variant of SENTs.
thirdly, why the hell would i make my SNPCs not use the AI base? That's a completely retarded idea.[/QUOTE]
No need to be an ass. I'm saying that what you're describing doesn't seem to require the level of AI that SNPCs are meant to support (not than anybody really uses it). I've seen plenty of SENTs accomplish the same thing. Chill out.
[QUOTE=grea$emonkey;21200622]I'm saying that what you're describing doesn't seem to require the level of AI that SNPCs are meant to support[/QUOTE]
what
You're suggesting that i create a SENT using base_anim to do the job of a SNPC using base_ai. Where is the logic in that?
Would i make my NPC a physics object that bounces around or something?
[QUOTE=Rambo_9;21200804]You're suggesting that i create a SENT using base_anim to do the job of a SNPC using base_ai. Where is the logic in that?
Would i make my NPC a physics object that bounces around or something?[/QUOTE]
Never mind. From what you said it sounded like you just wanted something that would run to nearby players and shoot them, which is something you don't really need AI for.
[QUOTE=grea$emonkey;21200983]Never mind. From what you said it sounded like you just wanted something that would run to nearby players and shoot them, which is something you don't really need AI for.[/QUOTE]
[IMG]http://i41.tinypic.com/235uo6.gif[/IMG]
[i]The GweaseMonkey Experience[/i]
[QUOTE=Rambo_9;21197297]that code/indentation makes me want to tear my eyes out of their sockets[/QUOTE]
What indendation? :v:
[img_thumb]http://i203.photobucket.com/albums/aa111/Hoffa1337/no_indendation.png?t=1270538152[/img_thumb]
Don't Dan's SNPCs move forwards while shooting? I swear to god that I saw them doing that...
Sorry, you need to Log In to post a reply to this thread.