Guest User

Untitled

a guest
Feb 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.33 KB | None | 0 0
  1.  
  2. local MakePlayerCharacter = require "prefabs/player_common"
  3.  
  4.  
  5. local assets = {
  6.     Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
  7.     Asset( "ANIM", "anim/chara.zip" ),
  8. }
  9. local prefabs = {}
  10.  
  11. -- Custom starting items
  12. local start_inv = {
  13.     "friskbandaid",
  14.     "charaworndagger",
  15. }
  16.  
  17. -- When the character is revived from human
  18. local function onbecamehuman(inst)
  19.     -- Set speed when reviving from ghost (optional)
  20.     inst.components.locomotor:SetExternalSpeedMultiplier(inst, "frisk_speed_mod", 1.35)
  21.     inst.components.talker:Say("*...But It Refused.", 2.5,true)
  22. end
  23.  
  24. local function onbecameghost(inst)
  25.     -- Remove speed modifier when becoming a ghost
  26.    inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "frisk_speed_mod")
  27. end
  28.  
  29. local function ResetDelay(inst)
  30.     inst.transform_delay = nil
  31. end
  32.  
  33. local function OnSave(inst, data)
  34.     data.transform_delay = inst.transform_delay
  35. end
  36.  
  37. -- When loading or spawning the character
  38. local function onload(inst, data)
  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. --Transform Delay
  50. local function OnLoad(inst, data)
  51.     if data then
  52.         if data.transform_delay then
  53.             local time_left = GetTime() - data.transform_delay
  54.             inst.transform_task = inst:DoTaskInTime(time_left, inst.ResetDelay)
  55.             inst.transform_delay = data.transform_delay
  56.         end
  57.     end
  58. end
  59.  
  60.  
  61. -- This initializes for both the server and client. Tags can be added here.
  62. local common_postinit = function(inst)
  63.     -- Minimap icon
  64.     inst.MiniMapEntity:SetIcon( "frisk.tex" )
  65.    
  66.     inst:AddTag("frisk_builder")
  67.     inst:AddTag("chara_builder")
  68.  
  69.     inst.transformed = false
  70.     inst:AddComponent("keyhandler")
  71.     inst.components.keyhandler:AddActionListener("frisk", TUNING.FRISK.KEY, "CHARA")
  72. end
  73.  
  74. -- This initializes for the server only. Components are added here.
  75. local master_postinit = function(inst)
  76.     -- choose which sounds this character will play
  77.     inst.soundsname = "frisk"
  78.    
  79.     -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
  80.     --inst.talker_path_override = "dontstarve_DLC001/characters/"
  81.    
  82.     -- Stats   
  83.     inst.components.health:SetMaxHealth(75)
  84.     inst.components.hunger:SetMax(150)
  85.     inst.components.sanity:SetMax(200)
  86.    
  87.     inst.components.health.SetPenalty = function(self, penalty)
  88.     self.penalty = math.clamp(penalty, 0, 0)
  89.     end
  90.            
  91.     -- Hunger rate (optional)
  92.     inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
  93.        
  94.     inst.Transform:SetScale(0.7, 0.7, 0.7)
  95.    
  96.     --Transform Delay
  97.     inst._cooldown = 3 * TUNING.TOTAL_DAY_TIME
  98.     inst.ResetDelay = ResetDelay
  99.  
  100.    
  101.     local _DoDelta = inst.components.health.DoDelta
  102.     inst.components.health.DoDelta = function(self, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
  103.         if amount > 0 then
  104.             if self.inst:HasTag("nohealz") then
  105.                 amount = 0
  106.             elseif self.inst:HasTag("doublehealz") then
  107.                 amount = amount * 2
  108.             end
  109.         end
  110.         _DoDelta(self, amount, overtime, cause, ignore_invincible, afflicter, ignore_absorb)
  111.     end
  112.    
  113.     inst.OnSave = OnSave
  114.     inst.OnLoad = OnLoad
  115.     inst.OnLoad = onload
  116.     inst.OnNewSpawn = onload
  117.        
  118. end
  119.  
  120. return MakePlayerCharacter("frisk", prefabs, assets, common_postinit, master_postinit, start_inv)
Add Comment
Please, Sign In to add comment