• Making a NPC run
    1 replies, posted
I have a NPC that walks around minding it's own business, and when it spots me it is supposed to run away, but it just walks away. How do I make it run away when it sees me? Code as it is: AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self:SetModel("models/player/chewie.mdl") self:SetHullType(HULL_HUMAN) self:SetHullSizeNormal() self:SetNPCState(NPC_STATE_SCRIPT) self:SetSolid(SOLID_BBOX) self:CapabilitiesAdd(CAP_MOVE_GROUND) self:SetUseType(SIMPLE_USE) self:SetMoveType(MOVETYPE_STEP) self:DropToFloor() end function ENT:GetRelationship(entity) if (entity:IsPlayer() and entity:Team() == 102) then return D_FR else return D_LI  end end
Assuming this is a nextbot, you would use the self:StartActivity( ) to make it do the animation you want, as for making it detect you, you would need to make it in a think function every second or so to reduce lag, and have it scan for players in its area using the ents:findinsphere or ents:findincone (not sure if thats the actual name of the functions but probably that) check the distance, use DistToSqr then just do your distance number times itself to reduce lag some more since this will be called very very often. Then make it find a random position away from the player, check if it is valid with navmeshes, and if so, run there at a faster speed, if not, recalculate a path.
Sorry, you need to Log In to post a reply to this thread.