Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.60 KB | None | 0 0
  1. return function(_p)
  2. local Utilities = _p.Utilities
  3. local rc4 = Utilities.rc4
  4.  
  5. local player = _p.player
  6.  
  7. local MAX_MONEY = 9999999
  8. local MAX_BP = 9999
  9.  
  10. --local ENABLE_DEBUG_LOCATION = true -- TODO: REMOVE BEFORE PUBLISHING
  11. --local DEBUG_LOCATION
  12.  
  13. local PlayerData = {
  14. gameBegan = false,
  15. trainerName = player.Name,
  16. badges = {},
  17. money = 0,
  18. bp = 0,
  19. completedEvents = {},
  20. expShareOn = false,
  21. defeatedTrainers = '',
  22. firstNonEggLevel = 1, -- remember us!!!
  23. firstNonEggAbility = '',
  24. }
  25.  
  26. _p.Network:bindEvent('PDChanged', function(...) -- k1, v1, k2, v2, ... kn, vn
  27. local k
  28. for _, v in pairs({...}) do
  29. if k then
  30. PlayerData[k] = v
  31. if k == 'money' then
  32. _p.Menu.shop:updateMoneyIfActive()
  33. end
  34. k = nil
  35. else
  36. k = v
  37. end
  38. end
  39. end)
  40.  
  41. _p.Network:bindEvent('eventCompleted', function(name)
  42. PlayerData.completedEvents[name] = true
  43. end)
  44.  
  45. _p.Network:bindEvent('badgeObtained', function(i)
  46. PlayerData.badges[i] = true
  47. end)
  48.  
  49. _p.Network:bindEvent('bpAwarded', function(amount, newTotal)
  50. PlayerData.bp = math.min(newTotal)
  51. _p.Menu.battleShop:updateBP()
  52. local gui = _p.RoundedFrame:new {
  53. CornerRadius = Utilities.gui.AbsoluteSize.Y*.025,
  54. BackgroundColor3 = BrickColor.new('Deep blue').Color,
  55. Size = UDim2.new(.3, 0, .3, 0),
  56. Position = UDim2.new(.35, 0, .35, 0),
  57. Parent = Utilities.frontGui,
  58. }
  59. Utilities.Write('+'..amount..' BP') {
  60. Frame = Utilities.Create 'Frame' {
  61. BackgroundTransparency = 1.0,
  62. Size = UDim2.new(0.0, 0, 0.3, 0),
  63. Position = UDim2.new(0.5, 0, 0.1, 0),
  64. ZIndex = 2, Parent = gui.gui,
  65. }, Scaled = true,
  66. }
  67. Utilities.Write 'Remember to SAVE!' {
  68. Frame = Utilities.Create 'Frame' {
  69. BackgroundTransparency = 1.0,
  70. Size = UDim2.new(0.0, 0, 0.15, 0),
  71. Position = UDim2.new(0.5, 0, 0.425, 0),
  72. ZIndex = 2, Parent = gui.gui,
  73. }, Scaled = true,
  74. }
  75. local ok; ok = _p.RoundedFrame:new {
  76. Button = true,
  77. CornerRadius = Utilities.gui.AbsoluteSize.Y*.025,
  78. BackgroundColor3 = BrickColor.new('Navy blue').Color,
  79. Size = UDim2.new(.5, 0, .3, 0),
  80. Position = UDim2.new(.25, 0, .6, 0),
  81. Parent = gui.gui,
  82. MouseButton1Click = function()
  83. ok:destroy()
  84. gui:destroy()
  85. end,
  86. }
  87. Utilities.Write 'OK' {
  88. Frame = Utilities.Create 'Frame' {
  89. BackgroundTransparency = 1.0,
  90. Size = UDim2.new(0.0, 0, 0.6, 0),
  91. Position = UDim2.new(0.5, 0, 0.2, 0),
  92. ZIndex = 2, Parent = ok.gui,
  93. }, Scaled = true,
  94. }
  95. delay(6, function()
  96. pcall(function()
  97. ok:destroy()
  98. gui:destroy()
  99. end)
  100. end)
  101. end)
  102.  
  103. _p.Network:bindEvent('ItemProductPurchased', function(itemName, itemIcon)
  104. game:GetService('StarterGui'):SetCore('SendNotification', {
  105. Title = itemName .. ' Obtained!',
  106. Text = 'Don\'t forget to SAVE!',
  107. Icon = 'rbxassetid://'..itemIcon,
  108. -- Duration = 5; -- Optional, defaults to 5 seconds
  109. -- Callback = bindableFunction; -- Optional, gets invoked with the text of the button the user pressed
  110. -- Button1 = "Yes"; -- Optional, makes a button appear with the given text that, when clicked, fires the Callback if it's given
  111. -- Button2 = "No"; -- Optional, makes another button appear with the given text that, when clicked, fires the Callback if it's given
  112. })
  113. end)
  114.  
  115. function PlayerData:formatMoney(m)
  116. return Utilities.comma_value(m or self.money)
  117. end
  118.  
  119. function PlayerData:completeEvent(event, ...)
  120. local r = _p.Network:get('PDS', 'completeEvent', event, ...)
  121. if r == false then return false end
  122. self.completedEvents[event] = true
  123. return r or true
  124. end
  125.  
  126. function PlayerData:getEtc()
  127. if not self.gameBegan then error('attempt to save before game began') end
  128.  
  129. local etc = {
  130. expShareOn = self.expShareOn,
  131. -- tName = self.trainerName
  132. }
  133.  
  134. -- repel
  135. if _p.Repel.steps > 0 then
  136. etc.repel = {}
  137. etc.repel.kind = _p.Repel.kind
  138. etc.repel.steps = math.ceil(_p.Repel.steps/2)
  139. end
  140.  
  141. -- options
  142. etc.options = {}
  143. etc.options.autosaveEnabled = _p.Autosave.enabled and true or false
  144. etc.options.reduceGraphics = _p.Menu.options.reduceGraphics and true or false
  145. etc.options.lastUnstuckTick = _p.Menu.options.lastUnstuckTick
  146.  
  147. -- location
  148. --[[
  149. if ENABLE_DEBUG_LOCATION then
  150. etc.location = DEBUG_LOCATION
  151. else]]if _p.context == 'adventure' then
  152. local buffer = _p.BitBuffer.Create()
  153. local chunk = _p.DataManager.currentChunk
  154. -- position
  155. local cframe = _p.player.Character.HumanoidRootPart.CFrame
  156. if chunk.id == 'gym5' and cframe.p.Y < 80 then
  157. cframe = CFrame.new(-130, 83, 350, -1, 0, 0, 0, 1, 0, 0, 0, -1) -- instead of loading under the dirt
  158. end
  159. if #chunk.roomStack > 0 then
  160. local room = chunk.roomStack[#chunk.roomStack]
  161. cframe = cframe - room.model.Base.Position
  162. end
  163. buffer:WriteCFrame(cframe)
  164. -- chunk / buildings
  165. buffer:WriteString(chunk.id)
  166. for i, room in pairs(chunk.roomStack) do
  167. buffer:WriteBool(true)
  168. buffer:WriteString(room.id)
  169. if i > 1 then
  170. buffer:WriteCFrame(room.exitCFrame-chunk.roomStack[i-1].model.Base.Position)
  171. end
  172. end
  173. buffer:WriteBool(false)
  174. etc.location = buffer:ToBase64()
  175. end
  176.  
  177. return etc
  178. end
  179.  
  180. function PlayerData:loadEtc(etc)
  181. self.trainerName = etc.tName
  182. self.defeatedTrainers = etc.dTrainers or ''
  183. self.completedEvents = etc.completedEvents --for event in pairs(self.completedEvents) do print(event) end
  184. _p.Events.init() -- to grab the new completedEvents table
  185. self.expShareOn = etc.expShareOn
  186.  
  187. local b = {}
  188. for k, v in pairs(etc.badges) do
  189. b[tonumber(k)] = v
  190. end
  191. self.badges = b
  192.  
  193. if self.completedEvents.ReceivedRTD then
  194. _p.Menu.rtd:enable()
  195. end
  196. if self.completedEvents.RunningShoesGiven then
  197. _p.RunningShoes:enable()
  198. end
  199.  
  200. if etc.repel then
  201. _p.Repel.kind = etc.repel.kind
  202. _p.Repel.steps = etc.repel.steps
  203. _p.Repel.more = etc.repel.more
  204. end
  205.  
  206. if etc.dcEgg then
  207. self.daycareManHasEgg = true
  208. end
  209.  
  210. if etc.options then
  211. if etc.options.autosaveEnabled then
  212. _p.Autosave:enable()
  213. end
  214. if etc.options.reduceGraphics then
  215. _p.Menu.options.reduceGraphics = true
  216. _p.Menu.options:setLightingForReducedGraphics(true)
  217. end
  218. _p.Menu.options.lastUnstuckTick = etc.options.lastUnstuckTick or 0
  219. end
  220.  
  221. if etc.newGameFlag then
  222. _p.Menu.newGameFlag = true
  223. end
  224.  
  225. self.rotomEventLevel = etc.rotom
  226.  
  227. -- location
  228. --[[
  229. if ENABLE_DEBUG_LOCATION then
  230. _p.DataManager:loadChunk('gym6')
  231. Utilities.Teleport(CFrame.new(216, 50, 883))
  232. DEBUG_LOCATION = etc.location
  233. else]]if etc.location then
  234. local buffer = _p.BitBuffer.Create()
  235. buffer:FromBase64(etc.location)
  236. -- position
  237. local cframe = buffer:ReadCFrame()
  238. -- chunk / buildings
  239. local chunkId = buffer:ReadString()
  240. local indoors = buffer:ReadBool()
  241. local chunk
  242. if not indoors then
  243. chunk = _p.DataManager:loadChunk(chunkId, {continueCFrame = cframe})
  244. else
  245. chunk = _p.DataManager:loadChunk(chunkId)
  246. chunk.indoors = true
  247. _p.MasterControl:SetIndoors(true)
  248. local roomId = buffer:ReadString()
  249. local door = chunk:getDoor(roomId)
  250. local room = chunk:getRoom(roomId, door, 1)
  251. chunk.roomStack = {room}
  252.  
  253. chunk:checkRegion(door.Position)
  254. game:GetService('RunService').RenderStepped:wait()
  255. local roomMusicId, roomMusicVolume
  256. if roomId == 'PokeCenter' then
  257. roomMusicId = 288895151
  258. elseif roomId:sub(1, 4) == 'Gate' and tonumber(roomId:sub(5)) then
  259. roomMusicId = 534997159--288893317
  260. roomMusicVolume = .45
  261. _p.DataManager.ignoreRegionChangeFlag = nil
  262. end
  263. pcall(function()
  264. if not chunk.roomData[roomId].Music then return end
  265. roomMusicId = chunk.roomData[roomId].Music
  266. roomMusicVolume = chunk.roomData[roomId].MusicVolume
  267. end)
  268. local function fixMusic()
  269. _p.MusicManager:fadeToVolume('RegionMusic', roomMusicId and 0 or 0.3, 0)
  270. if roomMusicId then
  271. _p.MusicManager:stackMusic(roomMusicId, 'RoomMusic', roomMusicVolume)
  272. end
  273. end
  274. local oneRegion = false
  275. for _ in pairs(chunk.data.regions) do
  276. if oneRegion then
  277. oneRegion = false
  278. break
  279. else
  280. oneRegion = true
  281. end
  282. end
  283. if oneRegion then
  284. spawn(function()
  285. local stack = _p.MusicManager:getMusicStack()
  286. while true do
  287. local l = stack[#stack]
  288. if l and l.Name == 'RegionMusic' then break end -- hax
  289. wait(.1)
  290. end
  291. fixMusic()
  292. end)
  293. else
  294. fixMusic()
  295. end
  296.  
  297. local event = _p.Events['onBeforeEnter_'..roomId]
  298. if event then event(room, cframe) end
  299.  
  300. while buffer:ReadBool() do
  301. chunk.indoors = true
  302. local subRoomId = buffer:ReadString()
  303. local subRoomButton
  304. for _, p in pairs(chunk:topRoom().model:GetChildren()) do
  305. if ((p.Name == 'SubRoom' and p:IsA('BasePart'))
  306. or (p.Name == 'InsideDoor' and p:IsA('Model')))
  307. and p:FindFirstChild('id') and p.id.Value == subRoomId then
  308. subRoomButton = p:IsA('Model') and p.Main or p
  309. break
  310. end
  311. end
  312. chunk:stackSubRoom(subRoomId, subRoomButton, true) -- support for multi-sub-roomed buildings ?
  313. chunk:topRoom().exitCFrame = buffer:ReadCFrame() + chunk.roomStack[#chunk.roomStack-1].model.Base.Position
  314. end
  315. workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
  316. chunk:bindIndoorCam()
  317. cframe = cframe + chunk:topRoom().model.Base.Position
  318. end
  319. local function indoorsFix()
  320. local room = chunk:topRoom()
  321. local entrance = room.Entrance
  322. if entrance then
  323. cframe = entrance.CFrame * CFrame.new(0, 3, 3.5) * CFrame.Angles(0, math.pi, 0)
  324. else
  325. entrance = room.model:FindFirstChild('ToChunk:'..chunk.id)
  326. if entrance then
  327. cframe = entrance.CFrame * CFrame.new(0, 3, -3.5)
  328. end
  329. end
  330. wait(1)
  331. end
  332. pcall(function() -- for those who save in spawn box and were *not* indoors OR were indoors and got the same LocalIndoorsOrigin
  333. if chunkId == 'mining' or _p.Region.FromPart(_p.storage.Models.SpawnRegion):CastPoint(cframe.p) then
  334. if indoors then
  335. indoorsFix()
  336. else
  337. -- local place = 'PokeCenter'
  338. -- if chunk.id == 'chunk1' then
  339. -- place = 'yourhomef1'
  340. -- end
  341. -- local door = chunk:getDoor(place) or chunk.doors[1]
  342. -- cframe = door.CFrame * CFrame.new(0, 0, door.Size.Z + 3)
  343. _p.Menu.options:getUnstuck(true)
  344. cframe = nil
  345. wait(1)
  346. end
  347. end
  348. end)
  349. pcall(function() -- for those who save in spawn box and were indoors, but got a different LocalIndoorsOrigin
  350. if not chunk.indoors then return end
  351. local hit = (workspace:FindPartOnRay(Ray.new(cframe.p, Vector3.new(0, -100, 0))))
  352. if hit then return end
  353. indoorsFix()
  354. end)
  355. if cframe then Utilities.Teleport(cframe) end
  356. end
  357.  
  358. self.gameBegan = true
  359. end
  360.  
  361. function PlayerData:save()
  362. return _p.Network:get('PDS', 'saveGame', self:getEtc())
  363. end
  364.  
  365.  
  366. return PlayerData end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement