grymlahv

warden prefab

Jul 6th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. local MakePlayerCharacter = require "prefabs/player_common"
  2.  
  3. local assets = {
  4. Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
  5. }
  6.  
  7. -- Your character's stats
  8. TUNING.WARDEN_HEALTH = 300
  9. TUNING.WARDEN_HUNGER = 100
  10. TUNING.WARDEN_SANITY = 50
  11.  
  12. -- Custom starting inventory
  13. TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WARDEN = {
  14. "flint",
  15. "flint",
  16. "rocks",
  17. "rocks",
  18. }
  19.  
  20. local start_inv = {}
  21. for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do
  22. start_inv[string.lower(k)] = v.WARDEN
  23. end
  24. local prefabs = FlattenTree(start_inv, true)
  25.  
  26. -- When the character is revived from human
  27. local function onbecamehuman(inst)
  28. -- Set speed when not a ghost (optional)
  29. inst.components.locomotor:SetExternalSpeedMultiplier(inst, "warden_speed_mod", .75)
  30. end
  31.  
  32. local function onbecameghost(inst)
  33. -- Remove speed modifier when becoming a ghost
  34. inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "warden_speed_mod")
  35. end
  36.  
  37. -- When loading or spawning the character
  38. local function onload(inst)
  39. inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
  40. inst:ListenForEvent("ms_becameghost", onbecameghost)
  41.  
  42. if inst:HasTag("playerghost") then
  43. onbecameghost(inst)
  44. else
  45. onbecamehuman(inst)
  46. end
  47. end
  48.  
  49.  
  50. -- This initializes for both the server and client. Tags can be added here.
  51. local common_postinit = function(inst)
  52. -- Minimap icon
  53. inst.MiniMapEntity:SetIcon( "warden.tex" )
  54. --[[ Mine the world
  55. inst:AddTag("multitasker")]]--
  56. end
  57.  
  58. -- This initializes for the server only. Components are added here.
  59. local master_postinit = function(inst)
  60. -- Set starting inventory
  61. inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default
  62.  
  63. -- choose which sounds this character will play
  64. inst.soundsname = "willow"
  65.  
  66. -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
  67. --inst.talker_path_override = "dontstarve_DLC001/characters/"
  68.  
  69. -- Stats
  70. inst.components.health:SetMaxHealth(TUNING.WARDEN_HEALTH)
  71. inst.components.hunger:SetMax(TUNING.WARDEN_HUNGER)
  72. inst.components.sanity:SetMax(TUNING.WARDEN_SANITY)
  73.  
  74. -- Damage multiplier (optional)
  75. inst.components.combat.damagemultiplier = 1
  76.  
  77. -- Hunger rate (optional)
  78. inst.components.hunger.hungerrate = .75 * TUNING.WILSON_HUNGER_RATE
  79.  
  80. -- Sanity rate (optional)
  81. inst.components.sanity.rate_modifier = 0.75
  82.  
  83. -- Diet of Rocks
  84. inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })
  85.  
  86.  
  87. -- Temperature Invulnerability
  88. inst.components.temperature.overheattemp = 69
  89. inst.components.temperature.inherentsummerinsulation = 50
  90. inst.components.temperature.inherentinsulation = 50
  91.  
  92. inst.OnLoad = onload
  93. inst.OnNewSpawn = onload
  94.  
  95. end
  96.  
  97. local WARDEN_LMB_ACTIONS =
  98. {
  99. "MINE",
  100. }
  101.  
  102. local function GetWardenAction(inst, target)
  103. for i, v in ipairs(WARDEN_LMB_ACTIONS) do
  104. if target:HasTag(v.."_workable") then
  105. return not target:HasTag("sign") and ACTIONS[v] or nil
  106. end
  107. end
  108. end
  109. local function WardenLeftClickPicker(inst, target)
  110. if target ~= nil and target ~= inst then
  111. for i, v in ipairs(WARDEN_LMB_ACTIONS) do
  112. if target:HasTag(v.."_workable") then
  113. return not target:HasTag("sign")
  114. and inst.components.playeractionpicker:SortActionList({ ACTIONS[v] }, target, nil)
  115. or nil
  116. end
  117. end
  118. end
  119. end
  120. local function SetWorker(inst, mode)
  121. inst:RemoveEventCallback("working", onworked)
  122.  
  123. if mode == WEREMODES.NONE then
  124. if inst.components.worker == nil then
  125. inst:AddComponent("worker")
  126. inst.components.worker:SetAction(ACTIONS.MINE, 2)
  127. inst.components.worker:SetAction(ACTIONS.HAMMER, 1)
  128. OnWorking(inst)
  129. end
  130. end
  131. end
  132. local function SetWereActions(inst, mode)
  133. if mode == WEREMODES.NONE then
  134. inst.ActionStringOverride = WardenActionString
  135. if inst.components.playercontroller ~= nil then
  136. inst.components.playercontroller.actionbuttonoverride = WardenActionButton
  137. end
  138. if inst.components.playeractionpicker ~= nil then
  139. inst.components.playeractionpicker.leftclickoverride = WardenLeftClickPicker
  140. inst.components.playeractionpicker.rightclickoverride = WardenRightClickPicker
  141. inst.components.playeractionpicker.pointspecialactionsfn = nil
  142. end
  143. EnableReticule(inst, false)
  144. end
  145. end
  146.  
  147.  
  148. return MakePlayerCharacter("warden", prefabs, assets, common_postinit, master_postinit, prefabs)
Advertisement
Add Comment
Please, Sign In to add comment