Jump to content

Recommended Posts

Hi! So I've begun work on my character's skilltree! I've tried a few methods for changeing maxhealth after Wramp unlocks the life leech skill on his skilltree. none of them have worked so far Here's the function and the prefab file: 

local MakePlayerCharacter = require "prefabs/player_common"
 
local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
    -- Other assets
    Asset("SCRIPT", "scripts/prefabs/skilltree_wramp.lua")
}
 
-- Custom starting inventory
TUNING.GAMEMODE_STARTING_ITEMS.DEFAULT.WRAMP = {
    "nightmarefuel",
    "nightmarefuel",
    "nightmarefuel",
    "nightmarefuel",
}
 
local start_inv = {}
for k, v in pairs(TUNING.GAMEMODE_STARTING_ITEMS) do
    start_inv[string.lower(k)] = v.WRAMP
end
local prefabs = FlattenTree(start_inv, true)
 
    TUNING.WRAMP_HUNGER = 300
    TUNING.WRAMP_SANITY = 200
    TUNING.WRAMP_HEALTH = 150
-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when not a ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wramp_speed_mod", 1)
end
 
local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "wramp_speed_mod")
end
--trying placement
local function GetEquippableDapperness(owner, equippable)
    local dapperness = equippable:GetDapperness(owner, owner.components.sanity.no_moisture_penalty)
    return equippable.inst:HasTag("shadow_item")
        and dapperness * TUNING.WAXWELL_SHADOW_ITEM_RESISTANCE
        or dapperness
end


 
--[[inst:ListenForEvent("sanitydelta", function(inst, data)    inst.components.health:SetMaxHealth(100+(inst.components.sanity.current))   inst.components.health:DoDelta(0)end)]]
--[[WANDA DAMAGE SFX
then
        local fx_prefab = inst.age_state == "old" and (weapon:HasTag("pocketwatch") and "wanda_attack_pocketwatch_old_fx" or "wanda_attack_shadowweapon_old_fx")
                or inst.age_state == "normal" and (weapon:HasTag("pocketwatch") and "wanda_attack_pocketwatch_normal_fx" or "wanda_attack_shadowweapon_normal_fx")
                or nil
 
        if fx_prefab ~= nil then
            local fx = SpawnPrefab(fx_prefab)
 
            local x, y, z = target.Transform:GetWorldPosition()
            local radius = target:GetPhysicsRadius(.5)
            local angle = (inst.Transform:GetRotation() - 90) * DEGREES
            fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius)
        end
 
        Sanity function
 
            inst:ListenForEvent("sanitydelta", function(inst, data)
    if inst.components.sanity.current >= 30 then
       inst.components.combat.damagemultiplier = 1.5
    elseif inst.components.sanity.current <= 30 then
       inst.components.combat.damagemultiplier = 2
    end
end
 
]]
 
--TEST
 
-- Old
--[[local function WrampShadowWeaponFx(inst, data)
    -- The rest of the function here
    if inst.components.sanity:GetPercent() <= .5 then
        -- Code
 
        if weapon ~= nil and target ~= nil and target:IsValid() and weapon:IsValid()    then
            local fx_prefab = "wanda_attack_shadowweapon_normal_fx" and print("NORMAL FX")
                    or nil
   
            if fx_prefab ~= nil then
                local fx = SpawnPrefab(fx_prefab)
   
                local x, y, z = target.Transform:GetWorldPosition()
                local radius = target:GetPhysicsRadius(.5)
                local angle = (inst.Transform:GetRotation() - 90) * DEGREES
                fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius)
 
    elseif inst.components.sanity:GetPercent() >= .3 then
        -- Code
 
        if weapon ~= nil and target ~= nil and target:IsValid() and weapon:IsValid()    then
            local fx_prefab = "wanda_attack_shadowweapon_old_fx" and print("BIG FX")
                    or nil
   
            if fx_prefab ~= nil then
                local fx = SpawnPrefab(fx_prefab)
   
                local x, y, z = target.Transform:GetWorldPosition()
                local radius = target:GetPhysicsRadius(.5)
                local angle = (inst.Transform:GetRotation() - 90) * DEGREES
                fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius)
    end
end]]--
 
-- New
local function WrampMaxHealth(inst)
        if inst:HasTag("wramp_skill_leech_1") then
    inst.components.health:SetMaxHealth(60)
    else
        inst.components.health:SetMaxHealth(150)
    end
end
 
local function WrampShadowWeaponFx(inst, target)
    if inst:HasTag("wramp_skill_leech_1") and target.components.combat ~= nil then
        inst.components.sanity:DoDelta(1)
        inst.components.health:DoDelta(1)
        else
 
        if target.components.combat ~= nil then
            inst.components.sanity:DoDelta(0.5)
            inst.components.health:DoDelta(0.3)
        end
    end
 
    if target ~= nil and target:IsValid() then
        local sanity_percent = inst.components.sanity:GetPercent() -- Setting it to a variable so its less to write out again and again
        -- The below works as a glorified If statement, setting fx_prefab to either old_fx, normal_fx, or nil depending on the given conditions
        local fx_prefab = sanity_percent <= .5 and sanity_percent > .3 and "shadow_merm_smacked_poof_fx"
            or sanity_percent <= .3 and "shadow_despawn"
            or nil
        print(fx_prefab)
       
        if fx_prefab ~= nil then
            local fx = SpawnPrefab(fx_prefab)  
            local x, y, z = target.Transform:GetWorldPosition()
            local radius = target:GetPhysicsRadius(.5)
            local angle = (inst.Transform:GetRotation() - 90) * DEGREES
            fx.Transform:SetPosition(x + math.sin(angle) * radius, 0, z + math.cos(angle) * radius)
        end
    end
end


 
-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end
 
-- This initializes for both the server and client. Tags can be added here.
local common_postinit = function(inst)
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "wramp.tex" )
 
    inst:AddTag("playermonster")
   
    inst:AddTag("monster")
 
    inst:AddTag("wramp_crafter")
 
    if inst.components.skilltreeupdater:IsActivated("wramp_hattrick") then
    inst:AddComponent("magician")-- Do stuff here
    end
 
end
   
local function CalculateStrength(inst, data)
    inst.components.combat.damagemultiplier = Remap(1 - data.newpercent, 0, 1, 1, 2)
end
 
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
    -- Set starting inventory
    inst.starting_inventory = start_inv[TheNet:GetServerGameMode()] or start_inv.default
   
   
    -- choose which sounds this character will play
    inst.soundsname = "wramp"
   
    -- Uncomment if "wathgrithr"(Wigfrid) or "webber" voice is used
    --inst.talker_path_override = "dontstarve_DLC001/characters/"
    -- Your character's stats
 
    -- Stats    
   
    inst.components.hunger:SetMax(TUNING.WRAMP_HUNGER)
    inst.components.sanity:SetMax(TUNING.WRAMP_SANITY)
 
    --[[
    inst.components.health:SetMaxHealth(TUNING.WRAMP_HEALTH)
    ]]
 
    inst:ListenForEvent("sanitydelta", CalculateStrength)
    -- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
   
    -- Hunger rate (optional)
    inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
   
    inst.components.builder.magic_bonus = 2
    --sanity loss
 
    inst.components.sanity.dapperness = -0.1
 
    inst.components.sanity.get_equippable_dappernessfn = GetEquippableDapperness
 
    inst.components.combat.onhitotherfn = WrampShadowWeaponFx
 
        if inst.components.eater ~= nil then
        inst.components.eater:SetAbsorptionModifiers(.65, .65, 1)
    end
 
    inst.components.foodaffinity:AddPrefabAffinity("pomegranate", TUNING.AFFINITY_15_CALORIES_TINY)
    inst.components.foodaffinity:AddPrefabAffinity("pomegranate_cooked", TUNING.AFFINITY_15_CALORIES_SMALL)
 
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
 
   
   
end
 
return MakePlayerCharacter("wramp", prefabs, assets, common_postinit, master_postinit, prefabs)

