Jump to content

Is there a function that activates when a player joins a server?


Recommended Posts

A glitch is happening within a mod that I am tweaking around with. in said mod, a structure built on top of a lake, is harvestable after a short period of time. The glitch that I am referring to is that when a player leaves a server and comes back, the graphic that is shown to signify that said structure is harvestable, is gone. Does anybody know of a function that activates when a player joins a server, so I can make it so that upon joining the server, the mod can check whether or not the structure is harvestable, and re-enable the graphic as a result. I have tried to use "Onload" to fix this problem as follows: If you know a better way to implement what I am trying to do here, tell me please.

But nothing happens, the structure still shows to be empty when it is harvestable. 

tl;dr: What is a function that activates when a player joins the game, or alternatively what is a better way to implement what is shown in the picture?

Edited by lbphero
Link to comment
Share on other sites

1 hour ago, YakumoYukari said:

If the issue is like that, probably the ultimate solution is not the way like this.
But there's an event that activates every time someone joins.
 


inst:ListenForEvent("ms_playerjoined", somefunc, TheWorld)

So, Like this? 

9ce3e84d2a4900bdc25eab14df20c19e.png

EDIT: I tried to use this as depicted, but the game seems to want me to put a name next to the ms_playerjoined, somehow.

Edited by lbphero
Link to comment
Share on other sites

It would help if you posted the mod or more data.

AnimState should propagate correctly to clients when changing (using "Show").

 

As an example, here's the correct usage:

-- prefab file


local function PlayerFix(inst)
    if not inst:HasTag("depleted") then
        inst.extractor.AnimState:Show("salt")
    end
end


local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    -- ...
    inst.entity:AddNetwork()

    -- here
    inst:ListenForEvent("ms_playerjoined", function(world, player) PlayerFix(inst) end, TheWorld)

    -- ...

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    -- ...

    return inst
end

 

More interesting would be to see the extractor prefab. It's probably missing a AddNetwork that would solve this without hassle.

  • Like 1
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...