Jump to content

Simplificação de setElementData


Recommended Posts

Olá pessoas eu dnv aqui com dúvida kk, queria saber como posso simplificar o setElementData e o setAccountData, para evitar trafego de rede... 

	if tonumber(dxBone) then
		if dxBone == 1 then
			addPedClothes ( localPlayer, "captruck", "captruck", 16 )
			Texto("Boné", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 50", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[1] = 50
		elseif dxBone == 2 then
			addPedClothes ( localPlayer, "skullygrn", "skullycap", 16 )
			Texto("Touca", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 25", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[2] = 25
		elseif dxBone == 3 then
			addPedClothes ( localPlayer, "hatmancblk", "hatmanc", 16 )
			Texto("Chapéu", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 20", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[3] = 20
		elseif dxBone == 4 then
			addPedClothes ( localPlayer, "capgang", "cap", 16 )
			Texto("Boné Preto", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 45", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[4] = 45
		end
	end

function Comprar (_,state)
	if dxRoupa == false then
		if state == "down" then
			if isCursorOnElement (x*115, y*277, x*95, y*15) then
				if tonumber(dxCamisas) then
					local money = getPlayerMoney(localPlayer)
				elseif tonumber(dxCalcas) then
				elseif tonumber(dxTenis) then
				elseif tonumber(dxBone) then
					local money = getPlayerMoney(localPlayer)
					if money >= tonumber(bone[dxBone]) then
						takePlayerMoney(bone[dxBone])
						outputChatBox(bone[dxBone])
						setElementFrozen(localPlayer, false)
						setCameraTarget(localPlayer)
						removeEventHandler ("onClientRender", root, dxRoupas)
						removeEventHandler ("onClientRender", root, dxRoupasComprar)
						showCursor (false)
						dxRoupa = false
						if dxBone == 1 then
							if getElementData(localPlayer, "BoneClothes") then
								ten = (getElementData(localPlayer, "BoneClothes"))
								setElementData(localPlayer, "BoneClothes", 1 .."".. 1 .."".. 0 .."".. 1 .."" )
								outputChatBox(ten)
							else
							setElementData(localPlayer, "BoneClothes", dxBone)
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientClick", root, Comprar)

Aqui está uma tentiva de salvar se o player tiver 1 bone ali irá ficar 1 onde está 0, más sem sucesso, o getElementData retorna o texto inteiro ex: 1101 e não tenho ideia de como faço para ver o valor de cada número sem retornar os 4 números. 0 = Não tem boné 1 = tem boné

 

edit1 : esses elseif estão sendo por causa que cada um tem o seu valor, dxCalcas quando o player estiver na tabela de comprar calças e assim por diante

Edited by zMpyster
Link to comment
function Comprar (_,state)
	if dxRoupa == false then
		if state == "down" then
			if isCursorOnElement (x*115, y*277, x*95, y*15) then
				if tonumber(dxCamisas) then
					local money = getPlayerMoney(localPlayer)
				elseif tonumber(dxCalcas) then
				elseif tonumber(dxTenis) then
				elseif tonumber(dxBone) then
					local money = getPlayerMoney(localPlayer)
					if money >= tonumber(bone[dxBone]) then
						takePlayerMoney(bone[dxBone])
						outputChatBox(bone[dxBone])
						setElementFrozen(localPlayer, false)
						setCameraTarget(localPlayer)
						removeEventHandler ("onClientRender", root, dxRoupas)
						removeEventHandler ("onClientRender", root, dxRoupasComprar)
						showCursor (false)
						dxRoupa = false
						if dxBone == 1 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) >= 1000 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number .."D")
								else
								setElementData(localPlayer, "BoneClothes", 1000 + number )
								outputChatBox(1000 + number .."C")
								end
							else
							setElementData(localPlayer, "BoneClothes", 1000)
							end
						elseif dxBone == 2 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 100 or tonumber(number) >= 1100 or tonumber(number) == 101 or tonumber(number) == 111 or tonumber(number) == 1110 or tonumber(number) == 110 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number .."B")
								else
								setElementData(localPlayer, "BoneClothes", number + 100 )
								outputChatBox(number + 100 .."A")
								end
							else
							setElementData(localPlayer, "BoneClothes", 100)
							end
						elseif dxBone == 3 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 10 or tonumber(number) == 110 or tonumber(number) == 1110 or tonumber(number) == 1111 or tonumber(number) == 111 or tonumber(number) == 11 or tonumber(number) == 1010 or tonumber(number) == 1011 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number + 10 .."E")
								else
								setElementData(localPlayer, "BoneClothes", number + 10 )
								outputChatBox(number + 10 .."F")
								end
							else
							setElementData(localPlayer, "BoneClothes", 10)
							end
						elseif dxBone == 4 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 1 or tonumber(number) == 11 or tonumber(number) == 111 or tonumber(number) == 1011 or tonumber(number) == 1111 or tonumber(number) == 1001 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number + 1 .."H")
								else
								setElementData(localPlayer, "BoneClothes", number + 1 )
								outputChatBox(number + 1 .."G")
								end
							else
							setElementData(localPlayer, "BoneClothes", 1)
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientClick", root, Comprar)

 

