Jump to content

Change texture when rain


Recommended Posts

Hi guys! Please, help me:

i try to add function, that changed character texture when rain, and return it back when character dry

my code changed texture, but not returned it 

i tried so much time but nothing, i used WX78 code 


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
        Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
        Asset("SCRIPT", "scripts/prefabs/vergil_fx.lua"),
        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),
        Asset( "SOUND", "sound/wilson.fsb" ),
        Asset( "ANIM", "anim/beard.zip" ),

        Asset( "ANIM", "anim/vergil.zip" ),
		Asset( "ANIM", "anim/vergil_rain.zip" ),
		Asset( "ANIM", "anim/vergil_devil.zip" ),
		Asset( "ANIM", "anim/ghost_vergil_build.zip" ),
		
		Asset( "ATLAS", "images/avatars/avatar_vergil.xml"),
		Asset( "ATLAS", "images/avatars/avatar_ghost_vergil.xml"),
		
	
}
local prefabs = {
	
	
}
local start_inv = {
	-- Custom starting items
"yamato",
}



-- When the character is revived from human







local function common_postinit(inst)
	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "vergil.tex" )
	inst:AddTag("vergil")
    inst:AddComponent("keyhandler")
    inst.components.keyhandler:AddActionListener("vergil", TUNING.VERGIL.KEY, "TRIGGER")
	inst:AddTag("vergilspecific")
	inst.TransformIsActive = false
	
	
	
		
end

local function VergilRain(inst)
    if inst.components.moisture ~= nil and inst.components.moisture:GetMoisture() > 0 then
		
            inst:DoTaskInTime(7 * FRAMES, function()
           -- inst.components.health:SetAbsorptionAmount(0) 
			inst.AnimState:SetBuild("vergil_rain")
	
	end)
end
end

local function VergilRainOut(inst)
    if inst.components.moisture == nil then
		
            inst:DoTaskInTime(7 * FRAMES, function()
           -- inst.components.health:SetAbsorptionAmount(0) 
			inst.AnimState:SetBuild("vergil")
	
	end)
end
end

local function onisraining(inst, israining)
    if israining then
        if inst.spark_task == nil then
            inst.spark_task = inst:DoTaskInTime(1, VergilRain)
			 
        end
    elseif inst.spark_task ~= nil then
	 inst.spark_task = inst:DoTaskInTime(1, VergilRainOut)
        inst.spark_task:Cancel()
        inst.spark_task = nil
    end
end




local function onbecamehuman(inst)
	-- Set speed when reviving from ghost (optional)
	-- inst.components.locomotor:SetExternalSpeedMultiplier(inst, "vergil_speed_mod", 1)
	inst:WatchWorldState("israining", onisraining)
       onisraining(inst, TheWorld.state.israining)
	if CONTROLS then
    end
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
    -- inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "vergil_speed_mod")
	 if inst.watchingrain then
        inst.watchingrain = false
        inst:StopWatchingWorldState("israining", onisraining)
    end
   if CONTROLS then
   end
end

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

local fn = function(inst)

	
	-- choose which sounds this character will play
	inst.soundsname = "wilson"
	
	-- Stats	
	inst.components.health:SetMaxHealth(150)
	inst.components.hunger:SetMax(150)
	inst.components.sanity:SetMax(200)
	
	-- Damage multiplier (optional)
    inst.components.combat.damagemultiplier = 1
	
	-- Hunger rate (optional)
	inst.components.hunger.hungerrate =  TUNING.WILSON_HUNGER_RATE
	
	-- Movement speed (optional)
	inst.components.locomotor.walkspeed = 6
	inst.components.locomotor.runspeed = 8
	inst.components.sanity.neg_aura_mult = 0.9
	inst.components.combat.min_attack_period = 0.5
	inst.components.sanity.night_drain_mult = 0.9
    
   
   
	inst.spark_task = nil
	inst.watchingrain = false
	
    inst.OnLoad = onload
    inst.OnNewSpawn = onload
	inst.transformedCd = false
	
   -- inst:ListenForEvent("rain", onisraining)
	
end

return MakePlayerCharacter("vergil", prefabs, assets, common_postinit, fn, start_inv)

 

Link to comment
Share on other sites

VergilRainOut is wrong. You just check whether the moisture component is on the player, and if it is not nil, you don't do anything. The moisture component never goes anywhere. It's always there. Just check if inst.components.moisture:GetMoisture() == 0

Link to comment
Share on other sites

inst:WatchWorldState("israining", onisraining)

You have to put this thing in fn() and it will work.
This lets the entity to see if TheWorld is raining. 
Read below if you want more information.

The code you put and comment

inst:ListenForEvent("rain", onisraining)

won't work because that entity doesn't have the event listening about "rain". 
Try not to put a random event name there. it won't work and just be a memory waste.
Instead, search through the game files and find which one is the event you looking for.

An event is raised by 

inst:PushEvent("eventname", datatable)

a method named PushEvent() which let inst to execute "fn" with datatable(optinal) when it has

inst:ListenForEvent("eventname", fn)

the event named "eventname".

inst:WatchWorldState("eventname", fn)

This method is to let inst listen to the event named "eventname" and execute fn.
You can think that "raining" is "world event" so if there's something related to the world, 
you have to use that method instead.
 

There're many examples exist in the game files. Check if you want more expressions.

inst.spark_task = inst:DoTaskInTime(1, VergilRain)

Since it doesn't need to be the "task", you may change this to something like

inst.IsVergilRain = true

bool variable which checks whether your character is currently VergilRain state.


Just some.. rework is needed for you since you copied wx-78's code and some unnecessary thing would be left even after your code will seem to be work.

inst.components.moisture:GetMoisture() > 0

This will not work if the character is fully-waterproofed at the start of rain.
But checking WorldState would be enough. Because it simply "see"s if rain. 

Edited by YakumoYukari
Link to comment
Share on other sites

oh, maybe i not actually understand you or do sometshing wrong

i add 

inst:WatchWorldState("israining", onisraining)

to local fn = function(inst)

but nothing changed

it's my 3 mod, but I still bad in code, too many things that I don't know how it actually work

Link to comment
Share on other sites

That's because Listener function will be executed AFTER the event raised.

if not inst.watchingrain then
  inst.watchingrain = true
  inst:WatchWorldState("israining", onisraining)
  onisraining(inst, TheWorld.state.israining)
end

According to the wx-78's code, you have to set the initial state whether if rain.

Edited by YakumoYukari
Link to comment
Share on other sites

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
 Share

×
  • Create New...