gregdwilson Posted May 4, 2015 Share Posted May 4, 2015 In my mod Shadow Dragons I have an event where the player becomes tired after using an item through an even push. In single player this works fine but I cannot figure out a way to have the event pushed the client. I found out that you can't call inst.HUD since this is removed from the client on the server. I also tried using a seperate mod that would run on the client and watch for the event but it still doesn't seem to work. Here is the code for the seperate mod I was trying to use. All implemented in modmain local function StatusPostConstruct(self)--Create the Tired status label self.tiredtext = self:AddChild(Text(GLOBAL.NUMBERFONT, 28)) self.tiredtext:SetScale(1,.78,1) self.tiredtext:SetPosition(40,-55.5,0) self.tiredtext:SetString("Tired")--Initialize the state. if self.owner:HasTag("tired") then self.tiredtext:Show() else self.tiredtext:Hide() end --Listen for triggertired even to update tired status self.inst:ListenForEvent("triggertired", function(inst) if self.owner:HasTag("tired") then self.tiredtext:Show() else self.tiredtext:Hide() end end, self.owner) endAddClassPostConstruct("widgets/statusdisplays", StatusPostConstruct) Link to comment https://forums.kleientertainment.com/forums/topic/53495-push-client-hud-event/ Share on other sites More sharing options...
Kzisor Posted May 4, 2015 Share Posted May 4, 2015 @gregdwilson, you have to use a net variable in order to send an event to the client. You can learn more about net variabled form this post: http://forums.kleientertainment.com/topic/48264-net-variable-types-and-sending-data-from-serverhost-to-clients/ Link to comment https://forums.kleientertainment.com/forums/topic/53495-push-client-hud-event/#findComment-634358 Share on other sites More sharing options...
gregdwilson Posted May 5, 2015 Author Share Posted May 5, 2015 So I tried net_variables but with no luck Here is my function local function fn() inst.AddComponent( inst.Tired = net_bool(inst.GUID, "triggertired", "triggertireddirty") inst.Tired:set(true) inst:ListenForEvent("triggertireddirty", OnPlayerTiredDirty) endend which I call in common_postinit in my character lua The listener function is then given by local function OnPlayerTiredDirty(inst) if inst.TiredStatus ~= nil then if inst.Tired:value() then inst.TiredStatus:Show() else inst.TiredStatus:Hide() end endend where TiredStatus is my HUD element set up in mod main by function StatusPostConstruct(self) self.TiredStatus = self:AddChild(Text(GLOBAL.NUMBERFONT, 28), self.owner) self.TiredStatus:SetScale(1,.78,1) self.TiredStatus:SetPosition(40,-55.5,0) self.TiredStatus:SetString("Tired") if self.inst:HasTag("tired") then self.TiredStatus:Show() else self.TiredStatus:Hide() endendAddClassPostConstruct("widgets/statusdisplays", StatusPostConstruct) I then use "owner.Tired:set(true)" in the OnUnequip function in my custom item lua. It is also changed in the onwake function of the sleepingbag component in modmain usingself.sleeper.Tired:set(false) Again, this works fine in singleplayer using PushEvent and event listeners but I have been unable to get it to work with a client. Am I calling the statusdisplay wrong by using inst.TiredStatus:Show() in OnPlayerTiredDirty? I know that TireStatus initializes for the client becuase if I set it as visible when I declare it in modmain it shows up on the client. I just can't get it to switch with the net variable. In the net_bool declaration inst.Tired = net_bool(inst.GUID, "triggertired", "triggertireddirty") what exactly do "triggertired" and "triggertireddirty" do. I thought they were like event markers which you can then listen to. Any help would be appreciated Link to comment https://forums.kleientertainment.com/forums/topic/53495-push-client-hud-event/#findComment-634590 Share on other sites More sharing options...
Kzisor Posted May 5, 2015 Share Posted May 5, 2015 (edited) @gregdwilson, in the example you've given if you are using it exactly as shown, you have a coding syntax error. inst:AddComponent( is never adding an actual component. To Quote the relevant post: In our latest hotfix, we've added a net_event wrapper.net_event = Class(function(self, guid, event)self._bool = net_bool(guid, event, event)end)function net_event:push()self._bool:set_local(true)self._bool:set(true)end--Example:inst.screenshakeevent = net_event(inst.GUID, "screenshake")inst:ListenForEvent("screenshake", OnScreenShake)--Servers can push this and it will trigger on clientsinst.screenshakeevent:push() Edited May 5, 2015 by Kzisor Link to comment https://forums.kleientertainment.com/forums/topic/53495-push-client-hud-event/#findComment-634637 Share on other sites More sharing options...
gregdwilson Posted May 5, 2015 Author Share Posted May 5, 2015 Thanks @Kzisor, I figured it out. I put my solution in the thread you linked. Thanks for your help. Link to comment https://forums.kleientertainment.com/forums/topic/53495-push-client-hud-event/#findComment-634680 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