Killerbee_x. Posted December 7, 2014 Share Posted December 7, 2014 Hey there, While scripting I stumbled upon the following problem: I want to trigger a clientsided function when a player joins the server. But for some reason the script does not recognise the addEvent() I added in client. I hope anybody has a way to solve this issue or knows a way around this. Thanks in advance server code: addEventHandler("onPlayerJoin", getRootElement(), function() setElementData(source, "loggedOn", false) redirectOpenPanel(source) end ) function redirectOpenPanel() triggerClientEvent("openPanel", source) end client code: function openUserpanel() -- Do stuff end addEvent("openPanel", true) addEventHandler("openPanel", getRootElement(), openUserpanel) debug gives the standard 'triggering client event. but event is not added clientside' Link to comment
Jaydan Posted December 7, 2014 Share Posted December 7, 2014 function redirectOpenPanel(source) triggerClientEvent(source, "openPanel", source) end Without putting source in the parameters how is it going to know what 'source' is? You also forgot to put source as the first parameter in the triggerClientEvent function, without doing that it would send it to every client. Also make sure your meta.xml file is correct, if you aren't sure post it below. Link to comment
Killerbee_x. Posted December 8, 2014 Author Share Posted December 8, 2014 Even when altering the lines like you mentioned it is not working properly. The fact that I also trigger the clientside script on client by calling the function indicates that the function is working as intended. Though, it used to work as intended via the triggerClientEvent, but somewhere along the scripting process it stopped working. Hope anyone else has had the similar problem and knows a solution. Link to comment
Moderators IIYAMA Posted December 8, 2014 Moderators Share Posted December 8, 2014 Problem: The client hasn't loaded the script before the server is sending him a trigger. Solution: "onClientResourceStart"(resourceRoot) > triggerServerEvent > triggerClientEvent > openpanel Link to comment
Killerbee_x. Posted December 8, 2014 Author Share Posted December 8, 2014 @IIYAMA this worked, thank you. Link to comment
Moderators IIYAMA Posted December 8, 2014 Moderators Share Posted December 8, 2014 np. Link to comment
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