Tony Scripter Posted March 15, 2021 Posted March 15, 2021 (edited) Olá, estou desenvolvendo uma loja de roupas por tabela, porem quando eu compro uma roupa ele não adiciona a roupa que eu selecionei ele vai para a roupa, sem camisa. function clickRender(btn, state) if varClothes == true then if btn == "left" and state == "up" then for t = 1, #gridClothes do local ix, iy, iw, ih, id = gridClothes[t][1], gridClothes[t][2], gridClothes[t][3], gridClothes[t][4], gridClothes[t][5] if cursorPosition(ix, iy, iw, ih) then refreshClothes() end if cursorPosition(x*370, y*250, y*310, x*215) then local name, id, price = Shirt[id][1], Shirt[id][2], Shirt[id][3] local texture, model = getClothesByTypeIndex(0, id) addPedClothes(localPlayer, texture, model, 0) CloseClothes() end end end end end addEventHandler("onClientClick", root, clickRender) Edited March 15, 2021 by Tony Scripter
androksi Posted March 16, 2021 Posted March 16, 2021 Olá. Bem-vindo(a) ao fórum. O que a função deveria fazer? Da forma que você descreveu o problema, acredito que aquele clique não deveria estar dentro do laço de repetição. Além disso, não vejo nenhuma lógica para selecionar a roupa.
Tony Scripter Posted March 16, 2021 Author Posted March 16, 2021 1 hour ago, andr0xy said: Olá. Bem-vindo(a) ao fórum. O que a função deveria fazer? Da forma que você descreveu o problema, acredito que aquele clique não deveria estar dentro do laço de repetição. Além disso, não vejo nenhuma lógica para selecionar a roupa. Entendi, bom eu mudei um pouco sobre a função porem ele da um erro no debugscript, falando que não consegue indentificaro (ID) da roupa porque a roupa primaria seta em um ped como se fosse o usuário e compra seta no player, pois assim ele não ira ficar clicando na roupa e gastando dinheiro function clickRender(btn, state) if varClothes == true then if btn == "left" and state == "up" then for t = 1, #gridClothes do local ix, iy, iw, ih, id = gridClothes[t][1], gridClothes[t][2], gridClothes[t][3], gridClothes[t][4], gridClothes[t][5] if cursorPosition(ix, iy, iw, ih) then local name, id, price = Shirt[id][1], Shirt[id][2], Shirt[id][3] local texture, model = getClothesByTypeIndex(0, id) addPedClothes(ped, texture, model, 0) end end end end end addEventHandler("onClientClick", root, clickRender) function clickBuy(btn, state) if varClothes == true then if btn == "left" and state == "up" then if cursorPosition(x*370, y*250, y*310, x*215) then local texture, model = getClothesByTypeIndex(0, id) addPedClothes(localPlayer, texture, model, 0) CloseClothes() end end end end addEventHandler("onClientClick", root, clickBuy) O novo codigo está assim, o unico problema que está a fazer e o set da roupa no localPlayer Bom consegui resolver o codigo aqui sozinho, obrigado por tentar ajudar qualquer outra duvida irei postar aqui no forum
androksi Posted March 16, 2021 Posted March 16, 2021 O erro ocorre pois na função de comprar a roupa, aquele ID não existe. Crie uma variável local pra você armazenar o ID selecionado pelo usuário. Uma coisa que percebi também, você tá percorrendo por todos os valores da tabela gridClothes. É recomendado que você utilize um break para parar a execução do loop for. Spoiler local currentIndex = 0 function clickRender(btn, state) if varClothes == true then if btn == "left" and state == "up" then for t = 1, #gridClothes do local ix, iy, iw, ih, id = gridClothes[t][1], gridClothes[t][2], gridClothes[t][3], gridClothes[t][4], gridClothes[t][5] if cursorPosition(ix, iy, iw, ih) then local name, id, price = Shirt[id][1], Shirt[id][2], Shirt[id][3] local texture, model = getClothesByTypeIndex(0, id) addPedClothes(ped, texture, model, 0) currentIndex = id break end end end end end addEventHandler("onClientClick", root, clickRender) E lá na função de comprar, use o currentIndex em vez do ID.
Tony Scripter Posted March 16, 2021 Author Posted March 16, 2021 Sim fiz exatamente desse jeito, obrigado pela dica irei usar o break aqui valeu!
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