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.


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


                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)

                    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)

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

            return true


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

  • Create New...