Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

Lazzary

I need help with my shark.

Recommended Posts

Lazzary    1

Hello everybody, I need some help with modding my first character. I'm new to modding and I looked up some courses but now I have problems with the game's mechanics and the commands it uses.

My character is supposed to swim and get bonuses when wet. I tried to look through WX's scripts with his lightning strike bonuses, but it didn't help at all, and I thought of using the hounds' swimming mechanics for the other part, will it break the game or something if I do?

Share this post


Link to post
Share on other sites
Yakuzashi    87

Hi. I rarely play DST, so I don't know how this whole water thing works but at the first look "boat" prefab should show you the right direction. You might find this response useless, but this is only one so far and I wanted to be helpful in a slightest degree. I have been thinking about submarine mod or something a like in the future, so when I am done with it I can hopefuly help you. If you have any other perks on your mind then you can post your mod files in attachment and I will try to add them for you. Cheers.

Share this post


Link to post
Share on other sites
Lazzary    1
8 hours ago, Yakuzashi said:

Hi. I rarely play DST, so I don't know how this whole water thing works but at the first look "boat" prefab should show you the right direction. You might find this response useless, but this is only one so far and I wanted to be helpful in a slightest degree. I have been thinking about submarine mod or something a like in the future, so when I am done with it I can hopefuly help you. If you have any other perks on your mind then you can post your mod files in attachment and I will try to add them for you. Cheers.

That would be of utmost help my dear friend. The thing is I need her to have Wigfrid's fight-lifesteal ability, the stronger when wet thing and the swimming, but the boat idea isn't a bad one, not at all! I'll have a look at the boat scripts from the game and see what I can do. 

Share this post


Link to post
Share on other sites
Yakuzashi    87

I am able to implement Wigfrid's lifesteal. I will look inside WX's lua and figure out wet bonus. About swimming, lately I have been experimenting with stategraphs, so maybe I could handle this.

Share this post


Link to post
Share on other sites
maliblues    26

I don't have expereince with characters but understand some of the code. You could listen to the moisture delta event on your character and then run a function whenever changes in wetness detected.

    inst:ListenForEvent("moisturedelta", OnMoistureDelta)

and then on the OnMoistureDelta function have something like

function OnMoistureDelta(inst, data)
    if inst.components.moisture:IsWet() then
       --add perks here
    end
end

I think the character is considered wet when wetness 35 or above. You may also want to add a sanity buff since wetness from inventory items decreases sanity I believe.

You can also add perks depending on the moisture % instead (so a bigger perk the more wetness character has) by using the line below instead of just "IsWet()" used above.

 inst.components.moisture:GetMoisturePercent()

 

Share this post


Link to post
Share on other sites
Yakuzashi    87

I have got solution for 2 of your perks. I must mention that I am not good "mod creator" at all, but I quite like it. So for lifesteal:
 

Quote

local function bloodlust(inst, data)
    local victim = data.victim
    if not inst.components.health:IsDead() then
        local total_health = victim.components.health:GetMaxWithPenalty()
        inst.components.sanity:DoDelta(total_health * .05)
        inst.components.hunger:DoDelta(total_health * .05)
    end
end

goes above master_postinit in your character's_name.lua

and inside master_postinit
 

Quote

    inst:ListenForEvent("killed", bloodlust)

For wet bonus:

Quote

local function misswettshirt(inst)
    if inst.components.moisture ~= nil and inst.components.moisture:GetMoisture() > 0 then
        inst.components.health:SetMaxHealth(333)
    end
end

and
 

Quote

    inst:ListenForEvent("moisturedelta", misswettshirt)

EDIT:
The maliblues' solution above this post should be better for your shark. As I mentioned I am pretty lame.

Share this post


Link to post
Share on other sites
Lazzary    1
Just now, Yakuzashi said:

I have got solution for 2 of your perks. I must mention that I am not good "mod creator" at all, but I quite like it. So for lifesteal:
 

goes above master_postinit in your character's_name.lua

and inside master_postinit
 

For wet bonus:

and
 

EDIT:
The maliblue's solution above this post should be better for your shark. As I mentioned I am pretty lame.

I don't mind at all, I appreciate your help and time! I don't want her health to be very high, as she has only 100. I want to make her more of a kite character so I want a speed boost instead.

Share this post


Link to post
Share on other sites
Lazzary    1
Just now, maliblues said:

I don't have expereince with characters but understand some of the code. You could listen to the moisture delta event on your character and then run a function whenever changes in wetness detected.


    inst:ListenForEvent("moisturedelta", OnMoistureDelta)

