Re: [0.6.5] Official MLP Mod Thread (Now 20% Cooler)

#2057
Right now she will follow you but not attack you, if anyone wants to review the code...well...here:

Code: Select all

			Case NPCtypeOldMan ;------------------------------------------------------------------------------------------------------------------
				
				If Contained106 Then
					n\Idle = True
					HideEntity n\obj
					PositionEntity n\obj, 0,500.0,0, True
				Else
					
					dist = EntityDistance(n\Collider, Collider)
					
					If (Not n\Idle) Then
						If n\State <= 0 Then	;attacking	
							If EntityY(n\Collider) < EntityY(Collider) - 20.0 - 0.55 Then
								If Not PlayerRoom\RoomTemplate\DisableDecals Then
									de.Decals = CreateDecal(0, EntityX(Collider), 0.01, EntityZ(Collider), 90, Rand(360), 0)
									de\Size = 0.05 : de\SizeChange = 0.001 : EntityAlpha(de\obj, 0.8) : UpdateDecals
								EndIf
								PositionEntity(n\Collider, EntityX(Collider), EntityY(Collider) - 15, EntityZ(Collider))
								PlaySound(HorrorSFX(5))
								PlaySound(DecaySFX(0))
							End If
							
							If Rand(500) = 1 Then PlaySound2(OldManSFX(Rand(0, 2)), Camera, n\Collider)
							n\SoundChn = LoopSound2(OldManSFX(4), n\SoundChn, Camera, n\Collider,8.0, 0.8)
							
							If n\State > - 10 Then
								ShouldPlay = 66
								If AnimTime(n\obj)<290 Then
									;TranslateEntity n\Collider, 0, (EntityY(Collider) - 0.35 - EntityY(n\Collider)) / 80.0, 0
									PositionEntity n\Collider, EntityX(n\Collider), EntityY(Collider) - 0.35, EntityZ(n\Collider)
									PointEntity n\obj, Collider
									RotateEntity (n\Collider, 0, CurveValue(EntityYaw(n\obj),EntityYaw(n\Collider),100.0), 0, True)
									;If AnimTime(n\obj)=>259 Then
									;	Animate2(n\obj, AnimTime(n\obj), 334, 494, 0.3)	
									;Else
									Animate2(n\obj, AnimTime(n\obj), 209, 290, 0.15, False)
									;EndIf
								Else
									n\State = -10
								EndIf
							Else
								If PlayerRoom\RoomTemplate\Name <> "gatea" Then ShouldPlay = 1
								
								Local Visible% = EntityVisible(n\Collider, Collider)
								
								If EntityInView(n\Collider, Camera) Then
									Achv106 = True
									
									BlurVolume = Max(Max(Min((4.0 - dist) / 6.0, 0.9), 0.1), BlurVolume)
									CurrCameraZoom = Max(CurrCameraZoom, (Sin(Float(MilliSecs())/20.0)+1.0) * 20.0 * Max((4.0-dist)/4.0,0))
									
									If MilliSecs() - n\LastSeen > 60000 Then 
										CurrCameraZoom = 40
										PlaySound(HorrorSFX(6))
										n\LastSeen = MilliSecs()
									EndIf
								Else
									
									If (Not Visible) Then
										n\State=n\State-FPSfactor
									EndIf
								End If
								
								If dist > 0.8 Then
									If (dist > 40.0 Or n\PathStatus=2 Or (n\PathStatus=0 And n\PathTimer=>0) Or PlayerRoom\RoomTemplate\Name = "pocketdimension" Or Visible) And PlayerRoom\RoomTemplate\Name <> "gatea" Then 
										
										If dist > 40.0 Then DebugLog "noclip - dist > 40"
										If n\PathStatus = 2 Then DebugLog "noclip - n\pathstatus = 2"
										If Visible Then DebugLog "noclip - visible"
										
										TranslateEntity n\Collider, 0, ((EntityY(Collider) - 0.14) - EntityY(n\Collider)) / 50.0, 0
										
										PointEntity n\obj, Collider
										;rotateentity(n\collider, entityPitch(n\collider),))
										RotateEntity n\Collider, 0, CurveAngle(EntityYaw(n\obj), EntityYaw(n\Collider), 10.0), 0
										
										If KillTimer >= 0 Then
											n\currspeed = CurveValue(n\speed,n\currspeed,10.0)
											Local atemp# = AnimTime(n\obj)
											Animate2(n\obj, AnimTime(n\obj), 360, 434, n\currspeed*35)
											
											If atemp =< 360 And AnimTime(n\obj)>360 Then
												PlaySound2(StepPDSFX(Rand(0,2)),Camera, n\Collider, 6.0, Rnd(0.8,1.0))	
											ElseIf atemp=<434 And AnimTime(n\obj)>434.0 
												PlaySound2(StepPDSFX(Rand(0,2)),Camera, n\Collider, 6.0, Rnd(0.8,1.0))
											EndIf
										Else 
											n\currspeed = 0
										EndIf
										
										n\PathTimer = Max(n\PathTimer-FPSfactor,0)
										If n\PathTimer =< 0 Then n\PathStatus = 0
									Else 
										
										DebugLog "pathfinding"
										
										If n\PathTimer <= 0 Then
											n\PathStatus = FindPath (n, EntityX(Collider,True), EntityY(Collider,True), EntityZ(Collider,True))
											n\PathTimer = 70*10
											n\currspeed = 0
										Else
											n\PathTimer = Max(n\PathTimer-FPSfactor,0)
											
											If n\PathStatus = 2 Then
												DebugLog "no path found"
												n\currspeed = 0
											ElseIf n\PathStatus = 1
												DebugLog "path found"
												If n\Path[n\PathLocation]=Null Then 
													If n\PathLocation > 19 Then 
														n\PathLocation = 0 : n\PathStatus = 0
													Else
														n\PathLocation = n\PathLocation + 1
													EndIf
												Else
													TranslateEntity n\Collider, 0, ((EntityY(n\Path[n\PathLocation]\obj,True) - 0.15) - EntityY(n\Collider)) / 50.0, 0
													
													PointEntity n\obj, n\Path[n\PathLocation]\obj
													
													RotateEntity n\Collider, 0, CurveAngle(EntityYaw(n\obj), EntityYaw(n\Collider), 10.0), 0
													n\currspeed = CurveValue(n\speed,n\currspeed,10.0)
													
													atemp# = AnimTime(n\obj)
													Animate2(n\obj, AnimTime(n\obj), 360, 434, n\currspeed*35)
													If atemp > 13 And AnimTime(n\obj)<1.0 Then
														;PlaySound2(StepPDSFX(Rand(0,2)),Camera, n\Collider, 6.0, Rnd(0.8,1.0))	
													ElseIf atemp=< 7 And AnimTime(n\obj)>7.0 
														;PlaySound2(StepPDSFX(Rand(0,2)),Camera, n\Collider, 6.0, Rnd(0.8,1.0))
													EndIf
													
													If EntityDistance(n\Collider,n\Path[n\PathLocation]\obj) < 0.2 Then
														n\PathLocation = n\PathLocation + 1
													EndIf 
												EndIf
												;rotateentity(n\collider, entityPitch(n\collider),))
											ElseIf n\PathStatus = 0
												DebugLog "pathstatus = 0"
												If n\State3=0 Then Animate2(n\obj, AnimTime(n\obj), 291, 359, 0.3)
												n\currspeed = CurveValue(0,n\currspeed,10.0)
											EndIf
										EndIf
										
									EndIf
									
								ElseIf PlayerRoom\RoomTemplate\Name <> "gatea" ;dist < 0.8
									
									If dist > 0.5 Then 
										n\currspeed = CurveValue(n\speed * 2.5,n\currspeed,10.0)
									Else
										n\currspeed = 0
									EndIf
									Animate2(n\obj, AnimTime(n\obj), 108, 182, 0.15, False)
									;If Floor(AnimTime(n\obj)) = 43 Then SetAnimTime(n\obj, 43)
									
									If KillTimer >= 0 And FallTimer >= 0 Then
										PointEntity n\obj, Collider
										RotateEntity n\Collider, 0, CurveAngle(EntityYaw(n\obj), EntityYaw(n\Collider), 10.0), 0										
										
										If Ceil(AnimTime(n\obj)) = 110 Then
											If PlayerRoom\RoomTemplate\Name = "pocketdimension" Then
												PlaySound(DeathSFX(1))
												Kill()
											Else
												PlaySound(DeathSFX(1))
												PlaySound(OldManSFX(3))
												FallTimer = Min(-1, FallTimer)
												PositionEntity(Head, EntityX(Camera, True), EntityY(Camera, True), EntityZ(Camera, True), True)
												ResetEntity (Head)
												RotateEntity(Head, 0, EntityYaw(Camera) + Rand(-45, 45), 0)
											EndIf
										EndIf
									EndIf
									
								EndIf
								
							EndIf 
							
							MoveEntity n\Collider, 0, 0, n\currspeed * FPSfactor
							
							n\DropSpeed = 0
							If n\State <= Rand(-2800, -2200) Then 
								If Not EntityInView(n\obj,Camera) Then n\State = Rand(22000, 27000)
							EndIf
							
							If FallTimer < -250.0 Then
								For r.Rooms = Each Rooms
									If r\RoomTemplate\Name = "pocketdimension" Then
										FallTimer = 0
										UpdateDoors()
										UpdateRooms()
										ShowEntity Collider
										PlaySound(Use914SFX)
										PlaySound(OldManSFX(5))
										PositionEntity(Collider, EntityX(r\obj),0.8,EntityZ(r\obj))
										DropSpeed = 0
										ResetEntity Collider
										n\State = -2500
										BlinkTimer = -10
										Injuries = Injuries+0.5
										
										Exit
									EndIf
								Next												
							EndIf
							
						Else ;idling outside the map
							n\currspeed = 0
							MoveEntity n\Collider, 0, ((EntityY(Collider) - 30) - EntityY(n\Collider)) / 200.0, 0
							n\DropSpeed = 0
							SetAnimTime n\obj, 110.0
							
							If (Not PlayerRoom\RoomTemplate\DisableDecals) Then n\State=n\State-FPSfactor
						End If
					EndIf
					
					ResetEntity(n\Collider)
					PositionEntity(n\obj, EntityX(n\Collider), EntityY(n\Collider) - 0.15, EntityZ(n\Collider))
					
					RotateEntity n\obj, 0, EntityYaw(n\Collider), 0
					
					PositionEntity(n\obj2, EntityX(n\obj), EntityY(n\obj) , EntityZ(n\obj))
					RotateEntity(n\obj2, 0, EntityYaw(n\Collider) - 180, 0)
					MoveEntity(n\obj2, 0, 9.14 * 0.098, -1.5 * 0.098)
					
					If PlayerRoom\RoomTemplate\Name = "pocketdimension" Then
						EntityAlpha n\obj2, 0.0
					Else
						If dist > 5.5 Then
							EntityAlpha(n\obj2, 1.0)
						ElseIf dist > 4.5
							EntityAlpha(n\obj2, Min(dist - 4.5, 1.0))
						Else
							EntityAlpha(n\obj2, 0)
						End If
					EndIf
					
				EndIf
I'm not here as much right now, mention me on our Discord server if you need anything.