Jump to content

ComboBox


Memory

Recommended Posts

Posted

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 
) 

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted

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 
) 
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted
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 
) 

ahmadsig1.png

Nobody is perfect , I'm nobody.

22771qw7.jpg

Skype : ahmad.nasser37

Posted
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 
) 
  
  
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted

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

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted
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) 
     
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted

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) 
  

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted
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?

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted

Because, You imagine what will be if I add around 40 - 50 languages and create team for every.

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted
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 
) 
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted

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) 

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted
if getPlayersInTeam (theteam) == 0 then 
destroyElement (theteam) 

Not sure.

Use countPlayersInTeam.

╔═╦╦╦╗╔╦═╦═╦═╦═╦╦╦╦╦╦╦═╦╦╦╦╗

║║║║║╠╝║║╚╣║║║║║║║║║║║║║║║║║

║║║║║╚╦╦═╦╦╦╦╣║║║║║║║║║║║║║║

║║║║╠═╣╠╝╔══╝║║║║║╟╢║║║║║╟╢║

╚╩══╩══╩═╩═══╩╩══╩╩═╩╩╩═╩╩═╝

«سبحانك اللهم وبحمدك أشهد أن لا إله إلا أنت أستغفرك وأتوب إليك»

M7mdAl7arthy : لتواصل سكايب

Posted
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؟

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

Posted
What do you mean 50 team؟

Are you kidding me? He has fifty (50) teams in his scoreboard window.

If I helped you, please click the like button on the right ;) Thanks!

Posted

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) 
  
  

Welcom to my server Q.5

Current game type in my server Drift

350x20_FFFFFF_FFFFFF_000000_000000.png

my Email : [email protected]

Programming level: 90%

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...