Advertisement
Kzisor

Untitled

Feb 4th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. local MakePlayerCharacter = require "prefabs/player_common"
  2.  
  3.  
  4. local assets = {
  5. Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
  6. Asset( "ANIM", "anim/chara.zip" ),
  7. }
  8. local prefabs = {}
  9.  
  10. -- Custom starting items
  11. local start_inv = {
  12. "friskbandaid",
  13. "charaworndagger",
  14. }
  15.  
  16. -- When the character is revived from human
  17. local function onbecamehuman(inst)
  18. -- Set speed when reviving from ghost (optional)
  19. inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 1.35)
  20. inst.components.talker:Say("*...But It Refused.", 2.5,true)
  21. end
  22.  
  23. local function onbecameghost(inst)
  24. -- Remove speed modifier when becoming a ghost
  25. inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "frisk_speed_mod")
  26. end
  27.  
  28. local function ResetDelay(inst)
  29. if inst.transform_task ~= nil then
  30. inst.transform_task:Cancel()
  31. inst.transform_task = nil
  32. end
  33. inst.transform_delay = nil
  34. inst.components.keyhandler:StopIgnoring()
  35. end
  36.  
  37. local function OnSave(inst, data)
  38. data.transformed = inst.transformed
  39. data.transform_delay = inst.transform_delay
  40. end
  41.  
  42. -- When loading or spawning the character
  43. local function onload(inst, data)
  44. inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
  45. inst:ListenForEvent("ms_becameghost", onbecameghost)
  46.  
  47. if inst:HasTag("playerghost") then
  48. onbecameghost(inst)
  49. else
  50. onbecamehuman(inst)
  51. end
  52. end
  53.  
  54. --Transform Delay
  55. local function OnLoad(inst, data)
  56. if data then
  57. if data.transformed then
  58. inst.transformed = data.transformed
  59. end
  60.  
  61. if data.transform_delay then
  62. inst.transform_delay = GetTime() - data.transform_delay
  63. end
  64. end
  65.  
  66. onload( inst, data )
  67.  
  68. if inst.transformed then
  69. local fn = GetModRPCHandler( "frisk", "CHARA" )
  70. fn(inst, true, inst.transform_delay)
  71. end
  72. end
  73.  
  74. local function Revive(inst)
  75. inst:DoTaskInTime(5, function(inst)
  76. if inst.transformed then
  77. if inst.transform_task ~= nil then
  78. inst.transform_task:Cancel()
  79. inst.transform_task = nil
  80. end
  81. local fn = GetModRPCHandler( "frisk", "CHARA" )
  82. fn(inst, true, inst.transform_delay)
  83. else
  84. inst.components.keyhandler:StopIgnoring()
  85. end
  86. end)
  87. end
  88.  
  89. -- This initializes for both the server and client. Tags can be added here.
  90. local common_postinit = function(inst)
  91. -- Minimap icon
  92. inst.MiniMapEntity:SetIcon( "frisk.tex" )
  93.  
  94. inst:AddTag("frisk_builder")
  95. inst:AddTag("chara_builder")
  96. --Starting out as Chara
  97. inst:AddTag("frisk")
  98. inst:AddTag("doublehealz")
  99. inst:RemoveTag("nohealz")
  100. inst:RemoveTag("chara")
  101. inst:RemoveTag("scarytoprey")
  102. inst:RemoveTag("monster")
  103.  
  104. inst:AddComponent("keyhandler")
  105. inst.components.keyhandler:AddActionListener("frisk", TUNING.FRISK.KEY, "CHARA")
  106.  
  107. end
  108.  
  109. -- This initializes for the server only. Components are added here.
  110. local master_postinit = function(inst)
  111. -- choose which sounds this character will play
  112. inst.soundsname = "frisk"
  113.  
  114. -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
  115. --inst.talker_path_override = "dontstarve_DLC001/characters/"
  116.  
  117. -- Stats
  118. inst.components.health:SetMaxHealth(75)
  119. inst.components.hunger:SetMax(150)
  120. inst.components.sanity:SetMax(200)
  121.  
  122. inst.components.health.SetPenalty = function(self, penalty)
  123. self.penalty = math.clamp(penalty, 0, 0)
  124. end
  125.  
  126. -- Hunger rate (optional)
  127. inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
  128.  
  129. inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 1.35)
  130. inst.components.health.absorb = 0.1
  131. inst.components.combat.damagemultiplier = 0.75
  132.  
  133. inst.Transform:SetScale(0.7, 0.7, 0.7)
  134.  
  135. --Transform Delay
  136. inst._cooldown = 3 * TUNING.TOTAL_DAY_TIME
  137. inst.ResetDelay = ResetDelay
  138.  
  139. local _DoDelta = inst.components.health.DoDelta
  140. inst.components.health.DoDelta = function(self, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
  141. if amount > 0 then
  142. if self.inst:HasTag("nohealz") then
  143. amount = 0
  144. elseif self.inst:HasTag("doublehealz") then
  145. amount = amount * 2
  146. end
  147. end
  148. _DoDelta(self, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
  149. end
  150.  
  151. inst:ListenForEvent("death", function(inst)
  152. if not inst.components.keyhandler.ignore_ then
  153. inst.components.keyhandler:StartIgnoring()
  154. end
  155. end)
  156.  
  157. inst:ListenForEvent("ms_respawnedfromghost", function(inst)
  158. Revive(inst)
  159. end)
  160.  
  161. inst.OnSave = OnSave
  162. inst.OnLoad = OnLoad
  163. inst.OnNewSpawn = onload
  164.  
  165. end
  166.  
  167. return MakePlayerCharacter("frisk", prefabs, assets, common_postinit, master_postinit, start_inv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement