Jump to content

Recommended Posts

The tittle is self explanatory. My character has 2 forms. Default and powered up. The issue is how do I make the game remember I quit in powered up state and load me with it?

I'm not new to coding nor to programming but I can't figure it out. Looking at wolfgang mightiness and woody wereness didn't help. I don't see why they can remain in their states and my character can not.

Rn transformation is tie d to killing anything to power up and equip anything to transform back

This is my 3rd topic on this character and previous 2 haven't received anything despite being viewed so I'm kinda tilted that this one will be overlooked as well. If you see this text and at least have any thoughts on how to make it work please write it in the comments

wylra.lua

1 hour ago, InvarkuI said:

How can I do it?

inst.OnLoad=function(inst,data) if data and data.characterfransformationstage then ....... end

inst.OnSave=function(inst,data)data.characterfransformationstage=inst.transformstage  end

Or if you see skinner component

function Skinner:OnSave()
	return {skin_name = self.skin_name, clothing = self.clothing}
end

function Skinner:OnLoad(data)
    --V2C: InGamePlay() is used to check whether world has finished
    --     loading and snapshot player sessions have been restored.
    --     Do not validate inventory when restoring snapshot saves,
    --     because the user is not actually logged in at that time.

    if data.clothing ~= nil then
        self.clothing = data.clothing

        if InGamePlay() then
            --it's possible that the clothing was traded away. Check to see if the player still owns it on load.
            for type,clothing in pairs( self.clothing ) do
                if clothing ~= "" and not TheInventory:CheckClientOwnership(self.inst.userid, clothing) then
                    self.clothing[type] = ""
                end
            end
        end
    end

    if data.skin_name == "NON_PLAYER" then
		self:SetupNonPlayerData()
    else
		local skin_name = self.inst.prefab.."_none"
		if data.skin_name ~= nil and
			data.skin_name ~= skin_name and
			(not InGamePlay() or TheInventory:CheckClientOwnership(self.inst.userid, data.skin_name)) then
			--load base skin (check that it hasn't been traded away)
			skin_name = data.skin_name
		end
		self:SetSkinName(skin_name, true)
	end

 

1 hour ago, Rickzzs said:

inst.OnLoad=function(inst,data) if data and data.characterfransformationstage then ....... end

inst.OnSave=function(inst,data)data.characterfransformationstage=inst.transformstage  end

Or if you see skinner component

function Skinner:OnSave()
	return {skin_name = self.skin_name, clothing = self.clothing}
end

function Skinner:OnLoad(data)
    --V2C: InGamePlay() is used to check whether world has finished
    --     loading and snapshot player sessions have been restored.
    --     Do not validate inventory when restoring snapshot saves,
    --     because the user is not actually logged in at that time.

    if data.clothing ~= nil then
        self.clothing = data.clothing

        if InGamePlay() then
            --it's possible that the clothing was traded away. Check to see if the player still owns it on load.
            for type,clothing in pairs( self.clothing ) do
                if clothing ~= "" and not TheInventory:CheckClientOwnership(self.inst.userid, clothing) then
                    self.clothing[type] = ""
                end
            end
        end
    end

    if data.skin_name == "NON_PLAYER" then
		self:SetupNonPlayerData()
    else
		local skin_name = self.inst.prefab.."_none"
		if data.skin_name ~= nil and
			data.skin_name ~= skin_name and
			(not InGamePlay() or TheInventory:CheckClientOwnership(self.inst.userid, data.skin_name)) then
			--load base skin (check that it hasn't been traded away)
			skin_name = data.skin_name
		end
		self:SetSkinName(skin_name, true)
	end

 

I'm sorry I don't get it

I have this functions as 2 forms. There is no third form

Spoiler

function TitanWylra (inst)

    inst.AnimState:SetBuild("wylra_big")
    MakeGiantCharacterPhysics(inst, 1000, 5)
    inst.Physics:SetCapsule(1, 3)
    inst.components.combat:SetDefaultDamage(150)
    inst.Transform:SetScale(2.5, 2.5, 2.5)
    inst.components.combat:SetRange(3, 3)
    inst.components.eater:SetAbsorptionModifiers(0.1, 1, 0.5)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY
    TUNING.wylra_efficiency = 2.5
    TUNING.WYLRA_speed = 0.5
    TUNING.WYLRA_titan = 1 
    inst:AddTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    inst.AnimState:PlayAnimation("powerup")
    return TUNING.WYLRA_titan
    end


function SmallWylra (inst)

    inst.AnimState:SetBuild("wylra")
    MakeGiantCharacterPhysics(inst, 300, 1)
    inst.Physics:SetCapsule(1, 1)
    inst.components.combat:SetDefaultDamage(15)
    inst.Transform:SetScale(2.0, 2.0, 2.0)
    inst.components.combat:SetRange(1.5, 1.5)
    inst.components.eater:SetAbsorptionModifiers(1, 1, 1)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY / 2
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY / 2
    TUNING.wylra_efficiency = 1.25
    TUNING.WYLRA_speed = 0.55
    TUNING.WYLRA_titan = 0.1 
    inst:RemoveTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    return TUNING.WYLRA_titan
end

This is what I wrote. I used your suggestion as Skinner one didn't do anything

Spoiler

local master_postinit = function(inst)

        inst.OnLoad=function(inst,data) 
        if data and data.titaness then
        if data.titaness == 1 then
        TitanWylra (inst)    
        else
        SmallWylra (inst)    
        end        
        end
        end

        inst.OnSave=function(inst,data)
        data.titaness=inst.WYLRA_titan  
        end
end

Now it's skips both forms completely loading my character as standard dst characters. I can tell because there are neither in small form nor big form effects on her

What am I doing wrong?

Edited by InvarkuI
1 minute ago, InvarkuI said:

I'm sorry I don't get it

I have this functions as 2 forms. There is no third form

This is what I wrote. I used your suggestion as Skinner one didn't do anything

Now it's skips both forms completely loading my character as standard dst characters. I can tell because there are neither in small form nor big form

What am I doing wrong?

At first glance your code looks correct. But it is best to set a fallback in case the data is not loaded at all, or it is the first time the character spawns. Please insert some prints to see at which line the logic goes wrong,

35 minutes ago, Rickzzs said:

At first glance your code looks correct. But it is best to set a fallback in case the data is not loaded at all, or it is the first time the character spawns. Please insert some prints to see at which line the logic goes wrong,

I made it print stuff on save on load and if load happened it should print what was loaded

Spoiler

if data and data.titaness then
        print("WylraData: trying to read.")
        if data.titaness == 1 then
        TitanWylra (inst)
        print("WylraData: loaded - titan.")
        elseif data.titaness ~= 1 then
        SmallWylra (inst)
        print("WylraData: loaded - small.")
        end        
        end

inst.OnSave=function(inst,data)
        data.titaness=inst.WYLRA_titan  
        print("WylraData: saved.")
        end

As I expected it was saved but never was loaded. I checked client_log for WylraData and only saving occurs. Why could this happen?

I tried moving OnLoad function into existing on load func. This didn't help. I still being loaded into default state. Not small nor big. It's likely failing to check "if data and data.titaness then" because it doesn't print "trying to read"

Spoiler

local function onload(inst, data)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
    
    
    if data and data.titaness then
        print("WylraData: trying to read.")
        if data.titaness == 1 then
        TitanWylra (inst)
        print("WylraData: loaded - titan.")
        elseif data.titaness ~= 1 then
        SmallWylra (inst)
        print("WylraData: loaded - small.")
        end        
        end

end

 

function TitanWylra (inst)

    inst.AnimState:SetBuild("wylra_big")
    MakeGiantCharacterPhysics(inst, 1000, 5)
    inst.Physics:SetCapsule(1, 3)
    inst.components.combat:SetDefaultDamage(150)
    inst.Transform:SetScale(2.5, 2.5, 2.5)
    inst.components.combat:SetRange(3, 3)
    inst.components.eater:SetAbsorptionModifiers(0.1, 1, 0.5)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY
    TUNING.wylra_efficiency = 2.5
    TUNING.WYLRA_speed = 0.5
    TUNING.WYLRA_titan = 1 
    inst:AddTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    inst.AnimState:PlayAnimation("powerup")
    return TUNING.WYLRA_titan
    end


function SmallWylra (inst)

    inst.AnimState:SetBuild("wylra")
    MakeGiantCharacterPhysics(inst, 300, 1)
    inst.Physics:SetCapsule(1, 1)
    inst.components.combat:SetDefaultDamage(15)
    inst.Transform:SetScale(2.0, 2.0, 2.0)
    inst.components.combat:SetRange(1.5, 1.5)
    inst.components.eater:SetAbsorptionModifiers(1, 1, 1)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY / 2
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY / 2
    TUNING.wylra_efficiency = 1.25
    TUNING.WYLRA_speed = 0.55
    TUNING.WYLRA_titan = 0.1 
    inst:RemoveTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    return TUNING.WYLRA_titan
end

 

local master_postinit = function(inst)

inst.OnSave=function(inst,data)
        data.titaness=inst.WYLRA_titan  
        print("WylraData: saved.")
        end
end

 

11 minutes ago, InvarkuI said:

I made it print stuff on save on load and if load happened it should print what was loaded

  Reveal hidden contents

if data and data.titaness then
        print("WylraData: trying to read.")
        if data.titaness == 1 then
        TitanWylra (inst)
        print("WylraData: loaded - titan.")
        elseif data.titaness ~= 1 then
        SmallWylra (inst)
        print("WylraData: loaded - small.")
        end        
        end

inst.OnSave=function(inst,data)
        data.titaness=inst.WYLRA_titan  
        print("WylraData: saved.")
        end

As I expected it was saved but never was loaded. I checked client_log for WylraData and only saving occurs. Why could this happen?

I tried moving OnLoad function into existing on load func. This didn't help. I still being loaded into default state. Not small nor big. It's likely failing to check "if data and data.titaness then" because it doesn't print "trying to read"

  Reveal hidden contents

local function onload(inst, data)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
    
    
    if data and data.titaness then
        print("WylraData: trying to read.")
        if data.titaness == 1 then
        TitanWylra (inst)
        print("WylraData: loaded - titan.")
        elseif data.titaness ~= 1 then
        SmallWylra (inst)
        print("WylraData: loaded - small.")
        end        
        end

end

 

function TitanWylra (inst)

    inst.AnimState:SetBuild("wylra_big")
    MakeGiantCharacterPhysics(inst, 1000, 5)
    inst.Physics:SetCapsule(1, 3)
    inst.components.combat:SetDefaultDamage(150)
    inst.Transform:SetScale(2.5, 2.5, 2.5)
    inst.components.combat:SetRange(3, 3)
    inst.components.eater:SetAbsorptionModifiers(0.1, 1, 0.5)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY
    TUNING.wylra_efficiency = 2.5
    TUNING.WYLRA_speed = 0.5
    TUNING.WYLRA_titan = 1 
    inst:AddTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    inst.AnimState:PlayAnimation("powerup")
    return TUNING.WYLRA_titan
    end


function SmallWylra (inst)

    inst.AnimState:SetBuild("wylra")
    MakeGiantCharacterPhysics(inst, 300, 1)
    inst.Physics:SetCapsule(1, 1)
    inst.components.combat:SetDefaultDamage(15)
    inst.Transform:SetScale(2.0, 2.0, 2.0)
    inst.components.combat:SetRange(1.5, 1.5)
    inst.components.eater:SetAbsorptionModifiers(1, 1, 1)
    inst.components.temperature.inherentinsulation = -TUNING.INSULATION_TINY / 2
    inst.components.temperature.inherentsummerinsulation = -TUNING.INSULATION_TINY / 2
    TUNING.wylra_efficiency = 1.25
    TUNING.WYLRA_speed = 0.55
    TUNING.WYLRA_titan = 0.1 
    inst:RemoveTag("Titan")
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "wylra_speed_mod", TUNING.WYLRA_speed)
    return TUNING.WYLRA_titan
end

 

local master_postinit = function(inst)

inst.OnSave=function(inst,data)
        data.titaness=inst.WYLRA_titan  
        print("WylraData: saved.")
        end
end

 

Good news. Loading and Saving both works I changed 

 data.titaness=inst.WYLRA_titan  to  data.titaness= 1

Save occurred and I was loaded in big form. Load message also was there. The problem then is in passing data from FORM func to data.titaness

I will update if I figure it out. If you have ideas then I'm all open to them

2 hours ago, Rickzzs said:

At first glance your code looks correct. But it is best to set a fallback in case the data is not loaded at all, or it is the first time the character spawns. Please insert some prints to see at which line the logic goes wrong,

Problem resolved. All it took was changing inst.WYLRA_titan to tuning.wylra_titan

Thank you for your support. Have a great day. I will close the topic in an hour

I left the finished code in the spoiler for anyone who might encounter the same problem

Spoiler

local function onload(inst, data)

    if data and data.titaness then
        print("WylraData: trying to read.")
        if data.titaness == 1 then
        TitanWylra (inst)
        print("WylraData: loaded - titan.")
        elseif data.titaness ~= 1 then
        SmallWylra (inst)
        print("WylraData: loaded - small.")
        end        
    end
end

function TitanWylra (inst)

    "some changes"

end


function SmallWylra (inst)

    "some other changes"    

end

local master_postinit = function(inst)
    
        inst.OnSave=function(inst,data)
        data.titaness = TUNING.WYLRA_titan
        print("WylraData: saved.")
    end
end

 

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...