Hello guys, I would like to ask for your help in solving one problem, if possible. I have a horse npc-entity, this is a very cool thing of the pack [url]http://steamcommunity.com/sharedfiles/filedetails/?id=104528277[/url] The problem is that when the player is attached to the horse he is still possible to spin on its axis, which is very hard to swallow when a third person, whether ak is locked in the same position?
[url=http://www.radikal.ru][img]http://s020.radikal.ru/i710/1403/7d/57dca2c6f693.jpg[/img][/url]
[B]Shared.lua[/B]
[CODE]ENT.Base = "npc_creature_base"
ENT.Type = "ai"
function ENT:Interaction()
local ent = self:GetNetworkedEntity("mount")
if(ent:IsValid() && ent == LocalPlayer()) then return "Dismount" end
return "Mount"
end
function ENT:CanInteract(pl)
local ent = pl:GetNetworkedEntity("mount")
if(!ent:IsValid() || ent == self) then return true end
return false
end
ENT.PrintName = "Horse"
ENT.Category = "Skyrim"
//ENT.NPCID = "0005PQS3"
function ENT:IsMounted() return self:GetNetworkedBool("mounted") end
hook.Add("CalcMainActivity","playermount",function(pl,vel)
local ent = pl:GetNetworkedEntity("mount")
if(ent:IsValid()) then return ACT_IDLE_CROUCH_KNIFE,-1 end
end)
function ENT:Name()
local owner = self:GetNetworkedEntity("plOwner")
if(owner:IsValid()) then return owner:GetName() .. "'s Horse" end
return "Horse"
end
if(CLIENT) then
language.Add("npc_horse","Horse")
hook.Add("CalcCamOrigin","playermount",function()
local pl = LocalPlayer()
local ent = pl:GetNetworkedEntity("mount")
if(ent:IsValid()) then
local att = ent:LookupAttachment("mount")
att = ent:GetAttachment(att)
if(att) then
return att.Pos +Vector(0,0,20)
end
end
end)
end[/CODE]
[B]init.lua[/B]
[CODE]AddCSLuaFile("shared.lua")
include('shared.lua')
local _R = debug.getregistry()
_R.NPCFaction.Create("NPC_FACTION_PLAYER","npc_horse")
ENT.NPCFaction = NPC_FACTION_PLAYER
ENT.iClass = CLASS_PLAYER_ALLY
util.AddNPCClassAlly(CLASS_PLAYER_ALLY,"npc_horse")
ENT.sModel = "models/skyrim/horse.mdl"
ENT.fMeleeDistance = 60
ENT.fSearchDistance = 600
ENT.bFlinchOnDamage = false
ENT.m_bKnockDownable = true
ENT.DontPossess = true
ENT.BoneRagdollMain = "NPC Root [Root]"
ENT.skName = "horse"
ENT.bPlayDeathSequence = false
ENT.UseActivityTranslator = true
ENT.UseCustomMovement = false
ENT.m_bDontGetBurnt = true
ENT.HullNav = HULL_WIDE_SHORT
ENT.CollisionBounds = Vector(46,46,88)
ENT.iBloodType = BLOOD_COLOR_RED
ENT.sSoundDir = "npc/horse/"
local tbSounds = {
["Attack"] = "horse_attack0[1-2].mp3",
["Death"] = "horse_death0[1-2].mp3",
["Dismount"] = "horse_dismount01.mp3",
["Graze"] = "horse_idle_graze0[1-3].mp3",
["Idle"] = {"horse_idle_head01_a0[1-3].mp3","horse_idle_head01_b0[1-3].mp3"},
["HeadShake"] = "horse_idle_headshake0[1-2].mp3",
["Paw"] = "horse_idle_paw01.mp3",
["Tail"] = "horse_idle_tail0[1-3].mp3",
["Pain"] = "horse_injured0[1-3].mp3",
["Mount"] = "horse_mount01.mp3",
["RearUp"] = "horse_rearup0[1-3].mp3",
["FootWalkFront"] = "foot/horse_walk_front0[1-6].mp3",
["FootWalkBack"] = "foot/horse_walk_back0[1-6].mp3",
["FootSprintFront"] = "foot/horse_sprint_front0[1-6].mp3",
["FootSprintBack"] = "foot/horse_sprint_back0[1-6].mp3"
}
function ENT:GetSoundEvents() return tbSounds end
function ENT:OnInit()
self:SetHullType(HULL_WIDE_SHORT)
self:SetHullSizeNormal()
self:SetCollisionBounds(self.CollisionBounds,Vector(self.CollisionBounds.x *-1,self.CollisionBounds.y *-1,0))
self:CapabilitiesAdd(CAP_MOVE_GROUND)
self:SetHealth(GetConVarNumber("sk_" .. self.skName .. "_health"))
self.m_bMounted = false
self.m_exhaustion = 0
local cspLoop = CreateSound(self,self.sSoundDir .. "horse_breathe0" .. math.random(1,2) .. "_lp.wav")
cspLoop:SetSoundLevel(58)
cspLoop:Play()
self.cspBreathe = cspLoop
self:StopSoundOnDeath(cspLoop)
self:SetSkin(math.random(1,4))
self:SetUseType(SIMPLE_USE)
end
function ENT:OnUse(activator,caller,type,value)
if(self:Disposition(activator) == D_LI) then
if(!GAMEMODE.Aftermath) then self:Mount(activator)
else
activator:HolsterWeapon(function()
if(activator:Alive() && self:OBBDistance(activator) <= 60) then
self:Mount(activator)
end
end)
end
end
end
function ENT:Mount(pl)
if(self:IsMounted() || !pl:Alive()) then return end
if(gamemode.Call("CanPlayerMount",pl,self) == true) then return end
self:PlaySound("Mount")
self:SetBodygroup(1,1)
self:SetOwner(pl)
local owner = self:GetNetworkedEntity("plOwner")
if(!owner:IsValid()) then self:SetNetworkedEntity("plOwner",pl) end
self:SetNetworkedEntity("mount",pl)
self:SetNetworkedBool("mounted",true)
self.m_turnSpeed = 0
self.m_tMounted = CurTime()
pl:SetNetworkedEntity("mount",self)
//pl:Spectate(OBS_MODE_CHASE)
pl:DrawViewModel(false)
pl:DrawWorldModel(false)
//pl:SpectateEntity(ent)
//pl:SetMoveType(MOVETYPE_OBSERVER)
if(GAMEMODE.Aftermath) then
pl:SetHUDTarget(self)
hook.Add("CanPlayerEquip","horsenoequip" .. self:EntIndex(),function(plTgt,item,cnd)
if(plTgt == pl) then if(!item) then return true end end
end)
pl:SetParent(self)
pl:Fire("SetParentAttachment","mount",0)
pl:AddEffects(EF_BONEMERGE)
else
local pos = self:GetPos()
pl:SetPos(pos +self:GetUp() *40 +self:GetForward() *6)
pl:SetParent(self)
pl:Fire("SetParentAttachmentMaintainOffset","mount",0)
end
end
function ENT:Dismount()
if(!self:IsMounted()) then return end
if(GAMEMODE.Aftermath) then hook.Remove("CanPlayerEquip","horsenoequip" .. self:EntIndex()) end
local pl = self:GetOwner()
if(IsValid(pl)) then
self:PlaySound("Dismount")
local forward = self:GetForward()
local right = self:GetRight()
local tbCheck = {right,right *-1,forward,forward *-1}
local pos = self:GetPos() +self:OBBCenter()
local posTgt
local min,max = pl:OBBMins(),pl:OBBMaxs()
for _,dir in ipairs(tbCheck) do
posTgt = pos +dir *88 +Vector(0,0,50)
local tr = util.TraceHull({
start = pos,
endpos = posTgt,
mins = min,
maxs = max,
filter = {self,pl},
mask = MASK_PLAYERSOLID
})
if(!tr.Hit) then break
elseif(_ == 4) then return end
end
pl:SetParent()
self:SetNetworkedEntity("mount",NULL)
pl:SetNetworkedEntity("mount",NULL)
if(GAMEMODE.Aftermath) then
pl:RemoveEffects(EF_BONEMERGE)
pl:ClearHUDTarget(self)
end
//pl:UnSpectate()
pl:DrawViewModel(true)
pl:DrawWorldModel(true)
//pl:SetMoveType(MOVETYPE_OBSERVER)
pl:SetMoveType(MOVETYPE_WALK)
if(pl:Alive()) then
local ang = self:GetAngles()
ang.r = 0
ang.p = 0
//pl:KillSilent()
//pl:Spawn()
pl:SetPos(posTgt)
pl:SetAngles(ang)
pl:DropToFloor()
end
end
self.m_tMounted = nil
self.bInSchedule = nil
self:SetBodygroup(1,0)
self:SetNetworkedBool("mounted",false)
self.m_turnSpeed = nil
self.m_bExhausted = nil
self:ChangeBreathVolume(58)
self:SetOwner()
local ang = self:GetAngles()
if(ang.p != 0 || ang.r != 0) then self:SetAngles(Angle(0,ang.y,0)) end
end
function ENT:_PossStart(pl)
self:Mount(pl)
end
function ENT:_PossEnd(pl)
self:Dismount(pl)
end
function ENT:OnKnockedDown()
self:Dismount()
end
function ENT:OnDeath(dmginfo)
self:Dismount()
end
function ENT:Removed()
self:Dismount()
end
function ENT:ChangeBreathVolume(vol)
self.cspBreathe:Stop()
self.cspBreathe:SetSoundLevel(vol)
self.cspBreathe:Play()
end
function ENT:_PossMovement() // Movement is handled through MountThink
end
function ENT:MountThink()
local act = self:GetActivity()
if(self.bInSchedule) then
if(act != ACT_LAND && act != ACT_STAND) then
local vel = self:GetVelocity()
if(vel.z > 0) then self:SetGroundEntity(NULL); return end
local pos = self:GetPos()
local tr = util.TraceLine({
start = pos,
endpos = pos +vel *0.25,
filter = self,
mask = MASK_NPCSOLID
})
if((vel.z == 0 && (CurTime() -self.m_tJumpStart) >= 1) || tr.Hit) then
local len = vel:Length()
if(len > 710) then
self:PlaySound("Pa
Message the developer
[QUOTE=AnonTakesOver;44395216]Message the developer[/QUOTE]
Unfortunately he is no longer involved Gmod :(
Sorry, you need to Log In to post a reply to this thread.