Jump to content

[HELP] Make character have a chance to grow flowers with each step in Spring?


Recommended Posts

As the question says, I intend to give a chance to spawn a flower under the character as he moves, in a specific season (in this case spring).

And also, if anyone answers this, can you please also specify how to edit the distance needed until a check, how to limit the number of flowers spawned in a period of time, and how I can attach more conditions to modify the chance? (high/low sanity, high/low health)

Thanks a lot in advance!

Link to comment
Share on other sites

Stalker_Forest in the Stalker.lua file should help you there as Lumina has stated.

As you only want to look for spring to activate this, you'll need inst:WatchWorldState("isspring", *your_Function*) in your character's fn(probably common) setup.

This line might help you for checking for situational season changes:

if TheWorld.state.isspring then
-- spring is here
else
 -- it's not spring
end

 

Edited by MorickClive
Link to comment
Share on other sites

@MorickClive Thanks for your help, and would you mind some more newb questions? I saw stalker_berry and stalker_bulb, the files for the types of flowers the Stalker spawns in Prefabs, but I do not understand the code that interacts with those files.

 function(offset)
            local x1 = x + offset.x
            local z1 = z + offset.z
            return map:IsPassableAtPoint(x1, 0, z1)
                and map:IsDeployPointClear(Vector3(x1, 0, z1), nil, 1)
                and #TheSim:FindEntities(x1, 0, z1, 2.5, { "stalkerbloom" }) < 4
        end

What does the part after Return mean? I figure that it's for checking if items can be spawned at that coordinate, but I do not understand the "stalkerbloom"

Also I don't really understand what DoPeriodicTask and DoTaskInTime do in this 

local function OnStartBlooming(inst)
    DoTrail(inst)
    inst._bloomtask = inst:DoPeriodicTask(3 * FRAMES, DoPlantBloom, 2 * FRAMES)
end

local function _StartBlooming(inst)
    if inst._bloomtask == nil then
        inst._bloomtask = inst:DoTaskInTime(0, OnStartBlooming)
    end

I would like to receive a bit more advice. I don't have much doing or modding experience, but I do have quite some time on my hands. I am willing to, but not sure if I need to learn to code in lua from the start, or if I can rely on templates because some other things I want to do are not in the templates, and I don't understand the functions and scripts in the prefabs (of course I see what it will do by looking at the name, but I dont know how to implement it or what exactly causes what) (I am reading the tutorials as I create the character)

Edited by dudedudedude
Link to comment
Share on other sites

Multi-part explanation coming up; sorry for length. ^^'

General explanation

Unlike normal glow berries and light/fern plants, the stalker_forest has special animations associated with the creation of each of it's own plants. In this regard they have unique prefabs to handle each that appear to grow and wither(both with animations attached). On creation the stalker plants will bloom and then exist for a few seconds before withering.

You should definitely spawn him in via console to see what I mean: " c_spawn("stalker_forest", 1) ". he'll die if spawned on the surface; but will still spawn in some plants that express it well.

Bare this in mind - it's likely that only the assets for these plants can support growth animations, I handled a similar problem with my nature monolith by spawning in the flowers with an additional fx each time to make it seem more believable.

Direct question answers

To your questions, return usually indicates a value the function will output. In this case it's a if statement, so there are several conditional statements there that are designed to return a bool value. In theory:

            return map:IsPassableAtPoint(x1, 0, z1)
                and map:IsDeployPointClear(Vector3(x1, 0, z1), nil, 1)
                and #TheSim:FindEntities(x1, 0, z1, 2.5, { "stalkerbloom" }) < 4

Check if the point we've found is clear and passable, if there's less than 3 "stalkerbloom"s then this spot is "true" or clear for spawning.

if any of those conditions are false the check will fail.

-- Tasks explained

DoPeriodicTask and  DoTaskInTime are both operations entities can perform, at any time an entity has a list of tasks it runs when given:

inst:DoTaskInTime(time_val, *your_function* ) -- this will create a function runs in the time allocation you set.

inst:DoPeriodicTask(time_interval_val, *your_function* ) -- this will create a function that'll call itself when it finishes and meets the time interval set.

In addition you may see occasions where your "inst" will include a function that requires a parameter but doesn't include it., this is usually because lua reads the active table as being a parameter, meaning that functions that include self or inst without declaring it often refer to the object/table calling it.

Further lua support - ( of which I myself also find handy)

If you'd like to master the syntax there are plenty of tutorials on lua, I'd say that even I get relatively confused when it comes to meta tables though(but they are often used in specific circumstances that most modders don't need to worry about).

Try SciTE for testing theoretic code out, it's what I use: http://www.scintilla.org/SciTEDownload.html (download the respective "executable" version).

Edited by MorickClive
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...