Jump to content

Books Function Modification


Recommended Posts

I want to make books more customizable: Number of birds, tentacles, sanity loss, etc...

I can't understand why code crashing and freezing my game :(
Any help would be helpful.

Thanks!

AddPrefabPostInit("book_tentacles", function(inst)
	inst.components.book.onread = function(inst, reader)
            local pt = reader:GetPosition()
            local numtentacles = 3

            reader.components.sanity:DoDelta(-TUNING.SANITY_HUGE)

            reader:StartThread(function()
                for k = 1, numtentacles do
                    local theta = math.random() * 2 * PI
                    local radius = math.random(3, 8)

                    local result_offset = FindValidPositionByFan(theta, radius, 12, function(offset)
                        local pos = pt + offset
                        --NOTE: The first search includes invisible entities
                        return #TheSim:FindEntities(pos.x, 0, pos.z, 1, nil, { "INLIMBO", "FX" }) <= 0
                            and TheWorld.Map:IsPassableAtPoint(pos:Get())
							and TheWorld.Map:IsDeployPointClear(pos, nil, 1)
                    end)

                    if result_offset ~= nil then
                        local x, z = pt.x + result_offset.x, pt.z + result_offset.z
                        local tentacle = SpawnPrefab("tentacle")
                        tentacle.Transform:SetPosition(x, 0, z)
                        tentacle.sg:GoToState("attack_pre")

                        --need a better effect
                        SpawnPrefab("splash_ocean").Transform:SetPosition(x, 0, z)
                        ShakeAllCameras(CAMERASHAKE.FULL, .2, .02, .25, reader, 40)
                    end

                    Sleep(.33)
                end
            end)
            return true
        end
end)

 

Edited by Vlad Undying
Link to comment
Share on other sites

Really weird. I don't see anything wrong in your code, and it passes the syntax checks...must be something inside the loop. Have you tried commenting out each section, starting from the bottom? Like, comment out camera shake, comment out spawning waves, comment out spawning of tentacles. comment out calculating result_offset...etc. to see what makes it stop? I can't think of anything else, if you don't see any errors in your log files.

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