Sign in to follow this  

Recommended Posts

I was given the code by a good person and I am very grateful to him.

 

But! it does not work if there are caves in the world and can this be eliminated

 

(One of my friends said that we need to check the caves)

 

how to make it?

Edited by Ghost_starved

Share this post


Link to post
Share on other sites
TheSkylarr    87
4 minutes ago, Ghost_starved said:

I was given the code by a good person and I am very grateful to him.

 

But! it does not work if there are caves in the world and can this be eliminated

 

(One of my friends said that we need to check the caves)

 

how to make it?

Usually when code doesn't work with caves, that means it's not coded properly for a server, which means it probably won't work with multiple players on a server without caves.

 

What kindof error are you getting specifically.

  • Potato Cup 1

Share this post


Link to post
Share on other sites
13 minutes ago, TheSkylarr said:

Usually when code doesn't work with caves, that means it's not coded properly for a server, which means it probably won't work with multiple players on a server without caves.

 

What kindof error are you getting specifically.

just a bug and disconnection of the game.

(If you know, can you suggest the code instead of what I was given before?)
Recovering the sanity of a webber if he is next to my character

Share this post


Link to post
Share on other sites
TheSkylarr    87
4 hours ago, Ghost_starved said:

just a bug and disconnection of the game.

(If you know, can you suggest the code instead of what I was given before?)
Recovering the sanity of a webber if he is next to my character

Can you send me what you were given before?

Share this post


Link to post
Share on other sites
6 hours ago, TheSkylarr said:

Can you send me what you were given before?

inst:AddTag("webberlovemyprettycharacter")

 

Now on your modmain:

 

 

 

local function IsMyPrettyCharacterNearby(inst)

 

    local x, y, z = inst.Transform:GetWorldPosition()

    local num_char = #GLOBAL.TheSim:FindEntities(x, y, z, 10, {"webberlovemyprettycharacter"}) -- Here I'm using a radius equal to 10

 

    if num_char > 0 then

 

     inst.num_char=1

 

    else

 

      inst.num_char=0

 

    end

 

    return 0

 

    -- num_char is 1 if there is at least 1 of yourcharacter nearby, else is 0

 

end

 

local function CustomSanityFn(inst, dt)

 

     return inst.num_char*500 -- a lot of sanity

end

 

 

 

AddPrefabPostInit("webber",function(inst)

 

    inst.num_char=0

    inst._update_character_sanity_task = inst:DoPeriodicTask(3, IsMyPrettyCharacterNearby) -- One verification every 3 seconds

 

    inst.components.sanity.custom_rate_fn = CustomSanityFn

 

end)

Share this post


Link to post
Share on other sites

I have a second one, but it just gives sanity and does not regenerate

local function WebberSanityAura(inst)
local x,y,z = inst.Transform:GetWorldPosition() 
local pt = inst:GetPosition()
local range = 10  -- range of ability
local SANITYREGAIN = 7 -- Amount of Sanity regained to Webber per tick
local tagz = { "_combat"}
local canttagz = {"structure"}

local check = TheSim:FindEntities(pt.x,pt.y,pt.z, range, tagz, canttagz)    
        for _,ent in ipairs(check) do
            if not ent.components.health:IsDead() and ent.prefab == "webber" then            
                ent.components.sanity:DoDelta(SANITYREGAIN)    
                if ent.components.combat then
                    ent.components.combat:SuggestTarget(inst)
                end
            end
        end
end

local function maincheck(inst)
     if not inst.components.health:IsDead() and not inst:HasTag("playerghost") and not inst:HasTag("playermonster") then        
        WebberSanityAura(inst)
    end
end

-- 1 time interval between every tick (seconds-ish, it's not 100% accurate)
inst:DoPeriodicTask(2, maincheck, nil, inst)

end

can it be made regenerative?

Share this post


Link to post
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
Sign in to follow this