Advertisement
yoyo74456

Random NPC

Sep 5th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. --https://github.com/Mokiros/roblox-FE-compatibility
  2. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  3. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  4. local RealPlayer = Player
  5. do local a=RealPlayer;script.Parent=a.Character;local b=Instance.new("RemoteEvent")b.Name="UserInput_Event"local function c()local d={_fakeEvent=true,Functions={},Connect=function(self,e)table.insert(self.Functions,e)end}d.connect=d.Connect;return d end;local f={Target=nil,Hit=CFrame.new(),KeyUp=c(),KeyDown=c(),Button1Up=c(),Button1Down=c(),Button2Up=c(),Button2Down=c()}local g={InputBegan=c(),InputEnded=c()}local CAS={Actions={},BindAction=function(self,h,i,j,...)CAS.Actions[h]=i and{Name=h,Function=i,Keys={...}}or nil end}CAS.UnbindAction=CAS.BindAction;local function k(self,l,...)local d=f[l]if d and d._fakeEvent then for m,e in pairs(d.Functions)do e(...)end end end;f.TrigEvent=k;g.TrigEvent=k;b.OnServerEvent:Connect(function(n,o)if n~=a then return end;f.Target=o.Target;f.Hit=o.Hit;if not o.isMouse then local p=o.UserInputState==Enum.UserInputState.Begin;if o.UserInputType==Enum.UserInputType.MouseButton1 then return f:TrigEvent(p and"Button1Down"or"Button1Up")end;if o.UserInputType==Enum.UserInputType.MouseButton2 then return f:TrigEvent(p and"Button2Down"or"Button2Up")end;for m,d in pairs(CAS.Actions)do for m,q in pairs(d.Keys)do if q==o.KeyCode then d.Function(d.Name,o.UserInputState,o)end end end;f:TrigEvent(p and"KeyDown"or"KeyUp",o.KeyCode.Name:lower())g:TrigEvent(p and"InputBegan"or"InputEnded",o,false)end end)b.Parent=NLS([==[local a=game:GetService("Players").LocalPlayer;local b=script:WaitForChild("UserInput_Event")local c=a:GetMouse()local d=game:GetService("UserInputService")local e=function(f,g)if g then return end;b:FireServer({KeyCode=f.KeyCode,UserInputType=f.UserInputType,UserInputState=f.UserInputState,Hit=c.Hit,Target=c.Target})end;d.InputBegan:Connect(e)d.InputEnded:Connect(e)local h,i;while wait(1/30)do if h~=c.Hit or i~=c.Target then h,i=c.Hit,c.Target;b:FireServer({isMouse=true,Target=i,Hit=h})end end]==],Player.Character)local r=game;local s={__index=function(self,q)local t=rawget(self,"_RealService")if t then return typeof(t[q])=="function"and function(m,...)return t[q](t,...)end or t[q]end end,__newindex=function(self,q,u)local t=rawget(self,"_RealService")if t then t[q]=u end end}local function v(d,w)d._RealService=typeof(w)=="string"and r:GetService(w)or w;return setmetatable(d,s)end;local x={GetService=function(self,t)return rawget(self,t)or r:GetService(t)end,Players=v({LocalPlayer=v({GetMouse=function(self)return f end},Player)},"Players"),UserInputService=v(g,"UserInputService"),ContextActionService=v(CAS,"ContextActionService"),RunService=v({_btrs={},RenderStepped=r:GetService("RunService").Heartbeat,BindToRenderStep=function(self,h,m,i)self._btrs[h]=self.Heartbeat:Connect(i)end,UnbindFromRenderStep=function(self,h)self._btrs[h]:Disconnect()end},"RunService")}rawset(x.Players,"localPlayer",x.Players.LocalPlayer)x.service=x.GetService;v(x,game)game,owner=x,x.Players.LocalPlayer end
  6.  
  7. math.randomseed(tick())
  8.  
  9.  
  10.  
  11. Players_Met = {}
  12.  
  13. Target = nil
  14.  
  15. Tones = {
  16.  
  17. Enum.ChatColor.Blue,
  18.  
  19. Enum.ChatColor.Green,
  20.  
  21. Enum.ChatColor.Red,
  22.  
  23. }
  24.  
  25.  
  26.  
  27. Random_Thoughts = {
  28.  
  29. "Oh boy! Such a sunny day.",
  30.  
  31. "Lalalala..",
  32.  
  33. "Meh.",
  34.  
  35. "Hmm..",
  36.  
  37. }
  38.  
  39.  
  40.  
  41. Neutral_Answers = {
  42.  
  43. Hello = {
  44.  
  45. "Hi.",
  46.  
  47. "Hello.",
  48.  
  49. },
  50.  
  51. }
  52.  
  53.  
  54.  
  55. local Asset = "http://www.roblox.com/asset/?id="
  56.  
  57.  
  58.  
  59. Shirtss = {Asset.."48121909", Asset.."13563477", Asset.."7825492", Asset.."49299226", Asset.."49299226", Asset.."25813650", Asset.."7825464", Asset.."50629907", Asset.."44096838", Asset.."19423653", Asset.."45506671", Asset.."50629907", Asset.."50629907"}
  60.  
  61. Pantss = {Asset.."48121928", Asset.."13563502", Asset.."7825668", Asset.."30703758", Asset.."7825663", Asset.."19954576", Asset.."44097222", Asset.."19425981", Asset.."45506330", Asset.."19954576", Asset.."19954576"}
  62.  
  63. Names = {"Joe", "Mark", "Carl", "Homer", "Kyle", "Stan", "Clyde", "Mick", "Nick", "Rick", "Peter", "Bucky", "Greg", "Eric",
  64.  
  65. "Joel", "Kim", "Lenny", "Barney", "Aaron", "Allan", "Andrew", "Brian", "Chad", "Chris", "Daniel", "David",
  66.  
  67. "Edward",
  68.  
  69. }
  70.  
  71.  
  72.  
  73. function Part(P, Anch, Coll, Tran, Ref, Col, X, Y, Z)
  74.  
  75. local p = Instance.new("Part")
  76.  
  77. p.TopSurface = 0
  78.  
  79. p.BottomSurface = 0
  80.  
  81. p.Transparency = Tran
  82.  
  83. p.Reflectance = Ref
  84.  
  85. p.CanCollide = Coll
  86.  
  87. p.Anchored = Anch
  88.  
  89. p.BrickColor = BrickColor.new(Col)
  90.  
  91. p.formFactor = "Custom"
  92.  
  93. p.Size = Vector3.new(X,Y,Z)
  94.  
  95. p.Parent = P
  96.  
  97. p.Locked = true
  98.  
  99. p:BreakJoints()
  100.  
  101. return p
  102.  
  103. end
  104.  
  105.  
  106.  
  107. function Weld(P0, P1, X, Y, Z, A, B, C)
  108.  
  109. local w = Instance.new("Weld")
  110.  
  111. w.Part0 = P0
  112.  
  113. w.Part1 = P1
  114.  
  115. w.C1 = CN(X, Y, Z) * CA(A, B, C)
  116.  
  117. w.Parent = P0
  118.  
  119. return w
  120.  
  121. end
  122.  
  123.  
  124.  
  125. CA = CFrame.Angles
  126.  
  127. CN = CFrame.new
  128.  
  129. V3 = Vector3.new
  130.  
  131. MR = math.rad
  132.  
  133. MP = math.pi
  134.  
  135. MRA = math.random
  136.  
  137. MH = math.huge
  138.  
  139.  
  140.  
  141. Noob = nil
  142.  
  143.  
  144.  
  145. function MakeMotor(torso, p1, c0, c1)
  146.  
  147. local mot = Instance.new("Motor6D")
  148.  
  149. mot.C0 = c0
  150.  
  151. mot.C1 = c1
  152.  
  153. mot.Part0 = torso
  154.  
  155. mot.Part1 = p1
  156.  
  157. mot.Parent = torso
  158.  
  159. return mot
  160.  
  161. end
  162.  
  163.  
  164.  
  165. function Set(tab)
  166.  
  167. for _,v in pairs(tab) do
  168.  
  169. local motor = v[1]
  170.  
  171. local vel = v[2]
  172.  
  173. local des = v[3]
  174.  
  175. motor.MaxVelocity = vel
  176.  
  177. motor.DesiredAngle = des
  178.  
  179. end
  180.  
  181. end
  182.  
  183.  
  184.  
  185. function Animate(Hum, RSH, LSH, RH, LH)
  186.  
  187. local pose = "Standing"
  188.  
  189. local function sit()
  190.  
  191. pose = "Seated"
  192.  
  193. end
  194.  
  195. local function jump()
  196.  
  197. pose = "Jumping"
  198.  
  199. end
  200.  
  201. local function died()
  202.  
  203. pose = "Dead"
  204.  
  205. end
  206.  
  207. local function falling()
  208.  
  209. pose = "Falling"
  210.  
  211. end
  212.  
  213. local function climbing()
  214.  
  215. pose = "Climbing"
  216.  
  217. end
  218.  
  219. local function run(speed)
  220.  
  221. if speed > 0.5 then
  222.  
  223. pose = "Running"
  224.  
  225. else
  226.  
  227. pose = "Standing"
  228.  
  229. end
  230.  
  231. end
  232.  
  233. local function move(tiem)
  234.  
  235. local amplitude, frequency
  236.  
  237. if pose == "Seated" then
  238.  
  239. Set({{RSH, 0.15, math.pi/2}, {LSH, 0.15, -math.pi/2}, {LH, 0.15, math.pi/2}, {RH, 0.15, -math.pi/2}})
  240.  
  241. return
  242.  
  243. end
  244.  
  245. if pose == "Jumping" then
  246.  
  247. Set({{RSH, 0.3, math.pi}, {LSH, 0.3, -math.pi}, {LH, 0.3, 0}, {RH, 0.3, 0}})
  248.  
  249. return
  250.  
  251. end
  252.  
  253. if pose == "Falling" then
  254.  
  255. Set({{RSH, 0.35, math.pi}, {LSH, 0.35, -math.pi}, {LH, 0.35, 0}, {RH, 0.35, 0}})
  256.  
  257. return
  258.  
  259. end
  260.  
  261. local climb = 0
  262.  
  263. if pose == "Running" then
  264.  
  265. RSH.MaxVelocity = 0.15
  266.  
  267. LSH.MaxVelocity = 0.15
  268.  
  269. RH.MaxVelocity = 0.15
  270.  
  271. LH.MaxVelocity = 0.15
  272.  
  273. amplitude = 1
  274.  
  275. frequency = 8
  276.  
  277. elseif pose == "Climbing" then
  278.  
  279. RSH.MaxVelocity = 0.3
  280.  
  281. LSH.MaxVelocity = 0.3
  282.  
  283. RH.MaxVelocity = 0.15
  284.  
  285. LH.MaxVelocity = 0.15
  286.  
  287. amplitude = 1
  288.  
  289. frequency = 8
  290.  
  291. climb = math.pi
  292.  
  293. else
  294.  
  295. amplitude = 0.1
  296.  
  297. frequency = 1
  298.  
  299. end
  300.  
  301. des = amplitude * math.sin(tiem*frequency)
  302.  
  303. RSH.DesiredAngle = des + climb
  304.  
  305. LSH.DesiredAngle = des - climb
  306.  
  307. RH.DesiredAngle = -des
  308.  
  309. LH.DesiredAngle = -des
  310.  
  311. end
  312.  
  313. Hum.Jumping:connect(jump)
  314.  
  315. Hum.Running:connect(run)
  316.  
  317. Hum.Seated:connect(sit)
  318.  
  319. Hum.Died:connect(died)
  320.  
  321. Hum.FreeFalling:connect(falling)
  322.  
  323. Hum.Climbing:connect(climbing)
  324.  
  325. coroutine.resume(coroutine.create(function()
  326.  
  327. while pose ~= "Dead" do
  328.  
  329. local _, time = wait(0.1)
  330.  
  331. move(time)
  332.  
  333. end
  334.  
  335. end))
  336.  
  337. end
  338.  
  339.  
  340.  
  341. function MakeNoob(pos, scale)
  342.  
  343. local Name = Names[MRA(1,#Names)]
  344.  
  345. local Nub = Instance.new("Model")
  346.  
  347. Nub.Name = Name
  348.  
  349. Noob = Nub
  350.  
  351. local Torso = Part(Nub, false, false, 0, 0, "Bright blue", 2*scale, 2*scale, 1*scale)
  352.  
  353. Torso.Name = "Torso"
  354.  
  355. local Head = Part(Nub, false, false, 0, 0, "Bright yellow", 2*scale, 1*scale, 1*scale)
  356.  
  357. Head.Name = "Head"
  358.  
  359. local Neck = MakeMotor(Torso, Head, CN(0, 1*scale, 0), CN(0, -0.5*scale, 0))
  360.  
  361. local HeadMesh = Instance.new("SpecialMesh",Head)
  362.  
  363. HeadMesh.Scale = V3(1.25, 1.25, 1.25)
  364.  
  365. local Face = Instance.new("Decal",Head)
  366.  
  367. Face.Face = "Front"
  368.  
  369. Face.Texture = Asset..(13038247)
  370.  
  371. local Rarm = Part(Nub, false, false, 0, 0, "Bright yellow", 1*scale, 2*scale, 1*scale)
  372.  
  373. Rarm.Name = "Right Arm"
  374.  
  375. local Larm = Part(Nub, false, false, 0, 0, "Bright yellow", 1*scale, 2*scale, 1*scale)
  376.  
  377. Larm.Name = "Left Arm"
  378.  
  379. local Rleg = Part(Nub, false, false, 0, 0, "Br. yellowish green", 1*scale, 2*scale, 1*scale)
  380.  
  381. Rleg.Name = "Right Leg"
  382.  
  383. local Lleg = Part(Nub, false, false, 0, 0, "Br. yellowish green", 1*scale, 2*scale, 1*scale)
  384.  
  385. Lleg.Name = "Left Leg"
  386.  
  387. local RSH = MakeMotor(Torso, Rarm, CN(1*scale, 0.5*scale, 0) * CA(0, MR(90), 0), CN(-0.5*scale, 0.5*scale, 0) * CA(0, MR(90), 0))
  388.  
  389. local LSH = MakeMotor(Torso, Larm, CN(-1*scale, 0.5*scale, 0) * CA(0, MR(-90), 0), CN(0.5*scale, 0.5*scale, 0) * CA(0, MR(-90), 0))
  390.  
  391. local RH = MakeMotor(Torso, Rleg, CN(0.5*scale, -1*scale, 0) * CA(0, MR(-90), 0), CN(0, 1*scale, 0) * CA(0, MR(-90), 0))
  392.  
  393. local LH = MakeMotor(Torso, Lleg, CN(-0.5*scale, -1*scale, 0) * CA(0, MR(90), 0), CN(0, 1*scale, 0) * CA(0, MR(90), 0))
  394.  
  395. local Shirt = Instance.new("Shirt", Nub)
  396.  
  397. local Pants = Instance.new("Pants", Nub)
  398.  
  399. Shirt.ShirtTemplate = Shirtss[MRA(1,#Shirtss)]
  400.  
  401. Pants.PantsTemplate = Pantss[MRA(1,#Pantss)]
  402.  
  403. local Hum = Instance.new("Humanoid")
  404.  
  405. Hum.MaxHealth = 40+(scale*60)
  406.  
  407. Hum.Health = 100
  408.  
  409. Hum.Parent = Nub
  410.  
  411. Nub.Parent = workspace
  412.  
  413. Nub:MakeJoints()
  414.  
  415. Nub:MoveTo(pos)
  416.  
  417. Animate(Hum,RSH,LSH,RH,LH)
  418.  
  419. --[[Hum.Died:connect(function()
  420.  
  421. wait(6)
  422.  
  423. Nub:remove()
  424.  
  425. wait(4)
  426.  
  427. MakeNoob(pos, scale)
  428.  
  429. end)]]
  430.  
  431. return {Name = Name, Model = Nub, Humanoid = Hum, Torso = Torso, Head = Head, Rarm = Rarm, Larm = Larm, Rleg = Rleg, Lleg = Lleg, RSH = RSH, LSH = LSH, RH = RH, LH = LH, Neck = Neck}
  432.  
  433. end
  434.  
  435.  
  436.  
  437. local Npc = MakeNoob(V3(MRA(-20, 20),10,MRA(-20, 20)), 1)
  438.  
  439.  
  440.  
  441. function Chat(msg, tone)
  442.  
  443. local tone = tone
  444.  
  445. if tone == nil then tone = 1 end
  446.  
  447. game:GetService("Chat"):Chat(Npc.Head, msg, Tones[tone] or 1)
  448.  
  449. end
  450.  
  451.  
  452.  
  453. wait(1.5)
  454.  
  455.  
  456.  
  457. Chat(("Hello! My name is %s."):format(Npc.Name))
  458.  
  459.  
  460.  
  461. while true do
  462.  
  463.  
  464.  
  465. wait(0.4)
  466.  
  467. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement