Memory Posted January 13, 2013 Share Posted January 13, 2013 Hello, please, tell me where error. client localPlayer = getLocalPlayer() function drawGUI() guiWindow = guiCreateWindow(200,200,300,300,"ComboBox test area",false,false) comboBox = guiCreateComboBox(20, 30, 288, 200, "selected", false, guiWindow) local Default = guiComboBoxAddItem(comboBox,"Default") local English = guiComboBoxAddItem(comboBox,"English") addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClickValue) guiSetVisible(guiWindow,false) end function somethingFromClickValue(button,state) if source == Default then triggerServerEvent("lang1",localPlayer) end if source == English then triggerServerEvent("lang2",localPlayer) end end function opengui() if not guiWindow then drawGUI() guiSetVisible(guiWindow,true) else guiSetVisible(guiWindow, not guiGetVisible(guiWindow)) end showCursor(not isCursorShowing()) end bindKey("F1", "down", opengui) addCommandHandler("combobox", opengui) Server addEvent ('lang1', true) addEventHandler ('lang1', root, function () local theTeam = createTeam ( "Default", 255, 255, 255 ) setPlayerTeam ( source, theTeam ) end ) addEvent ('lang2', true) addEventHandler ('lang2', root, function (source) local Team = createTeam ( "English", 255, 255, 255 ) setPlayerTeam ( source, theTeam ) end ) Tried this but doesn't work addEventHandler ('lang1', root, function (player) local theTeam = createTeam ( "Default", 255, 255, 255 ) setPlayerTeam ( player, theTeam ) end ) Link to comment
MR.S3D Posted January 13, 2013 Share Posted January 13, 2013 client localPlayer = getLocalPlayer() function drawGUI() guiWindow = guiCreateWindow(200,200,300,300,"ComboBox test area",false,false) comboBox = guiCreateComboBox(20, 30, 288, 200, "selected", false, guiWindow) local Default = guiComboBoxAddItem(comboBox,"Default") local English = guiComboBoxAddItem(comboBox,"English") button1 = guiCreateButton(80, 80, 100, 50, "selected", false, guiWindow) ---button addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClickValue) guiSetVisible(guiWindow,false) end function somethingFromClickValue() if ( source == button1 ) then ---When Click button1 local item = guiComboBoxGetSelected(comboBox) -- get Selected local text = guiComboBoxGetItemText(comboBox,item) --- get text if text == "Default" then triggerServerEvent("lang1",localPlayer) elseif text == "English" then triggerServerEvent("lang2",localPlayer) end end end function opengui() if not guiWindow then drawGUI() guiSetVisible(guiWindow,true) else guiSetVisible(guiWindow, not guiGetVisible(guiWindow)) end showCursor(not isCursorShowing()) end bindKey("F1", "down", opengui) addCommandHandler("combobox", opengui) Server theTeam = createTeam ( "Default", 255, 255, 255 ) -- Team = createTeam ( "English", 255, 255, 255 ) addEvent ('lang1', true) addEventHandler ('lang1', root, function () setPlayerTeam ( source, theTeam ) end ) addEvent ('lang2', true) addEventHandler ('lang2', root, function () setPlayerTeam ( source, theTeam ) end ) Link to comment
Memory Posted January 13, 2013 Author Share Posted January 13, 2013 Sorry, but your code is wrong. You just add a button Link to comment
AhmadQTR Posted January 13, 2013 Share Posted January 13, 2013 addEvent ('lang1', true) addEventHandler ('lang1', root, function (player) theTeam = createTeam ( "Default", 255, 255, 255 ) setPlayerTeam ( source, theTeam ) end ) addEvent ('lang2', true) addEventHandler ('lang2', root, function (player) Team = createTeam ( "English", 255, 255, 255 ) setPlayerTeam ( player, Team ) end ) Link to comment
Memory Posted January 13, 2013 Author Share Posted January 13, 2013 You are laugh? I written already that I tried it. Link to comment
MR.S3D Posted January 13, 2013 Share Posted January 13, 2013 Sorry, but your code is wrong. You just add a button its works i tested it Client localPlayer = getLocalPlayer() function drawGUI() guiWindow = guiCreateWindow(200,200,300,300,"ComboBox test area",false,false) comboBox = guiCreateComboBox(20, 30, 288, 200, "selected", false, guiWindow) local Default = guiComboBoxAddItem(comboBox,"Default") local English = guiComboBoxAddItem(comboBox,"English") button1 = guiCreateButton(80, 80, 100, 50, "selected", false, guiWindow) addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClickValue) guiSetVisible(guiWindow,false) end function somethingFromClickValue() if ( source == button1 ) then local item = guiComboBoxGetSelected(comboBox) local text = guiComboBoxGetItemText(comboBox,item) if text == "Default" or text == "English" then triggerServerEvent("lang",localPlayer,text) end end end function opengui() if not guiWindow then drawGUI() guiSetVisible(guiWindow,true) else guiSetVisible(guiWindow, not guiGetVisible(guiWindow)) end showCursor(not isCursorShowing()) end bindKey("F1", "down", opengui) addCommandHandler("combobox", opengui) Server theTeam = createTeam ( "Default", 255, 255, 255 ) Team = createTeam ( "English", 255, 255, 255 ) addEvent ('lang', true) addEventHandler ('lang', root, function (team) if team == "Default" then setPlayerTeam ( source, theTeam ) else setPlayerTeam ( source, Team) end end ) Link to comment
Memory Posted January 14, 2013 Author Share Posted January 14, 2013 Thanks, now works Link to comment
Memory Posted January 14, 2013 Author Share Posted January 14, 2013 I have still one question. Tell me, please, how destroy team if players in team are 0. I think that I must use destroyElement and countPlayersInTeam, but doens't work Link to comment
MR.S3D Posted January 14, 2013 Share Posted January 14, 2013 I have still one question. Tell me, please, how destroy team if players in team are 0.I think that I must use destroyElement and countPlayersInTeam, but doens't work This Example theTeam = createTeam ( "Default", 255, 255, 255 ) --- element theTeam local function count(team) return countPlayersInTeam ( getTeamFromName ( team ) ) --- to get all players in team end addCommandHandler("destroyTeam", function() Players = count( "Default" ) ---return function count(teamName) if ( Players == 0 ) then destroyElement(theTeam) -- destroy elemnt theTeam theTeam = nil end end) Link to comment
Memory Posted January 14, 2013 Author Share Posted January 14, 2013 If I add still a lot of languages, code will be correct? Functions will very big and I doubt in logic of the code. Client localPlayer = getLocalPlayer() function drawGUI() guiWindow = guiCreateWindow(200,200,300,300,"ComboBox test area",false,false) comboBox = guiCreateComboBox(20, 30, 288, 200, "selected", false, guiWindow) local Default = guiComboBoxAddItem(comboBox,"Default") local English = guiComboBoxAddItem(comboBox,"English") local Russian = guiComboBoxAddItem(comboBox,"Russian") button1 = guiCreateButton(80, 80, 100, 50, "Select", false, guiWindow) addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClickValue) guiSetVisible(guiWindow,false) end function somethingFromClickValue() if ( source == button1 ) then local item = guiComboBoxGetSelected(comboBox) local text = guiComboBoxGetItemText(comboBox,item) if text == "Default" or text == "English" or text == "Russian" then triggerServerEvent("lang",localPlayer,text) end end end function opengui() if not guiWindow then drawGUI() guiSetVisible(guiWindow,true) else guiSetVisible(guiWindow, not guiGetVisible(guiWindow)) end showCursor(not isCursorShowing()) end bindKey("F1", "down", opengui) addCommandHandler("combobox", opengui) Server addEvent ('lang', true) addEventHandler ('lang', root, function (team) if team == "Default" then theTeam = createTeam ( "Default", 255, 255, 255 ) if theTeam then setPlayerTeam ( source, theTeam ) end elseif team == "English" then Team = createTeam ( "English", 255, 255, 255 ) if Team then setPlayerTeam ( source, Team) end elseif team == "Russian" then TeamRussian = createTeam ( "Russian", 255, 255, 255 ) if TeamRussian then setPlayerTeam ( source, TeamRussian) end end end ) local function count(team) return countPlayersInTeam ( getTeamFromName ( team ) ) end addEvent ('lang', true) addEventHandler ('lang', root, function() Players = count( "Default" ) PlayersEng = count( "English" ) PlayersRus = count( "Russian" ) if ( Players == 0 ) then destroyElement(theTeam) theTeam = nil end if ( PlayersEng == 0 ) then destroyElement(Team) Team = nil end if ( PlayersRus == 0 ) then destroyElement(TeamRussian) TeamRussian = nil end end) Link to comment
MR.S3D Posted January 14, 2013 Share Posted January 14, 2013 If I add still a lot of languages, code will be correct? Functions will very big and I doubt in logic of the code.Client localPlayer = getLocalPlayer() function drawGUI() guiWindow = guiCreateWindow(200,200,300,300,"ComboBox test area",false,false) comboBox = guiCreateComboBox(20, 30, 288, 200, "selected", false, guiWindow) local Default = guiComboBoxAddItem(comboBox,"Default") local English = guiComboBoxAddItem(comboBox,"English") local Russian = guiComboBoxAddItem(comboBox,"Russian") button1 = guiCreateButton(80, 80, 100, 50, "Select", false, guiWindow) addEventHandler ("onClientGUIClick",getResourceRootElement(getThisResource()),somethingFromClickValue) guiSetVisible(guiWindow,false) end function somethingFromClickValue() if ( source == button1 ) then local item = guiComboBoxGetSelected(comboBox) local text = guiComboBoxGetItemText(comboBox,item) if text == "Default" or text == "English" or text == "Russian" then triggerServerEvent("lang",localPlayer,text) end end end function opengui() if not guiWindow then drawGUI() guiSetVisible(guiWindow,true) else guiSetVisible(guiWindow, not guiGetVisible(guiWindow)) end showCursor(not isCursorShowing()) end bindKey("F1", "down", opengui) addCommandHandler("combobox", opengui) Server addEvent ('lang', true) addEventHandler ('lang', root, function (team) if team == "Default" then theTeam = createTeam ( "Default", 255, 255, 255 ) if theTeam then setPlayerTeam ( source, theTeam ) end elseif team == "English" then Team = createTeam ( "English", 255, 255, 255 ) if Team then setPlayerTeam ( source, Team) end elseif team == "Russian" then TeamRussian = createTeam ( "Russian", 255, 255, 255 ) if TeamRussian then setPlayerTeam ( source, TeamRussian) end end end ) local function count(team) return countPlayersInTeam ( getTeamFromName ( team ) ) end addEvent ('lang', true) addEventHandler ('lang', root, function() Players = count( "Default" ) PlayersEng = count( "English" ) PlayersRus = count( "Russian" ) if ( Players == 0 ) then destroyElement(theTeam) theTeam = nil end if ( PlayersEng == 0 ) then destroyElement(Team) Team = nil end if ( PlayersRus == 0 ) then destroyElement(TeamRussian) TeamRussian = nil end end) you add 2 Event in server side why? and then why you need destroy team? Link to comment
Memory Posted January 14, 2013 Author Share Posted January 14, 2013 Because, You imagine what will be if I add around 40 - 50 languages and create team for every. Link to comment
MR.S3D Posted January 14, 2013 Share Posted January 14, 2013 Because, You imagine what will be if I add around 40 - 50 languages and create team for every. Server this create team one time then just set player in team theTeam = createTeam ( "Default", 255, 255, 255 ) Team = createTeam ( "English", 255, 255, 255 ) TeamRussian = createTeam ( "Russian", 255, 255, 255 ) addEvent ('lang', true) addEventHandler ('lang', root, function (team) if team == "Default" then if theTeam then setPlayerTeam ( source, theTeam ) end elseif team == "English" then if Team then setPlayerTeam ( source, Team) end elseif team == "Russian" then if TeamRussian then setPlayerTeam ( source, TeamRussian) end end end ) Link to comment
Memory Posted January 14, 2013 Author Share Posted January 14, 2013 I know that team is created one time, I say that if I add around 50 languages, I will have 50 teams in scoreboard. And when in team 0 players, team will screen in scoreboard with 0 players, and I want make when 0 players in team, she will destroyed. i.e. function() Players = count( "Default" ) PlayersEng = count( "English" ) PlayersRus = count( "Russian" ) if ( Players == 0 ) then destroyElement(theTeam) theTeam = nil end if ( PlayersEng == 0 ) then destroyElement(Team) Team = nil end if ( PlayersRus == 0 ) then destroyElement(TeamRussian) TeamRussian = nil end end) Link to comment
AhmadQTR Posted January 14, 2013 Share Posted January 14, 2013 if getPlayersInTeam (theteam) == 0 then destroyElement (theteam) Not sure. Link to comment
abu5lf Posted January 14, 2013 Share Posted January 14, 2013 if getPlayersInTeam (theteam) == 0 then destroyElement (theteam) Not sure. Use countPlayersInTeam. Link to comment
MR.S3D Posted January 14, 2013 Share Posted January 14, 2013 I know that team is created one time, I say that if I add around 50 languages, I will have 50 teams in scoreboard. And when in team 0 players, team will screen in scoreboard with 0 players, and I want make when 0 players in team, she will destroyed. i.e. function() Players = count( "Default" ) PlayersEng = count( "English" ) PlayersRus = count( "Russian" ) if ( Players == 0 ) then destroyElement(theTeam) theTeam = nil end if ( PlayersEng == 0 ) then destroyElement(Team) Team = nil end if ( PlayersRus == 0 ) then destroyElement(TeamRussian) TeamRussian = nil end end) What do you mean 50 team؟ Link to comment
myonlake Posted January 14, 2013 Share Posted January 14, 2013 What do you mean 50 team؟ Are you kidding me? He has fifty (50) teams in his scoreboard window. Link to comment
MR.S3D Posted January 14, 2013 Share Posted January 14, 2013 This is an example to remove all the teams in the current resource local function count(team) return countPlayersInTeam ( getTeamFromName ( team ) ) --- to get all players in team end addCommandHandler("Team", function() for _, AllTeams in ipairs ( getElementsByType ( "team",getResourceRootElement(getThisResource())) ) do Players = count(getTeamName(AllTeams)) if Players == 0 then -- If there is no one in the team destroyElement(AllTeams) --- destroy team end end end) Link to comment
Memory Posted January 15, 2013 Author Share Posted January 15, 2013 Thank you very much, it's works 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