DarkXero Posted January 20, 2015 Share Posted January 20, 2015 Minutes ago, I tried the Hide the Hud mod, and pressing H to hide the hud worked only for the host. I tried:GLOBAL.TheInput:AddKeyDownHandler(GLOBAL.KEY_K, function(key) print("Hello world") end)But it only worked for the host.And print(TheInput:GetWorldEntityUnderMouse()) works for the client. I have tried adding functions, commands, and components to things from the client side and they don't work if the server doesn't have them, or only the server can do them. For example, my attachment. It works for the host but it doesn't for the client. Why? The OnUpdate only runs on the host and it doesn't on the client? Where can I attach a periodic task for the client? Test.zip Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/ Share on other sites More sharing options...
Kzisor Posted January 20, 2015 Share Posted January 20, 2015 (edited) @DarkXero, are you talking about my Toggle HUD mod? If so, then the server must have it installed because it adds the keyhandler component to all characters. Edited January 20, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/#findComment-603928 Share on other sites More sharing options...
DarkXero Posted January 20, 2015 Author Share Posted January 20, 2015 (edited) @Kzisor, yes, I don't know why it didn't work for me. edit: I thought it was client side only. Regardless, my point still stands, I take the postinits only work if you are the host then? How can I make the client run custom commands based on what happens to him or the world? For example, I want the client to press the key K and run ThePlayer:EnableMovementPrediction(false).Or press K and run print("Hello"). Edited January 20, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/#findComment-603939 Share on other sites More sharing options...
Kzisor Posted January 20, 2015 Share Posted January 20, 2015 @DarkXero, I have not looked into making that happen. I think I know of a few ways of doing it, however, I was working on getting nightvision working fully on non-dedicated servers, which is impossible with how the current game mechanics work. I will look into making the Toggle HUD client side only and create a guide on how it's done. Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/#findComment-603958 Share on other sites More sharing options...
Kzisor Posted January 20, 2015 Share Posted January 20, 2015 (edited) @DarkXero, you will need the following code to make it work correctly on the client*. local prediciton = truelocal function OnKeyPressed(key) if key == GLOBAL.KEY_K then if prediction then GLOBAL.ThePlayer:EnableMovementPrediction(false) prediction = false else GLOBAL.ThePlayer:EnableMovementPrediction(true) prediction = true end endendlocal function OnRawKey(key, down) if (key and not down) and not GLOBAL.IsPaused() then OnKeyPressed(key) endendlocal function ControlsPostConstruct(inst) local handler_prediction = GLOBAL.TheInput:AddKeyHandler(function(key, down) OnRawKey(key, down) end )endlocal function ConsolePostConstruct(inst)function inst:OnBecomeActive()GLOBAL.SetPause(true)inst._base.OnBecomeActive(inst)TheFrontEnd:ShowConsoleLog()inst.console_edit:SetFocus()inst.console_edit:SetEditing(true)TheFrontEnd:LockFocus(true)endfunction inst:OnBecomeInactive() GLOBAL.SetPause(false) inst._base.OnBecomeInactive(self) if inst.runtask ~= nil then inst.runtask:Cancel() inst.runtask = nil endendreturn instendlocal function ChatPostConstruct(inst)function inst:OnBecomeActive()GLOBAL.SetPause(true)inst._base.OnBecomeActive(inst)inst.chat_edit:SetFocus()inst.chat_edit:SetEditing(true)TheFrontEnd:LockFocus(true)endfunction inst:OnBecomeInactive() GLOBAL.SetPause(false) inst._base.OnBecomeInactive(self) if inst.runtask ~= nil then inst.runtask:Cancel() inst.runtask = nil endendreturn instendAddClassPostConstruct("screens/consolescreen", ConsolePostConstruct)AddClassPostConstruct("screens/chatinputscreen", ChatPostConstruct)AddClassPostConstruct("widgets/controls", ControlsPostConstruct) * has been edited. Edited January 20, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/#findComment-604070 Share on other sites More sharing options...
DarkXero Posted January 20, 2015 Author Share Posted January 20, 2015 @Kzisor, awesome. This works because screens and widgets are loaded by host and client seperately, right? Maybe there is a way to attach something to replicas? The world and entites of the client are replicas, right? The not replicas are the things you c_spawn as the client but you can do nothing with them because they don't have components as per the ismastersim if. Link to comment https://forums.kleientertainment.com/forums/topic/49422-how-to-run-a-client-side-thing-only/#findComment-604176 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