and then on the OnMoistureDelta function have something like


function OnMoistureDelta(inst, data)
    if inst.components.moisture:IsWet() then
       --add perks here
    end
end

I think the character is considered wet when wetness 35 or above. You may also want to add a sanity buff since wetness from inventory items decreases sanity I believe.

You can also add perks depending on the moisture % instead (so a bigger perk the more wetness character has) by using the line below instead of just "IsWet()" used above.


 inst.components.moisture:GetMoisturePercent()

 

Thank you very much, this shall help me greatly!!

EDIT: I seem to be in a stop, is there any place that I should put them in the LUA file, or I can just place it around anywhere?

Share this post


Link to post
Share on other sites
Yakuzashi    87
Quote

I want a speed boost instead.

Swap

Quote

inst.components.health:SetMaxHealth(333)

for

Quote

inst.components.locomotor:SetExternalSpeedMultiplier(inst, "YOURCHARACTERSNAMEHERE_speed_mod", 1.35)

You can change value "1.35" to anything you want, but remember to type your character's name in spot I have marked ex. "shark"

Share this post


Link to post
Share on other sites
Lazzary    1
14 hours ago, Yakuzashi said:

Swap

for

You can change value "1.35" to anything you want, but remember to type your character's name in spot I have marked ex. "shark"

I figured the speed multiplier out but I add the functions and the game crashing saying that "<name> or "..." is expected near "moisturedelta" " I don't quite understand what it's trying to say, even after I change the value next to "moisturedelta" to the character's name.

Share this post


Link to post
Share on other sites
Lazzary    1
Just now, Yakuzashi said:

Could you upload whole mod folder ? I will take a look and figure it out

Of course, though I can't really upload the whole folder, it'll get only some of the things on and some of the files. I can give you the script file and have a look though. If you really want, I guess I could fiddle with it and get the whole folder loaded.

wushi.lua

Share this post


Link to post
Share on other sites
Yakuzashi    87

I can't test any of those bugs with only character's prefab. Moreover I can't see anything realted to:

Quote

I figured the speed multiplier out but I add the functions and the game crashing saying that "<name> or "..." is expected near "moisturedelta" " I don't quite understand what it's trying to say, even after I change the value next to "moisturedelta" to the character's name.

indisde wushi.lua

Share this post


Link to post
Share on other sites
Lazzary    1
15 hours ago, Yakuzashi said:

I can't test any of those bugs with only character's prefab. Moreover I can't see anything realted to:

indisde wushi.lua

Aparrently I can't send you the whole folder :( Is there a specific place in which I need to place those functions?

Share this post


Link to post
Share on other sites
Lazzary    1

Thank you very much for the help, as of now the scripts for the character are complete, apart from the swimming but I think I'll just bay that mechanic. If you need some help yourself, just give me a message, with like a drawing or something cause I suck at coding. See ya man, and thanks again.

 

EDIT : Hey actually, maybe you can give me one last help with something. I found this in the hound section, and I wonder if I can use it on an character and what would I need on it.

    if data.amphibious then
        inst:AddComponent("embarker")
        inst.components.embarker.embark_speed = inst.components.locomotor.runspeed
        inst.components.embarker.antic = true

        inst.components.locomotor:SetAllowPlatformHopping(true)

        inst:AddComponent("amphibiouscreature")
        inst.components.amphibiouscreature:SetBanks(bank, bank.."_water")
        inst.components.amphibiouscreature:SetEnterWaterFn(
            function(inst)
                inst.landspeed = inst.components.locomotor.runspeed
                inst.components.locomotor.runspeed = TUNING.HOUND_SWIM_SPEED
                inst.hop_distance = inst.components.locomotor.hop_distance
                inst.components.locomotor.hop_distance = 4
            end)            
        inst.components.amphibiouscreature:SetExitWaterFn(
            function(inst)
                if inst.landspeed then
                    inst.components.locomotor.runspeed = inst.landspeed 
                end
                if inst.hop_distance then
                    inst.components.locomotor.hop_distance = inst.hop_distance
                end
            end)

        inst.components.locomotor.pathcaps = { allowocean = true }
    end

Share this post


Link to post
Share on other sites
Yakuzashi    87

I'll take a look at this in about 4 hours. Gotta study right now, and I can't loose my rhythm

 

EDIT: I have stucked, so I will give it another go tomorrow

Share this post


Link to post
Share on other sites
Lazzary    1
On 2/12/2019 at 3:24 AM, Yakuzashi said:

I'll take a look at this in about 4 hours. Gotta study right now, and I can't loose my rhythm

 

EDIT: I have stucked, so I will give it another go tomorrow

No worries! If you need any help just ask me and I'll look around. If you're not able to do it then it's okay as well, so you can kind stop because I have already posted the mod and it's ready for playing. If you wish to give it a go, search for Wushi The Courages! 

Thanks again! And just ask if you wish for some artistic help!

Share this post


Link to post
Share on other sites
Yakuzashi    87

Hello. I am still struggling with this. The inst:AddComponent("amphibiouscreature") that you have found inside hound prefab is somehow working. I can't crack it, but I am trying. I have to find mechanism that will allow Wushi to jump into water. She does not sink in the water, but she's invisible and bugged. Of course I can't find a way to get out of water too. After I solve those major problems this should be good to go.

Share this post


Link to post
Share on other sites
maliblues    26
6 hours ago, Yakuzashi said:

Hello. I am still struggling with this. The inst:AddComponent("amphibiouscreature") that you have found inside hound prefab is somehow working. I can't crack it, but I am trying. I have to find mechanism that will allow Wushi to jump into water. She does not sink in the water, but she's invisible and bugged. Of course I can't find a way to get out of water too. After I solve those major problems this should be good to go.

Perhaps the stategraph/animatons needed are part of the issue. I see this code regarding swimming on the hound stategraph:

CommonStates.AddAmphibiousCreatureHopStates(states, 
{ -- config
	swimming_clear_collision_frame = 9 * FRAMES,
},
{ -- anims
},
{ -- timeline
	hop_pre =
	{
		TimeEvent(0, function(inst) 
			if inst:HasTag("swimming") then 
				SpawnPrefab("splash_green").Transform:SetPosition(inst.Transform:GetWorldPosition()) 
			end
		end),
	},
	hop_pst = {
		TimeEvent(4 * FRAMES, function(inst) 
			if inst:HasTag("swimming") then 
				inst.components.locomotor:Stop()
				SpawnPrefab("splash_green").Transform:SetPosition(inst.Transform:GetWorldPosition()) 
			end
		end),
		TimeEvent(6 * FRAMES, function(inst) 
			if not inst:HasTag("swimming") then 
                inst.components.locomotor:StopMoving()
			end
		end),
	}
})

 

Share this post


Link to post
Share on other sites
maliblues    26

oh just noticed, since this state is actually added in, it is created in the commonstates.lua file so this is the full code for it:

Spoiler

