Jump to content

sorteio kit armas no bau


Recommended Posts

addCommandHandler("bau",
function(thePlayer)
	local x,y,z = getElementPosition(thePlayer)
	local xr,yr,zr = getElementRotation(thePlayer)
	px,py,pz = getElementPosition(thePlayer)
	prot = getPedRotation(thePlayer)
	local offsetRot = math.rad(prot+90)
	local vx = px+1.5*math.cos(offsetRot)
	local vy = py+1.5*math.sin(offsetRot)
	local vz = pz+2
	local vrot = prot+180
	tent = createObject(964,vx,vy,z-1,0,0,vrot)
	setObjectScale(tent,1.0)
	tentCol = createColSphere(x,y,z,4)
	attachElements(tentCol,tent,0,0,0)
	setElementData(tentCol,"parent",tent)
	setElementData(tent,"parent",tentCol)
	setElementData(tentCol,"tent",true)
	setElementData(tentCol,"vehicle",true)
	item = tendaItens[math.random(#tendaItens)]
	aa,bb = item[1],item[2]
		setElementData(tentCol,aa,bb)
	
end)


tendaItens = {
	["kitSniper"] = {
		{"M107",10},
	},
	["kitRifler"] = {
		{"M4A1 CCO",20},
	},
}

como vocês pode ver acima /\ eu to tentando fazer varias classe de itens  em um bau ,mas nessas classe os item vai ser diferente so que não conseguindo concluir isso

Link to comment
  • Moderators

Isso mesmo, nesse caso a tabela deve ter a sua estrutura utilizando números nos índices pra funcionar.

Você pode adicionar mais itens em cada categoria assim:

tendaItens = {
	{
		{"M107",10},
		{"arma",123},
		{"arma",123}
	},

	{
		{"M4A1 CCO",20},
		{"arma",123},
		{"arma",123}
	}
}

Não é obrigatório fazer desse jeito, mas vai ficar mais fácil.
Se quiser usar uma string para o índice, como no código do 1º post, você pode fazer assim para obter uma categoria aleatória da tabela:

	local cats = { "first", "sec" } -- tabela com as categorias
	local categoria_aleatoria = tendaItens[ cats[ math.random(#cats) ] ]
	
	--[[
		math.random(#cats) : Retorna um índice aleatório da tabela (nesse caso deve ser 1 ou 2)
		cats[ math.random(#cats) ] : É o mesmo que cats[1] ou cats[2], retorna uma das strings da tabela
	]]

 

 

On 08/09/2017 at 00:47, AnnaBelle said:

tendaItens = {
		{"M107",10},

		{"M4A1 CCO",20},
}

 

Lembrando que a tabela dessa forma, sem criar a chave ou índice manualmente, é o mesmo que isto:

tendaItens = {
		[1] = {"M107",10},

		[2] = {"M4A1 CCO",20},
}

 

 

Edited by DNL291
Link to comment

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...