Desblat Posted December 20, 2014 Share Posted December 20, 2014 (edited) 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)endI don't understand how to overwrite it... component file name is "sanity_replica", but the file itself ends as:return SanityAny ideas how to overwrite "_replica" component? Edited December 21, 2014 by Desblat Link to comment Share on other sites More sharing options...
rezecib Posted December 20, 2014 Share Posted December 20, 2014 @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 More sharing options...
simplex Posted December 21, 2014 Share Posted December 21, 2014 (edited) 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. DoAddPlayerPostInit(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 December 21, 2014 by simplex Link to comment Share on other sites More sharing options...
Desblat Posted December 21, 2014 Author Share Posted December 21, 2014 @rezecibTY, this will work. However I need a way to call client side function from the host. @simplexThanks 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 More sharing options...
Kam297 Posted December 21, 2014 Share Posted December 21, 2014 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. DoAddPlayerPostInit(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 modhttp://steamcommunity.com/sharedfiles/filedetails/?id=359606820 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now