Jump to content

[help?] "_replica" components.... and overwriting "replica" components


Recommended Posts

As far as I understand components with "replica" ending (e.g. sanity_replica) work on clients only, and aren't sycned directly by host. Am I right?

 

I need a function, what works at client, so I can use "ThePlayer" getting actual player, not host.

In sanity.lua " ThePlayer " refrers to host always, so I tried to use  "sanity_replica.lua"...

 

I tried to overwrite such component by just copy-pasting it into mod's component folder. But if I call function I added to sanity_replica.lua, game crashes.

 

The function I added:

function Sanity:Fakemessage(0, nameof, pharseforclone) ThePlayer.HUD.controls.networkchatqueue:OnMessageReceived(0, nameof, pharseforclone)end

I don't understand how to overwrite it... component file name is "sanity_replica", but the file itself ends as:return Sanity

Any ideas how to overwrite "_replica" component?

Edited by Desblat
Link to comment
Share on other sites

@Desblat, Try using something like this instead: (in my opinion this is actually a good idea to do generally, because overwriting a file entirely is likely to botch compatibility with other mods)

AddClassPostConstruct("components/sanity_replica", function(self) --[[stuff]] end)
Link to comment
Share on other sites

A component replica is created on every client, event for player entities, and also the host. I suggest you don't touch replicas unless you're really familiar with their internals (check the Replica class in entityscript.lua and entityreplica.lua).

Your particular case can be handled by a clientside component. Do

AddPlayerPostInit(function(player)    if player == GLOBAL.ThePlayer then        player:AddComponent("myclientsidecomponentwhichdoesntequireanyserversidestuff")    endend)
EDIT: Actually, I don't think "player == GLOBAL.ThePlayer" will work, because ThePlayer is probably set after the postinit runs... I can't find where ThePlayer is set, it seems this is done by the engine itself. I'll probe into it some more. Nonetheless, you should do some check which would tell you the 'player' entity is the local player.

EDIT 2: Ok, this should work, but there must be a simpler way:

AddPrefabPostInit("world", function(wrld)    wrld:ListenForEvent("playeractivated", function(wlrd, player)        if player == GLOBAL.ThePlayer then            player:AddComponent("myclientsidecomponentwhichdoesntequireanyserversidestuff")        end    end)end)
Edited by simplex
Link to comment
Share on other sites

@rezecib

TY, this will work. However I need a way to call client side function from the host.

 

@simplex

Thanks a lot, you told me the exact thing I needed. Is it possible to create client-side mob? Or client can not spawn mobs at all.

Link to comment
Share on other sites

A component replica is created on every client, event for player entities, and also the host. I suggest you don't touch replicas unless you're really familiar with their internals (check the Replica class in entityscript.lua and entityreplica.lua).

Your particular case can be handled by a clientside component. Do

AddPlayerPostInit(function(player)    if player == GLOBAL.ThePlayer then        player:AddComponent("myclientsidecomponentwhichdoesntequireanyserversidestuff")    endend)
EDIT: Actually, I don't think "player == GLOBAL.ThePlayer" will work, because ThePlayer is probably set after the postinit runs... I can't find where ThePlayer is set, it seems this is done by the engine itself. I'll probe into it some more. Nonetheless, you should do some check which would tell you the 'player' entity is the local player.

EDIT 2: Ok, this should work, but there must be a simpler way:

AddPrefabPostInit("world", function(wrld)    wrld:ListenForEvent("playeractivated", function(wlrd, player)        if player == GLOBAL.ThePlayer then            player:AddComponent("myclientsidecomponentwhichdoesntequireanyserversidestuff")        end    end)end)

I love you... I love you. I love you. I love you. I love you. I love you. I love you. 

using this i got all my modmain shiz to load after entering the game rather then at the menu allowing me to set my recipies on a tuning value set only by the host :)

(assuming a client trying to change a tuning value crashes... i hope so...)

 

i wont be able to test it till later today with a client but it looks pretty.

if you wanna check it out along with the issue i tagged you in on my post they are in this mod

http://steamcommunity.com/sharedfiles/filedetails/?id=359606820

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