kuwalda Posted May 24, 2014 Share Posted May 24, 2014 I have been creating automatic race system and for now all was fine, until I found a little bug that I am unable to find and fix. Script idea: --[sERVER] Script considers to make race or not function raceConsider( ) if getPlayerCount() >= 2 then if raceActive[1] == "false" then triggerClientEvent ( "showRaceInfo", getRootElement()) raceActive[1] = "true" end end end addEventHandler ( "onPlayerJoin", getRootElement(), raceConsider ) --[CLIENT] Sets timer to allow player login, so he can freely look at GUI function showRaceInformation ( ) setTimer ( function ()triggerServerEvent( "needRaceGUI", root)end, 15000, 1) end addEvent( "showRaceInfo", true ) addEventHandler( "showRaceInfo", getRootElement(), showRaceInformation ) --[sERVER] Gathers information for race function getRaceGUI( ) raceRikotajs = Rikotajs[ math.random( 1,#Rikotajs ) ] triggerClientEvent(root, "gotRaceGUI", root, raceRikotajs) end addEvent( "needRaceGUI", true ) addEventHandler( "needRaceGUI", root, getRaceGUI ) --[CLIENT] And displays GUI function showRaceGUI ( raceRikotajs ) ... end addEvent( "gotRaceGUI", true ) addEventHandler( "gotRaceGUI", getRootElement(), showRaceGUI ) Problem is: when I am connected to server and my friend joins it - all works perfectly and fine, but when I reset raceActive[1] = "true" to raceActive[1] = "false" and my friend joins this GUI is displaying 2 times. How to make it apper only 1 time? Where did I go wrong? Link to comment
kuwalda Posted May 24, 2014 Author Share Posted May 24, 2014 There is Client and Server sides, I have marked them with --[sERVER] or --[CLIENT] Link to comment
Castillo Posted May 24, 2014 Share Posted May 24, 2014 Well, you put it to show to everyone, since you're triggering the client side event "showRaceInfo" to getRootElement. Link to comment
kuwalda Posted May 24, 2014 Author Share Posted May 24, 2014 (edited) Well, you put it to show to everyone, since you're triggering the client side event "showRaceInfo" to getRootElement. I want it to show to everyone, but I dont want it to trigger 2 times and show 2 GUIs at once. As I said, GUI shows only once for each player when I trigger it first time, but when I trigger it second time, it shows 2 GUIs per player. Where is the GUI ? --[CLIENT] And displays GUI function showRaceGUI ( raceRikotajs ) ... end addEvent( "gotRaceGUI", true ) addEventHandler( "gotRaceGUI", getRootElement(), showRaceGUI ) With GUI everything should be fine, there is just styling options. As I understand problem is somewhere in first or second "step" Edited May 24, 2014 by Guest Link to comment
Castillo Posted May 24, 2014 Share Posted May 24, 2014 Well, you're obviously creating the GUI everytime, instead of setting it visible. Link to comment
kuwalda Posted May 24, 2014 Author Share Posted May 24, 2014 Well, you're obviously creating the GUI everytime, instead of setting it visible. Yes, because this GUI tells information about race event and it gets random values everytime, so information in this GUI is changing. raceRikotajs = Rikotajs[ math.random( 1,#Rikotajs ) ] Link to comment
Castillo Posted May 24, 2014 Share Posted May 24, 2014 But, there's no need to do that, you can use the function guiSetText. Link to comment
kuwalda Posted May 24, 2014 Author Share Posted May 24, 2014 But, there's no need to do that, you can use the function guiSetText. I know, but that is not my problem. The problem is like this: * I join the server * My friend join the server * event is triggered * GUI pops out for both of us * My friend leaves the server * I reset value to raceActive[1] = "false" * My friend join the server * event is triggered * GUI pops out for both of us and ANOTHER GUI pops out on top of last one So basiclly event is being triggered 2 times, but I have no idea what causes it. Link to comment
Castillo Posted May 24, 2014 Share Posted May 24, 2014 Is triggered 2 times because that's how your script works, when you reset the value to "false", you should also destroy the GUI if exists. Link to comment
kuwalda Posted May 24, 2014 Author Share Posted May 24, 2014 Is triggered 2 times because that's how your script works, when you reset the value to "false", you should also destroy the GUI if exists. No, there is button in GUI to close the last one. If I wouldnt close it on first time, there would be in total of 3 GUIs when event is triggered 2nd time Link to comment
Chronic Posted May 24, 2014 Share Posted May 24, 2014 guiGetVisible So you can check if the GUI is already open for the player. 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