mouse Posted June 30, 2015 Share Posted June 30, 2015 Long story short:I created a series of buttons. When the player clicks a button, all buttons disappear and things happen.One of the things that happen is giving the player an item. Right now that's not happening.From what I understand, all I have to do is:local function eventxfunction() print("stuff happens")endAddPlayerPostInit(function(inst) inst.eventx=GLOBAL.net_event(inst.GUID, "eventxname", eventxfunction)end)AddClassPostConstruct("widgets/statusdisplays", function(self)--blah blah blah button stuff buttonx:SetOnClick(function() self.owner.eventx:Push() end)end)But that gives the error: "push" is a nil value.Am I using net_event wrong or something? Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/ Share on other sites More sharing options...
Kzisor Posted June 30, 2015 Share Posted June 30, 2015 @mouse, from client to server you need to use MOD RPC's. http://forums.kleientertainment.com/files/file/1126-tutorial-mod-rpcs-with-keyhandler/ Server to client it's net_event. Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/#findComment-651092 Share on other sites More sharing options...
mouse Posted July 1, 2015 Author Share Posted July 1, 2015 @mouse, from client to server you need to use MOD RPC's. http://forums.kleientertainment.com/files/file/1126-tutorial-mod-rpcs-with-keyhandler/ Server to client it's net_event. No sorry, by "button" I mean imagebutton. It's a series of GUI buttons on the screen. For anybody stumbling across this thread in the future, the first problem was "Push" isn't supposed to be capitalized. Now the problem I'm having is I can't give any items to the player after the button is clicked. I take it the client can't change a server value via inst._netvar:set(var)? Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/#findComment-651112 Share on other sites More sharing options...
DarkXero Posted July 1, 2015 Share Posted July 1, 2015 I take it the client can't change a server value via inst._netvar:set(var)? A netvar is a variable that exists both in the server and the client.If the server sets the variable, then the changes propagate. A client can change a netvar like that, for example, the one that tells you that you are taking fire damage in health replica.The arrow down for the health badge will pop up. However your health won't go down.This change won't propagate to the server. And if the server changes the netvar, the netvar in the client will change. This is what Kzisor means:AddModRPCHandler(modname, "GiveItem", function(player) local item = GLOBAL.SpawnPrefab("meat") player.components.inventory:GiveItem(item)end) AddClassPostConstruct("widgets/statusdisplays", function(self) --blah blah blah button stuff buttonx:SetOnClick(function() SendModRPCToServer(MOD_RPC[modname]["GiveItem"]) end)end) Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/#findComment-651114 Share on other sites More sharing options...
mouse Posted July 1, 2015 Author Share Posted July 1, 2015 A netvar is a variable that exists both in the server and the client.If the server sets the variable, then the changes propagate.I know. I was just using "netvar" as a generic variable name. Like:local stringvar="hello" A client can change a netvar like that, for example, the one that tells you that you are taking fire damage in health replica.The arrow down for the health badge will pop up. However your health won't go down.This change won't propagate to the server. And if the server changes the netvar, the netvar in the client will change. This is what Kzisor means:AddModRPCHandler(modname, "GiveItem", function(player) local item = GLOBAL.SpawnPrefab("meat") player.components.inventory:GiveItem(item)end) AddClassPostConstruct("widgets/statusdisplays", function(self) --blah blah blah button stuff buttonx:SetOnClick(function() SendModRPCToServer(MOD_RPC[modname]["GiveItem"]) end)end)That RPC handler stuff is pretty important. I wish I had known about it sooner. BTW, what does RPC stand for?Anyhow, that did the trick and now I can finally move on to other parts of the mod. Thank you very much. Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/#findComment-651142 Share on other sites More sharing options...
DarkXero Posted July 1, 2015 Share Posted July 1, 2015 what does RPC stand for? https://en.wikipedia.org/wiki/Remote_procedure_call Link to comment https://forums.kleientertainment.com/forums/topic/55790-how-to-push-an-event-from-the-client-to-the-server/#findComment-651144 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