I've tried listening for the event, when the player spawns and seeing if they have the skill tag then reduceing max health. I'm haveing problems geting that working if anyone know a solution that would be really appreciated! :wilson_love:

inst:ListenForEvent("ms_newplayerspawned", function(inst, data)
    if inst:HasTag("wramp_skill_leech_1") then
        inst.components.health:SetMaxHealth(60)
    else
        inst.components.health:SetMaxHealth(150)
    end
end)

have you tried putting it in OnLoad?

local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
    
    if inst:HasTag("wramp_skill_leech_1") then
        inst.components.health:SetMaxHealth(60)
    else
        inst.components.health:SetMaxHealth(150)
    end
end

I don't know if the component is initialized at that point, but you can try. What you want to do is have the player spawn with their maximum health changed based on your skill tree, right?

I've also tried testing if the skill is enabled set the max health

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
 
     if inst.components.skilltreeupdater:IsActivated("wramp_leech_1") then
        inst.components.health:SetMaxHealth(60)
    else
        inst.components.health:SetMaxHealth(150)
    end
end
local function onload(inst)
  	print("onload")
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
 	local res = inst.components.skilltreeupdater:IsActivated("wramp_leech_1")
  	print("wramp_leech_1 is activated")
  	print(res)
     if res then
        inst.components.health:SetMaxHealth(60)
    	print("Max health 60")
    else
        inst.components.health:SetMaxHealth(150)
    	print("Max health 150")
    end
end

Try that, get into a game and then go to the logs, send me which print() were written and which were not.

11 minutes ago, Doodle Monster said:

it printed wramp_leech_1 is active and maxhealth at 150, So I assume there's something wrong with the maxhealth change not being run

In fact, "Is activated" will appear regardless of the value. The actual value is false. 

inst.components.skilltreeupdater:IsActivated("wramp_leech_1")

returns false, so I assume "wramp_leech_1" isn't actually activated.

1 minute ago, Doodle Monster said:

That might be wrong, I thought rollingback would reset the console

 

 

Run this command in the console when everything is loaded

print(AllPlayers[1].components.skilltreeupdater:IsActivated("wramp_leech_1"))

and tell me what you get as a result

I changed it back to detecting the tag, I think that will mess with it I probably should have not changed it

local function onload(inst)
    print("onload")
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
    local res = inst:HasTag("wramp_skill_leech_1")
    print("wramp_leech_1 is activated")
    print(res)
     if res then
        inst.components.health:SetMaxHealth(60)
        print("Max health 60")
    else
        inst.components.health:SetMaxHealth(150)
        print("Max health 150")
    end
end

I keep getting bugged out the fourms like to keep repeat posting images lol

@FerniFrenito It prints true, tried it twice to make sure

Edited by Doodle Monster

It prints true for the command you gave me in the console

I changed it back to :

local function onload(inst)
  	print("onload")
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)
 
    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
 	local res = inst.components.skilltreeupdater:IsActivated("wramp_leech_1")
  	print("wramp_leech_1 is activated")
  	print(res)
     if res then
        inst.components.health:SetMaxHealth(60)
    	print("Max health 60")
    else
        inst.components.health:SetMaxHealth(150)
    	print("Max health 150")
    end
end

 

 

 

Edited by Doodle Monster
16 minutes ago, Doodle Monster said:

It prints true for the command you gave me in the console

This means that by the time OnLoad is executed, the tree's ability is not yet activated, it is activated later.

 

Wait, I'll see if you can run the code when the skill is set to true.

Try this

local function onload(inst)
  -- ...
  inst:ListenForEvent("onactivateskill_server", function(data)
      print("EVENT LISTENER :")
      print(data)
      if data then print(data.skill) end
      print("________")

      if data and data.skill == "wramp_leech_1" then
        inst.components.health:SetMaxHealth(60)
      else
        inst.components.health:SetMaxHealth(150)
      end
    end)
  end

This should work, but what I don't know is what it returns in the data variable, so make the change and look for where "EVENT LISTENER :" is printed and send me a screenshot of that part.

Edited by FerniFrenito

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...