Edited by zMpyster
Link to comment
26 minutes ago, zMpyster said:

function Comprar (_,state)
	if dxRoupa == false then
		if state == "down" then
			if isCursorOnElement (x*115, y*277, x*95, y*15) then
				if tonumber(dxCamisas) then
					local money = getPlayerMoney(localPlayer)
				elseif tonumber(dxCalcas) then
				elseif tonumber(dxTenis) then
				elseif tonumber(dxBone) then
					local money = getPlayerMoney(localPlayer)
					if money >= tonumber(bone[dxBone]) then
						takePlayerMoney(bone[dxBone])
						outputChatBox(bone[dxBone])
						setElementFrozen(localPlayer, false)
						setCameraTarget(localPlayer)
						removeEventHandler ("onClientRender", root, dxRoupas)
						removeEventHandler ("onClientRender", root, dxRoupasComprar)
						showCursor (false)
						dxRoupa = false
						if dxBone == 1 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) >= 1000 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number .."D")
								else
								setElementData(localPlayer, "BoneClothes", 1000 + number )
								outputChatBox(1000 + number .."C")
								end
							else
							setElementData(localPlayer, "BoneClothes", 1000)
							end
						elseif dxBone == 2 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 100 or tonumber(number) >= 1100 or tonumber(number) == 101 or tonumber(number) == 111 or tonumber(number) == 1110 or tonumber(number) == 110 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number .."B")
								else
								setElementData(localPlayer, "BoneClothes", number + 100 )
								outputChatBox(number + 100 .."A")
								end
							else
							setElementData(localPlayer, "BoneClothes", 100)
							end
						elseif dxBone == 3 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 10 or tonumber(number) == 110 or tonumber(number) == 1110 or tonumber(number) == 1111 or tonumber(number) == 111 or tonumber(number) == 11 or tonumber(number) == 1010 or tonumber(number) == 1011 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number + 10 .."E")
								else
								setElementData(localPlayer, "BoneClothes", number + 10 )
								outputChatBox(number + 10 .."F")
								end
							else
							setElementData(localPlayer, "BoneClothes", 10)
							end
						elseif dxBone == 4 then
							if getElementData(localPlayer, "BoneClothes") then
								local number = (getElementData(localPlayer, "BoneClothes"))
								if tonumber(number) == 1 or tonumber(number) == 11 or tonumber(number) == 111 or tonumber(number) == 1011 or tonumber(number) == 1111 or tonumber(number) == 1001 then
								setElementData(localPlayer, "BoneClothes", false)
								outputChatBox(number + 1 .."H")
								else
								setElementData(localPlayer, "BoneClothes", number + 1 )
								outputChatBox(number + 1 .."G")
								end
							else
							setElementData(localPlayer, "BoneClothes", 1)
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientClick", root, Comprar)

 

Acabei "economizando" 3 setElementData, se alguém encontrar quaisquer erro me fale por favor

Link to comment
6 hours ago, zMpyster said:

