s1m13 Posted June 24, 2019 Share Posted June 24, 2019 Hey ho, is it correct, that it is not possible to register for events using ListenForEvent in a client only mod?: AddComponentPostInit("health", function(Health, inst) inst:ListenForEvent("healthdelta", function(inst, data) if inst.components.health then ----- end end) end) Would be happy for any confirmation in any direction. Thanks a lot! Link to comment Share on other sites More sharing options...
Ultroman Posted June 25, 2019 Share Posted June 25, 2019 Client-only mods are restricted from making changes to the server, and thus can only alter things on the client-side, like the UI. I'm not entirely sure about your query. Why don't you try it out? Link to comment Share on other sites More sharing options...
s1m13 Posted June 27, 2019 Author Share Posted June 27, 2019 My code does not work. I was asking for whether I made principle mistake, or whether it's impossible generally. Link to comment Share on other sites More sharing options...
Developer zarklord_klei Posted June 27, 2019 Developer Share Posted June 27, 2019 13 hours ago, s1m13 said: My code does not work. I was asking for whether I made principle mistake, or whether it's impossible generally. depends on what you trying to do. Link to comment Share on other sites More sharing options...
CarlZalph Posted June 27, 2019 Share Posted June 27, 2019 (edited) @s1m13 It's perfectly fine to listen for events on the client side. However, you're trying to check for a component that doesn't exist entirely on the client. The health component check you're doing there will always return false as a client when it is also not the server (no cave self host). See: player_common.lua and how `inst:AddComponent("health")` happens after the "if not TheWorld.ismastersim then" check. It exists only in a replica state on the client side. You can touch the replica health via: inst.replica.health This does not exist on the server however, so mind your checks. Further, you do not have access to the health component replica of anything that isn't you the player by default. So doing a global component postinit is effectively just hooking your player, which at that point you may as well do a player post init and check against the GLOBAL.ThePlayer variable or something. Or a "world" prefab post init and then listen for "playeractivated" while still checking against GLOBAL.ThePlayer. Edited June 27, 2019 by CarlZalph Link to comment Share on other sites More sharing options...
s1m13 Posted June 28, 2019 Author Share Posted June 28, 2019 Thanks @CarlZalph, I will give it a try. 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