bamby12 Posted February 21, 2011 Share Posted February 21, 2011 i want to show a gui when a player logs in but it dosnt work, heres the code: server: addEvent("showGUI") function onlogin(player) triggerClientEvent("showGUI", player) end addEventHandler("onPlayerLogin",getRootElement(),onlogin) client: addEvent("showGUI") function guishow(player) guiSetVisible(GUIEditor_Window[1],true) end addEventHandler("showGUI",getRootElement(),guishow) Link to comment
Aibo Posted February 21, 2011 Share Posted February 21, 2011 because first argument passed by "onPlayerLogin" event is player's previous account, not the player element player element is the source of the event. and you're not specifying for which player the event should be triggered. -- server function onlogin() triggerClientEvent(source, "showGUI", source) end addEventHandler("onPlayerLogin", getRootElement(), onlogin) and you dont need (player) in client handler. Link to comment
Kenix Posted February 21, 2011 Share Posted February 21, 2011 i want to show a gui when a player logs in but it dosnt work, heres the code:server: addEvent("showGUI") function onlogin(player) triggerClientEvent("showGUI", player) end addEventHandler("onPlayerLogin",getRootElement(),onlogin) client: addEvent("showGUI") function guishow(player) guiSetVisible(GUIEditor_Window[1],true) end addEventHandler("showGUI",getRootElement(),guishow) use in Client side function guishow() guiSetVisible(GUIEditor_Window[1],true) end addEventHandler("onClientResourceStart",getRootElement(),guishow) Link to comment
Castillo Posted February 21, 2011 Share Posted February 21, 2011 volk-rus, he said WHEN A PLAYER LOGINS, not when a player joins the server. Link to comment
Aibo Posted February 21, 2011 Share Posted February 21, 2011 use in Client side function guishow() guiSetVisible(GUIEditor_Window[1],true) end addEventHandler("onClientResourceStart",getRootElement(),guishow) 1. if you didn't notice, gui is set to show on player login, not on join. 2. your script will show the window every time ANY resource starts. Link to comment
proracer Posted February 21, 2011 Share Posted February 21, 2011 Yep, instead of getRootElement you should use resourceRoot Link to comment
bamby12 Posted February 21, 2011 Author Share Posted February 21, 2011 ok i changed what aiboforcen said and it still dont work when the player logged in Link to comment
proracer Posted February 21, 2011 Share Posted February 21, 2011 Any errors..? Did you try deleting 1st arg in line 3? Just leave empty bracket. Link to comment
SDK Posted February 21, 2011 Share Posted February 21, 2011 The clientside added event must be allowed to get triggered from serverside, set allowRemoteTrigger to true: --client addEvent("showGUI", true) You dont need to add the event serverside btw, you can remove it there. Link to comment
bamby12 Posted February 21, 2011 Author Share Posted February 21, 2011 Whey works thanks SDK Link to comment
Kenix Posted February 21, 2011 Share Posted February 21, 2011 agree: D just made a mistake it would be wise to do next / as do not need to use some functions not to do so, simply attach it to the Events button Link to comment
bamby12 Posted February 22, 2011 Author Share Posted February 22, 2011 1 more think i want a button to set a players team but when i click on the button it dosnt do anything and i dont get errors heres the code: server: function chooseteam(player) setPlayerTeam" class="kw6">setPlayerTeam ( player, getTeamFromName("team") )--i dno why it says class = "kw6" here end addEvent("setteam",true) addEventHandler("setteam", resourceRoot, chooseteam) client: addEventHandler("onClientGUIClick", GUIEditor_Button[1], clickbutton, false) function clickbutton(player) triggerServerEvent("setteam",getLocalPlayer()) guiSetVisible("GUIEditor_Window[1]", false) showCursor(false) end Link to comment
SDK Posted February 22, 2011 Share Posted February 22, 2011 In the client file, put the addEventHandler under the function. clickbutton must first be defined before you can assign it to an event In the server file, you're expecting a player variable, but that will just be nil. The source of your event will be the player, so use "source" instead of "player" in setPlayerTeam. Reason: the second argument in triggerServerEvent will be the source. (that class kw6 is a bug in the forum with setPlayerTeam) Link to comment
bamby12 Posted February 22, 2011 Author Share Posted February 22, 2011 ok i put the handler into the function that opens the gui on login and now the buttons work but still dont change the players team, any more help is appreciated. 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