Olá pessoas eu dnv aqui com dúvida kk, queria saber como posso simplificar o setElementData e o setAccountData, para evitar trafego de rede... 


	if tonumber(dxBone) then
		if dxBone == 1 then
			addPedClothes ( localPlayer, "captruck", "captruck", 16 )
			Texto("Boné", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 50", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[1] = 50
		elseif dxBone == 2 then
			addPedClothes ( localPlayer, "skullygrn", "skullycap", 16 )
			Texto("Touca", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 25", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[2] = 25
		elseif dxBone == 3 then
			addPedClothes ( localPlayer, "hatmancblk", "hatmanc", 16 )
			Texto("Chapéu", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 20", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[3] = 20
		elseif dxBone == 4 then
			addPedClothes ( localPlayer, "capgang", "cap", 16 )
			Texto("Boné Preto", 150, 217, 300, 234, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
			Texto("R$ 45", 167, 240, 281, 257, tocolor(0, 169, 15, 254), 1.00, "default", "center", "center", false, false, false, false, false)
			bone[4] = 45
		end
	end

function Comprar (_,state)
	if dxRoupa == false then
		if state == "down" then
			if isCursorOnElement (x*115, y*277, x*95, y*15) then
				if tonumber(dxCamisas) then
					local money = getPlayerMoney(localPlayer)
				elseif tonumber(dxCalcas) then
				elseif tonumber(dxTenis) then
				elseif tonumber(dxBone) then
					local money = getPlayerMoney(localPlayer)
					if money >= tonumber(bone[dxBone]) then
						takePlayerMoney(bone[dxBone])
						outputChatBox(bone[dxBone])
						setElementFrozen(localPlayer, false)
						setCameraTarget(localPlayer)
						removeEventHandler ("onClientRender", root, dxRoupas)
						removeEventHandler ("onClientRender", root, dxRoupasComprar)
						showCursor (false)
						dxRoupa = false
						if dxBone == 1 then
							if getElementData(localPlayer, "BoneClothes") then
								ten = (getElementData(localPlayer, "BoneClothes"))
								setElementData(localPlayer, "BoneClothes", 1 .."".. 1 .."".. 0 .."".. 1 .."" )
								outputChatBox(ten)
							else
							setElementData(localPlayer, "BoneClothes", dxBone)
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientClick", root, Comprar)

Aqui está uma tentiva de salvar se o player tiver 1 bone ali irá ficar 1 onde está 0, más sem sucesso, o getElementData retorna o texto inteiro ex: 1101 e não tenho ideia de como faço para ver o valor de cada número sem retornar os 4 números. 0 = Não tem boné 1 = tem boné

Falei sobre isso no seu outro tópico, você pode separar esses valores com vírgula e obter cada um com a função split:

setElementData(localPlayer, "BoneClothes", "1,1,0,1" )
local bclothes = getElementData(localPlayer, "BoneClothes" )
if bclothes then
	local v = split( playerPosData, ',' )
	iprint( v )
end

 

Edited by DNL291
  • Thanks 1
Link to comment
5 minutes ago, DNL291 said:

Falei sobre isso no seu outro tópico, você pode separar esses valores com vírgula e obter cada um com a função split:


setElementData(localPlayer, "BoneClothes", "1,1,0,1" )local bclothes = getElementData(localPlayer, "BoneClothes" )if bclothes then	local v = split( playerPosData, ',' )	iprint( v )end

 

'split' essa função que eu estava procurando, obrigado, ficará bem mais fácil agr 

  • Like 1
Link to comment
40 minutes ago, DNL291 said:

Falei sobre isso no seu outro tópico, você pode separar esses valores com vírgula e obter cada um com a função split:


setElementData(localPlayer, "BoneClothes", "1,1,0,1" )local bclothes = getElementData(localPlayer, "BoneClothes" )if bclothes then	local v = split( playerPosData, ',' )	iprint( v )end

 

v = {}
function Comprar (_,state)
	if dxRoupa == false then
		if state == "down" then
			if isCursorOnElement (x*115, y*277, x*95, y*15) then
				if tonumber(dxCamisas) then
					local money = getPlayerMoney(localPlayer)
				elseif tonumber(dxCalcas) then
				elseif tonumber(dxTenis) then
				elseif tonumber(dxBone) then
					local money = getPlayerMoney(localPlayer)
					if money >= tonumber(bone[dxBone]) then
						takePlayerMoney(bone[dxBone])
						outputChatBox(bone[dxBone])
						setElementFrozen(localPlayer, false)
						setCameraTarget(localPlayer)
						removeEventHandler ("onClientRender", root, dxRoupas)
						removeEventHandler ("onClientRender", root, dxRoupasComprar)
						showCursor (false)
						dxRoupa = false
						if dxBone == 1 then
							if getElementData(localPlayer, "BoneClothes") then
								local c = getElementData(localPlayer, "BoneClothes")
								local v = split(c, ',')
								if v[1] == "1" then
									outputChatBox("OLA")
								else
									setElementData(localPlayer, "BoneClothes", "1,"..v[2]..","..v[3]..","..v[4] )
								end
							else
								setElementData(localPlayer, "BoneClothes", "1,0,0,0" )
							end
						elseif dxBone == 2 then
							if getElementData(localPlayer, "BoneClothes") then
								local c = getElementData(localPlayer, "BoneClothes")
								local v = split(c, ',')
								if v[2] == "1" then
									outputChatBox("OLAA")
								else
									setElementData(localPlayer, "BoneClothes", ""..v[1]..",1,"..v[3]..","..v[4] )
								end
							else
								setElementData(localPlayer, "BoneClothes", "0,1,0,0" )
							end
						elseif dxBone == 3 then
							if getElementData(localPlayer, "BoneClothes") then
								local c = getElementData(localPlayer, "BoneClothes")
								local v = split(c, ',')
								if v[3] == "1" then
									outputChatBox("OLAB")
								else
									setElementData(localPlayer, "BoneClothes", ""..v[1]..","..v[2]..",1,"..v[4] )
								end
							else
								setElementData(localPlayer, "BoneClothes", "0,0,1,0" )
							end
						elseif dxBone == 4 then
							if getElementData(localPlayer, "BoneClothes") then
								local c = getElementData(localPlayer, "BoneClothes")
								local v = split(c, ',')
								if v[4] == "1" then
									outputChatBox("OLAC")
									setElementData(localPlayer, "BoneClothes", false) 
								else
									setElementData(localPlayer, "BoneClothes", ""..v[1]..","..v[2]..","..v[3]..",1" )
								end
							else
								setElementData(localPlayer, "BoneClothes", "0,0,0,1" )
							end								
						end
					end
				end
			end
		end
	end
end
addEventHandler ("onClientClick", root, Comprar)

Observe como uma função facilita totalmente a criação de um script.

  • Like 1
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...