CommonStates.AddAmphibiousCreatureHopStates = function(states, config, anims, timelines, updates)
	config = config or {}
	anims = anims or {}
	timelines = timelines or {}

	local onenters = (config ~= nil and config.onenters ~= nil) and config.onenters or nil
	local onexits = (config ~= nil and config.onexits ~= nil) and config.onexits or nil

	local base_hop_pre_timeline = {
        TimeEvent(config.swimming_clear_collision_frame or 0, function(inst) 
			if inst.sg.statemem.swimming then
				inst.Physics:ClearCollidesWith(COLLISION.LIMITS)
			end
		end),
	}
	timelines.hop_pre = timelines.hop_pre == nil and base_hop_pre_timeline or JoinArrays(timelines.hop_pre, base_hop_pre_timeline)

    table.insert(states, State
	{
        name = "hop_pre",
        tags = { "doing", "busy", "jumping", "canrotate" },

        onenter = function(inst)
			inst.sg.statemem.swimming = inst:HasTag("swimming")
            inst.AnimState:PlayAnimation("jump")
			if not inst.sg.statemem.swimming then		      
				inst.Physics:ClearCollidesWith(COLLISION.LIMITS)
			end
			if inst.components.embarker:HasDestination() then
	            inst.sg:SetTimeout(18 * FRAMES)
                inst.components.embarker:StartMoving()
			else
	            inst.sg:SetTimeout(18 * FRAMES)
                if inst.landspeed then
                    inst.components.locomotor.runspeed = inst.landspeed 
                end                
                inst.components.locomotor:RunForward()
			end

			if onenters ~= nil and onenters.hop_pre ~= nil then
				onenters.hop_pre(inst)
			end
        end,

	    onupdate = function(inst,dt)                
			if inst.components.embarker:HasDestination() then
				if inst.sg.statemem.embarked then
					inst.components.embarker:Embark()
					inst.components.locomotor:FinishHopping()
					inst.sg:GoToState("hop_pst", false)                    
				elseif inst.sg.statemem.timeout then
					inst.components.embarker:Cancel()
					inst.components.locomotor:FinishHopping()

					local x, y, z = inst.Transform:GetWorldPosition()
					inst.sg:GoToState("hop_pst", not TheWorld.Map:IsVisualGroundAtPoint(x, y, z) and TheWorld.Map:GetPlatformAtPoint(x, z) == nil)
				end
            elseif inst.sg.statemem.timeout or  
                   (inst.sg.statemem.tryexit and inst.sg.statemem.swimming == TheWorld.Map:IsVisualGroundAtPoint(inst.Transform:GetWorldPosition())) or 
                   (not inst.components.locomotor.dest and not inst.components.locomotor.wantstomoveforward) then 
				inst.components.embarker:Cancel()
				inst.components.locomotor:FinishHopping()
				local x, y, z = inst.Transform:GetWorldPosition()
				inst.sg:GoToState("hop_pst", not TheWorld.Map:IsVisualGroundAtPoint(x, y, z) and TheWorld.Map:GetPlatformAtPoint(x, z) == nil)
			end
		end,

        timeline = timelines.hop_pre,

		ontimeout = function(inst)
			inst.sg.statemem.timeout = true          
		end,

        events =
        {
            EventHandler("done_embark_movement", function(inst)
				if not inst.AnimState:IsCurrentAnimation("jump_loop") then
					inst.AnimState:PlayAnimation("jump_loop", false)
				end
				inst.sg.statemem.embarked = true
            end),     
            EventHandler("animover", function(inst)       
				if not inst.AnimState:IsCurrentAnimation("jump_loop") then
					if inst.AnimState:AnimDone() then                    
						if not inst.components.embarker:HasDestination() then                                                               
							inst.sg.statemem.tryexit = true
						end                    
					end 
					inst.AnimState:PlayAnimation("jump_loop", false)
				end
            end),
        },

		onexit = function(inst)
            inst.Physics:CollidesWith(COLLISION.LIMITS) 
			if inst.components.embarker:HasDestination() then
				inst.components.embarker:Cancel()
				inst.components.locomotor:FinishHopping()
			end

			if onexits ~= nil and onexits.hop_pre ~= nil then
				onexits.hop_pre(inst)
			end
		end,
    })

    table.insert(states, State
	{
        name = "hop_pst",
        tags = { "busy", "jumping" },

        onenter = function(inst, land_in_water)
			if land_in_water then
				inst.components.amphibiouscreature:OnEnterOcean()	            
			else
				inst.components.amphibiouscreature:OnExitOcean()	            
			end

			if onenters ~= nil and onenters.hop_pst ~= nil then
				onenters.hop_pst(inst)
			end

            inst.AnimState:PlayAnimation("jump_pst")
        end,

        timeline = timelines.hop_pst,

        events =
        {
            EventHandler("animover", function(inst)
                if inst.AnimState:AnimDone() then
                    inst.sg:GoToState("idle")
                end
            end),
        },

        onexit = function(inst)
			if onexits ~= nil and onexits.hop_pst ~= nil then
				onexits.hop_pst(inst)
			end
		end,
    })

    table.insert(states, State
    {
        name = "hop_antic",
        tags = { "doing", "busy", "jumping", "canrotate" },

        onenter = function(inst)
            inst.components.locomotor:StopMoving()
            inst.sg.statemem.swimming = inst:HasTag("swimming")

            inst.AnimState:PlayAnimation("jump_antic")    

            inst.sg:SetTimeout(30 * FRAMES)

			if onenters ~= nil and onenters.hop_antic ~= nil then
				onenters.hop_antic(inst)
			end
        end,

        timeline = timelines.hop_antic,

        ontimeout = function(inst)
            inst.sg:GoToState("hop_pre")
        end,
        onexit = function(inst)
			if onexits ~= nil and onexits.hop_antic ~= nil then
				onexits.hop_antic(inst)
			end
        end,        
    })
end

 

I'm not sure if the the character already has these jump animations but I suspect they might because of wormhole/boat jumping but the "hop" ones I'm unsure about.

Share this post


Link to post
Share on other sites
Lazzary    1

Guys this is cool! We might be able to break in through a way of making swimming a real thing in mods!

 

EDIT: I have tried the upper function and nothing happens. Tried pressing all buttons, and walking through water. Maybe it needs something to trigger it.

Share this post


Link to post
Share on other sites