Booo Posted April 26, 2012 Share Posted April 26, 2012 hi I have a question , about the Table TeAMS = { teamBlue = { [ {weapons=[31,50],[29,50]} ] ,[ { skin=[46]}] }, temRed ={ [ {weapons=[28,50],[26,50]} ] ,[ { skin=[45]}] } } is this true in table ? or TeAMS = { teamBlue = { {weapons=[31,50],[29,50]} , skin=[46] }, temRed = { {weapons=[28,50],[26,50]} , skin=[45] } } And how Get key teamBlue and values !! Link to comment
Booo Posted April 26, 2012 Author Share Posted April 26, 2012 Again learn lua? lol You Here, Taught me this learn .. Link to comment
Kenix Posted April 26, 2012 Share Posted April 26, 2012 index = value !! Your code totally wrong .. local tTeams = { tTeamBlue = { [46] = { [31] = 50; [29] = 50; }; }; tTeamRed = { [45] = { [28] = 50; [26] = 50; }; }; } http://lua-users.org/wiki/TablesTutorial t = { } t[1] = 1 print( t[1] ) -- 1 table.insert( t, 2 ) print( t[2] ) -- 2 t = { 1 } print( t[1] ) -- 1 --If you not define index it defined default -- Example t = { 1; 2; 3; } print( t[3] ) -- 3 -- Next example t = { '1'; '2'; '3'; } print( t[3], type( t[3] ) ) -- 3 string t = { } t['index'] = 'value' print( t.index, '...', t['index'] ) --[[ value ... value ]] Link to comment
Booo Posted April 26, 2012 Author Share Posted April 26, 2012 index = value !!Your code totally wrong .. local tTeams = { tTeamBlue = { [46] = { [31] = 50; [29] = 50; }; }; tTeamRed = { [45] = { [28] = 50; [26] = 50; }; }; } http://lua-users.org/wiki/TablesTutorial t = { } t[1] = 1 print( t[1] ) -- 1 table.insert( t, 2 ) print( t[2] ) -- 2 t = { 1 } print( t[1] ) -- 1 --If you not define index it defined default -- Example t = { 1; 2; 3; } print( t[3] ) -- 3 -- Next example t = { '1'; '2'; '3'; } print( t[3], type( t[3] ) ) -- 3 string t = { } t['index'] = 'value' print( t.index, '...', t['index'] ) --[[ value ... value ]] TeAMS= { tTeamBlue = { [46] = { [31] = 50, [29] = 50 } }; tTeamRed = { [45] = { [28] = 50, [26] = 50 } }; } and how Get key and value team blue ?? for k,v in ipairs (TeAMS) do local TeamBlue = createTeam ( tostring(??) ) -- i need here tTeamBlue if TeamBlue then giveWeapon ( source, ??, ?? ) setElementModel ( source, ?? ) end Link to comment
Guest Guest4401 Posted April 26, 2012 Share Posted April 26, 2012 Table: teams = { teamBlue = { weapons = { { 31, 50 } , { 29 , 50 } }, skin = 46 }, teamRed = { weapons = { { 28,50 } , { 26, 50 } }, skin = 45 } } Code: outputChatBox("Weapon ID #1 of blue team : "..teams.teamBlue.weapons[1][1]) outputChatBox("Ammo #1 of blue team: "..teams.teamBlue.weapons[1][2]) outputChatBox("Weapon ID #2 of blue team : "..teams.teamBlue.weapons[2][1]) outputChatBox("Ammo #2 of blue team: "..teams.teamBlue.weapons[2][2]) outputChatBox("Skin of blue team : "..teams.teamBlue.skin) outputChatBox("Weapon ID #1 of red team : "..teams.teamRed.weapons[1][1]) outputChatBox("Ammo #1 of red team: "..teams.teamRed.weapons[1][2]) outputChatBox("Weapon ID #2 of red team : "..teams.teamRed.weapons[2][1]) outputChatBox("Ammo #2 of red team: "..teams.teamRed.weapons[2][2]) outputChatBox("Skin of red team : "..teams.teamRed.skin) Output: Weapon ID #1 of blue team : 31 Ammo #1 of blue team: 50 Weapon ID #2 of blue team : 29 Ammo #2 of blue team: 50 Skin of blue team : 46 Weapon ID #1 of red team : 28 Ammo #1 of red team: 50 Weapon ID #2 of red team : 26 Ammo #2 of red team: 50 Skin of red team : 45 Link to comment
Booo Posted April 26, 2012 Author Share Posted April 26, 2012 Table: teams = { teamBlue = { weapons = { { 31, 50 } , { 29 , 50 } }, skin = 46 }, teamRed = { weapons = { { 28,50 } , { 26, 50 } }, skin = 45 } } Code: outputChatBox("Weapon ID #1 of blue team : "..teams.teamBlue.weapons[1][1]) outputChatBox("Ammo #1 of blue team: "..teams.teamBlue.weapons[1][2]) outputChatBox("Weapon ID #2 of blue team : "..teams.teamBlue.weapons[2][1]) outputChatBox("Ammo #2 of blue team: "..teams.teamBlue.weapons[2][2]) outputChatBox("Skin of blue team : "..teams.teamBlue.skin) outputChatBox("Weapon ID #1 of red team : "..teams.teamRed.weapons[1][1]) outputChatBox("Ammo #1 of red team: "..teams.teamRed.weapons[1][2]) outputChatBox("Weapon ID #2 of red team : "..teams.teamRed.weapons[2][1]) outputChatBox("Ammo #2 of red team: "..teams.teamRed.weapons[2][2]) outputChatBox("Skin of red team : "..teams.teamRed.skin) Output: Weapon ID #1 of blue team : 31 Ammo #1 of blue team: 50 Weapon ID #2 of blue team : 29 Ammo #2 of blue team: 50 Skin of blue team : 46 Weapon ID #1 of red team : 28 Ammo #1 of red team: 50 Weapon ID #2 of red team : 26 Ammo #2 of red team: 50 Skin of red team : 45 i like it, thx karthik184, you are the best .. but how can use the table in for ipairs !! teams = { teamBlue = { weapons = { { 31, 50 } , { 29 , 50 } }, skin = 46 }, teamRed = { weapons = { { 28,50 } , { 26, 50 } }, skin = 45 } } for k,v in ipairs (teams) do local TeamBlue = createTeam ( tostring(??) ) -- i need here tTeamBlue if TeamBlue then giveWeapon ( source, ??, ?? ) setElementModel ( source, ?? ) end end Link to comment
Kenix Posted April 26, 2012 Share Posted April 26, 2012 local tTeams = { tTeamBlue = { [46] = { [31] = 50; [29] = 50; }; }; tTeamRed = { [45] = { [28] = 50; [26] = 50; }; }; } for sIndex, t in pairs( tTeams ) do createTeam( sIndex ) end function fTableGetIndexs( t ) local tTest = { } for m, _ in pairs( t ) do table.insert( tTest, m ) end return tTest end addEventHandler( 'onResourceStart', resourceRoot, function( ) for _, uPlayer in pairs( getElementsByType 'player' ) do setTimer( setPlayerTeam, 100, 1, uPlayer, getTeamFromName( fTableGetIndexs( tTeams )[ math.random( #fTableGetIndexs( tTeams ) ) ] ) ) -- set random team for example setTimer( function( uPlayer, tTeams ) local sTeam = getTeamName( getPlayerTeam( uPlayer ) ) setElementModel( uPlayer, fTableGetIndexs( tTeams[ sTeam ] )[1] ) for nIndex, nValue in pairs( tTeams[ sTeam ][ fTableGetIndexs( tTeams[ sTeam ] )[1] ] ) do setTimer( giveWeapon, 100, 1, uPlayer, nIndex, nValue ) end end, 200, 1, uPlayer, tTeams ) end end ) Updated Link to comment
Booo Posted April 27, 2012 Author Share Posted April 27, 2012 local tTeams = { tTeamBlue = { [46] = { [31] = 50; [29] = 50; }; }; tTeamRed = { [45] = { [28] = 50; [26] = 50; }; }; } for sIndex, t in pairs( tTeams ) do createTeam( sIndex ) end function fTableGetIndexs( t ) local tTest = { } for m, _ in pairs( t ) do table.insert( tTest, m ) end return tTest end addEventHandler( 'onResourceStart', resourceRoot, function( ) for _, uPlayer in pairs( getElementsByType 'player' ) do setTimer( setPlayerTeam, 100, 1, uPlayer, getTeamFromName( fTableGetIndexs( tTeams )[ math.random( #fTableGetIndexs( tTeams ) ) ] ) ) -- set random team for example setTimer( function( uPlayer, tTeams ) local sTeam = getTeamName( getPlayerTeam( uPlayer ) ) setElementModel( uPlayer, fTableGetIndexs( tTeams[ sTeam ] )[1] ) for nIndex, nValue in pairs( tTeams[ sTeam ][ fTableGetIndexs( tTeams[ sTeam ] )[1] ] ) do setTimer( giveWeapon, 100, 1, uPlayer, nIndex, nValue ) end end, 200, 1, uPlayer, tTeams ) end end ) Updated Nice idea man.. You pro in pairs Thanks! Link to comment
Booo Posted April 27, 2012 Author Share Posted April 27, 2012 hi Im again I fix it the script Is this true now .؟ local teams = { [createTeam("teamBlue",0,255,0)] = { weapons={ [31] = 150,[26]=50},skin=46}, [createTeam("teamRed",0,0,255)] = { weapons={ [31] = 150,[26]=50},skin=0} } playerst = { } addEventHandler("onResourceStart",resourceRoot, function () for _, uPlayer in pairs( getElementsByType 'player' ) do for team, _t in pairs(teams) do if isTimer(playerst[source]) then return end playerst[uPlayer] = setTimer( setPlayerTeam, 100, 1, uPlayer, getTeamFromName( team[ math.random( #teams ) ] ) ) local teamP = teams[source] setElementModel ( uPlayer, teamP.skin ) for weapon, ammo in pairs (teamP.weapons) do giveWeapon(uPlayer,weapon,ammo,true) end end end end ) Link to comment
Booo Posted April 27, 2012 Author Share Posted April 27, 2012 Your code is totally wrong. ops !! why ?? Link to comment
Kenix Posted April 27, 2012 Share Posted April 27, 2012 I can't explain this, because it's unexplained. I don't understand what you're doing. I try playerst[uPlayer] = setTimer( setPlayerTeam, 100, 1, uPlayer, getTeamFromName( team[ math.random( #teams ) ] ) ) Cut getTeamFromName( team[ math.random( #teams ) ] ) team is userdata NOT TABLE!! Also getTeamFromName Have only one argument and only STRING. local teamP = teams[source] source = resource, so index is nil setElementModel ( uPlayer, teamP.skin ) Same, teamP is nil for weapon, ammo in pairs (teamP.weapons) do Same ^^ Please learn lua! viewtopic.php?f=148&t=40809 Link to comment
Booo Posted April 27, 2012 Author Share Posted April 27, 2012 I can't explain this, because it's unexplained. I don't understand what you're doing.I try playerst[uPlayer] = setTimer( setPlayerTeam, 100, 1, uPlayer, getTeamFromName( team[ math.random( #teams ) ] ) ) Cut getTeamFromName( team[ math.random( #teams ) ] ) team is userdata NOT TABLE!! Also getTeamFromName Have only one argument and only STRING. local teamP = teams[source] source = resource, so index is nil setElementModel ( uPlayer, teamP.skin ) Same, teamP is nil for weapon, ammo in pairs (teamP.weapons) do Same ^^ Please learn lua! viewtopic.php?f=148&t=40809 lol , i stupid ok i fix it is this true local teams = { [createTeam("teamBlue",0,255,0)] = { weapons={ [31] = 150,[26]=50},skin=46}, [createTeam("teamRed",0,0,255)] = { weapons={ [31] = 150,[26]=50},skin=0} } playerst = { } addEventHandler("onResourceStart",resourceRoot, function () for _, uPlayer in pairs( getElementsByType 'player' ) do for team, _t in pairs(teams) do if isTimer(playerst[uPlayer]) then return end if getTeamName(team) == teamBlue and countPlayersInTeam ( team ) < countPlayersInTeam ( getTeamFromName(teamRed) ) then playerst[uPlayer] = setTimer( setPlayerTeam, 100, 1, uPlayer, team ) setElementModel ( uPlayer, _t.skin ) for weapon, ammo in pairs (_t.weapons) do giveWeapon(uPlayer,weapon,ammo,true) end end end end end ) 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