LucasBaker Posted May 13, 2013 Posted May 13, 2013 Bom esse script faz com que, quem não for da gangue não poderá entrar no veículo x ( exemplo ), só que não to conseguindo usar ;x alguem poderia me ajudar ? teams = { 'LEI', 'team2' } cars = { 598, 596, 597, 599, 497, 490, 528, 599, 523, 425 } function checkTeam( player ) for k,v in ipairs( teams ) do if getTeamName( getPlayerTeam( player ) ) == v then return true end end return false end addEventHandler( 'onVehicleStartEnter', root, function( player ) for k,v in ipairs( cars ) do if getElementModel( source ) == v then local check = checkTeam( player ) if not check then cancelEvent( ) outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Organização LEI !', player, 255, 255, 255, true ) end end end end ) teams = { 'Crips', 'team2' } cars = { 520 } function checkTeamCrips( player ) for k,v in ipairs( teams ) do if getTeamName( getPlayerTeam( player ) ) == v then return true end end return false end addEventHandler( 'onVehicleStartEnter', root, function( player ) for k,v in ipairs( cars ) do if getElementModel( source ) == v then local check = checkTeamCrips( player ) if not check then cancelEvent( ) outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Gangue Crips !', player, 255, 255, 255, true ) end end end end ) teams = { 'Bloods', 'team2' } cars = { 450 } function checkTeamBloods( player ) for k,v in ipairs( teams ) do if getTeamName( getPlayerTeam( player ) ) == v then return true end end return false end addEventHandler( 'onVehicleStartEnter', root, function( player ) for k,v in ipairs( cars ) do if getElementModel( source ) == v then local check = checkTeamCrips( player ) if not check then cancelEvent( ) outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Gangue Bloods !', player, 255, 255, 255, true ) end end end end )
manawydan Posted May 14, 2013 Posted May 14, 2013 tente o seguinte! local cars = { [598]=true, [596]=true, [597]=true, [599]=true, [497]=true, [490]=true, [528]=true, [599]=true, [523]=true, [425]=true } addEventHandler( 'onVehicleStartEnter', root, function( player ) if cars[getElementModel(source)] then local timE = getPlayerTeam(player) if getTeamName(timE) == "LEI" or getTeamName(timE) == "team2" then end else cancelEvent( ) outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Organização LEI !', player, 255, 255, 255, true ) end) pode ser que não funcione, não testei (se funcionar com isso voce pode fazer o que quer)
LucasBaker Posted May 14, 2013 Author Posted May 14, 2013 Não cara acho que você não entendeu por exemplo eu boto uma parte do script assim teams = { 'gangA', 'gangB' } cars = { 598, 596, 597, 599, 497, 490, 528, 599, 523, 425 } function checkTeam( player ) for k,v in ipairs( teams ) do if getTeamName( getPlayerTeam( player ) ) == v then return true end end return false end addEventHandler( 'onVehicleStartEnter', root, function( player ) for k,v in ipairs( cars ) do if getElementModel( source ) == v then local check = checkTeam( player ) if not check then cancelEvent( ) outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Gangue Arsenal !', player, 255, 255, 255, true ) end end end end ) dai ele funciona deboas só que quando eu boto 2 x o mesmo script no mesmo arquivo.lua não pega..
manawydan Posted May 14, 2013 Posted May 14, 2013 bom, acredito que seja porque voce usa a variavel teams e cars 3 vezes, só que com valores diferentes, (elas iram se sobrescrever)
RaceXtreme Posted May 15, 2013 Posted May 15, 2013 Você vai ter dar atenção a esse script porque o que você está tentando fazer envolve multiplas variáveis. Quando isso acontece, nós temos que usar as tabelas e ao mesmo tempo, manipulá-las da melhor forma possível para economizar o gasto com o processador. Então, a seguir vem o código que você deve usar: teamVehicleList = { 'team2' = { }, 'LEI' = { 598, 596, 597, 599, 497, 490, 528, 599, 523, 425 }, 'Crips' = { 520 }, 'Bloods' = { 450 } } addEventHandler( 'onVehicleStartEnter', root, function( player ) local vModel = getElementModel (source) local pTeam = getTeamName (getPlayerTeam (player)) for kTeam, list in pairs( teamVehicleList ) do if pTeam ~= kTeam then for _,id in pairs ( list ) do if vModel == id then cancelEvent () outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Organização ' .. team .. ' !', player, 255, 255, 255, true ) return end end elseif pTeam == kTeam[1] then return end end end A ideia que eu tive foi fazer uma tabela com os times vinculados a uma "lista" com os carros que devem ser verificados. Quando o jogador entra em um carro, será verificado se ele pertence a algum time. Se no caso ele não pertencer ao time verificado, e o carro que ele entrou estiver vinculado a esse time, o evento será cancelado.
LucasBaker Posted May 16, 2013 Author Posted May 16, 2013 Você vai ter dar atenção a esse script porque o que você está tentando fazer envolve multiplas variáveis. Quando isso acontece, nós temos que usar as tabelas e ao mesmo tempo, manipulá-las da melhor forma possível para economizar o gasto com o processador. Então, a seguir vem o código que você deve usar: teamVehicleList = { 'team2' = { }, 'LEI' = { 598, 596, 597, 599, 497, 490, 528, 599, 523, 425 }, 'Crips' = { 520 }, 'Bloods' = { 450 } } addEventHandler( 'onVehicleStartEnter', root, function( player ) local vModel = getElementModel (source) local pTeam = getTeamName (getPlayerTeam (player)) for kTeam, list in pairs( teamVehicleList ) do if pTeam ~= kTeam then for _,id in pairs ( list ) do if vModel == id then cancelEvent () outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Organização ' .. team .. ' !', player, 255, 255, 255, true ) return end end elseif pTeam == kTeam[1] then return end end end A ideia que eu tive foi fazer uma tabela com os times vinculados a uma "lista" com os carros que devem ser verificados. Quando o jogador entra em um carro, será verificado se ele pertence a algum time. Se no caso ele não pertencer ao time verificado, e o carro que ele entrou estiver vinculado a esse time, o evento será cancelado. obrigado..
nelsonjrr23 Posted January 12, 2014 Posted January 12, 2014 Dame um erro RaceXtreme [2014-01-12 16:44:32] ERROR: Loading script failed: Veiculo-gang\script.lua:2: '}' expected (to close '{' at line 1) near '='
DNL291 Posted January 12, 2014 Posted January 12, 2014 O código tinha alguns erros, tente: teamVehicleList = { ['team2'] = { }, ['LEI'] = { 598, 596, 597, 599, 497, 490, 528, 599, 523, 425 }, ['Crips'] = { 520 }, ['Bloods'] = { 450 } } addEventHandler( 'onVehicleStartEnter', root, function( player ) local vModel = getElementModel (source) local pTeam = getTeamName (getPlayerTeam (player)) for kTeam, list in pairs( teamVehicleList ) do if pTeam ~= kTeam then for _,id in pairs ( list ) do if vModel == id then cancelEvent () outputChatBox( '#F08080[ERRO] #FF0000Este veículo pertence a Organização ' .. kTeam .. ' !', player, 255, 255, 255, true ) break end end end end end )
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