Advertisement
grymlahv

warden prefab

Jul 7th, 2020
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 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. --Mine the World
  50. local WARDEN_LMB_ACTIONS =
  51. {
  52. "MINE",
  53. }
  54.  
  55. local function GetWardenAction(inst, target)
  56. for i, v in ipairs(WARDEN_LMB_ACTIONS) do
  57. if target:HasTag(v.."_workable") then
  58. return not target:HasTag("sign") and ACTIONS[v] or nil
  59. end
  60. end
  61. end
  62. local function WardenLeftClickPicker(inst, target)
  63. if target ~= nil and target ~= inst then
  64. for i, v in ipairs(WARDEN_LMB_ACTIONS) do
  65. if target:HasTag(v.."_workable") then
  66. return not target:HasTag("sign")
  67. and inst.components.playeractionpicker:SortActionList({ ACTIONS[v] }, target, nil)
  68. or nil
  69. end
  70. end
  71. end
  72. end
  73. local function SetWorker(inst, mode)
  74. inst:RemoveEventCallback("working", onworked)
  75.  
  76. if inst.components.worker == nil then
  77. inst:AddComponent("worker")
  78. inst.components.worker:SetAction(ACTIONS.MINE, 2)
  79. inst.components.worker:SetAction(ACTIONS.HAMMER, 1)
  80. OnWorking(inst)
  81. end
  82. end
  83. local function SetWereActions(inst)
  84. inst.ActionStringOverride = WardenActionString
  85. if inst.components.playercontroller ~= nil then
  86. inst.components.playercontroller.actionbuttonoverride = WardenActionButton
  87. end
  88. if inst.components.playeractionpicker ~= nil then
  89. inst.components.playeractionpicker.leftclickoverride = WardenLeftClickPicker
  90. inst.components.playeractionpicker.rightclickoverride = WardenRightClickPicker
  91. inst.components.playeractionpicker.pointspecialactionsfn = nil
  92. end
  93.  
  94.  
  95. end
  96.  
  97. -- This initializes for both the server and client. Tags can be added here.
  98. local common_postinit = function(inst)
  99. -- Minimap icon
  100. inst.MiniMapEntity:SetIcon( "warden.tex" )
  101. end
  102.  
  103. -- This initializes for the server only. Components are added here.
  104. local master_postinit = function(inst)
  105. -- Set starting inventory
  106. inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default
  107.  
  108. -- choose which sounds this character will play
  109. inst.soundsname = "willow"
  110.  
  111. -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
  112. --inst.talker_path_override = "dontstarve_DLC001/characters/"
  113.  
  114. -- Stats
  115. inst.components.health:SetMaxHealth(TUNING.WARDEN_HEALTH)
  116. inst.components.hunger:SetMax(TUNING.WARDEN_HUNGER)
  117. inst.components.sanity:SetMax(TUNING.WARDEN_SANITY)
  118.  
  119. -- Damage multiplier (optional)
  120. inst.components.combat.damagemultiplier = 1
  121.  
  122. -- Hunger rate (optional)
  123. inst.components.hunger.hungerrate = .75 * TUNING.WILSON_HUNGER_RATE
  124.  
  125. -- Sanity rate (optional)
  126. inst.components.sanity.rate_modifier = 0.75
  127.  
  128. -- Diet of Rocks
  129. inst.components.eater:SetDiet({ FOODTYPE.ELEMENTAL }, { FOODTYPE.ELEMENTAL })
  130.  
  131. -- Mine the World
  132. setwereactions(inst)
  133.  
  134. -- Temperature Invulnerability
  135. inst.components.temperature.overheattemp = 69
  136. inst.components.temperature.inherentsummerinsulation = 50
  137. inst.components.temperature.inherentinsulation = 50
  138.  
  139. inst.OnLoad = onload
  140. inst.OnNewSpawn = onload
  141.  
  142. end
  143.  
  144. return MakePlayerCharacter("warden", prefabs, assets, common_postinit, master_postinit, prefabs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement