FelipeMallmann Posted June 1, 2015 Posted June 1, 2015 Galera eu estou tentando fazer com que quando eu coloque um objeto no jogo ele seja setado no interior em que o player está, e nao no interior 0. tent = createObject(3243,vx,vy,z-1,0,0,vrot) setElementInterior(tent, getElementInterior(source)) Por que isso não está funcionando? codigo completo function onPlayerPitchATent (itemName) setElementData(source,itemName,getElementData(source,itemName)-1) setPedAnimation (source,"BOMBER","BOM_Plant",-1, false, false, false, false) local source = source setTimer( function () local x,y,z = getElementPosition(source) local xr,yr,zr = getElementRotation(source) px, py, pz = getElementPosition(source) prot = getPedRotation(source) local offsetRot = math.rad(prot+90) local vx = px + 5 * math.cos(offsetRot) local vy = py + 5 * math.sin(offsetRot) local vz = pz + 2 local vrot = prot+180 tent = createObject(3243,vx,vy,z-1,0,0,vrot) setElementInterior(tent, getElementInterior(source)) setObjectScale(tent,1.3) 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) setElementData(tentCol,"MAX_Slots",100) triggerClientEvent(source,"refreshInventoryManual",source) end,1500,1) end addEvent("onPlayerPitchATent",true) addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
DNL291 Posted June 6, 2015 Posted June 6, 2015 Você recebe algum erro no debug? Certifique-se que getElementInterior(source) esteja retornando o valor correto.
FelipeMallmann Posted June 7, 2015 Author Posted June 7, 2015 Não da erro, ele simplesmente não executa isso, e quando ao inves de getElementInterior(source) eu coloco um numero inteiro, ai funciona! Exemplo tent = createObject(3243,vx,vy,z-1,0,0,vrot) setElementInterior(tent, 18) Porem eu não jogo apenas em um interior, precisaria identificar o interior que o player está e criar esse objeto naquele interior. Provavelmente getElementInterior(source) Deve estar retornando nil, mas por que? Existe alguma outra logica para fazer o que preciso? Obrigado!
#RooTs Posted June 7, 2015 Posted June 7, 2015 Felipe, já tentou setar a dimensão dele ? tent = createObject(3243,vx,vy,z-1,0,0,vrot) setElementInterior(tent, 18) setElementDimension(tent, 0) -- o padrão é (0)
FelipeMallmann Posted June 7, 2015 Author Posted June 7, 2015 Nao, nao tem nada a ver com a dimensao! Eu quero fazer alguma coisa que verique o interior que o player está, e crie o objeto nele. Digamos que ele tem um comando para criar o objeto, mas se ele ta no interior 0, ele cria no 0, se ele ta no 18, ele cria no 18, para nao o objeto nao ficar invisivel quando o player estiver em interiores
Death Posted June 7, 2015 Posted June 7, 2015 Post o trigger do evento onPlayerPitchATent provavelmente o erro estara la
FelipeMallmann Posted June 8, 2015 Author Posted June 8, 2015 elseif itemName == "Tent" then triggerServerEvent("onPlayerPitchATent",getLocalPlayer(),itemName) Quando ele clicar no nome Tent, chama o evento function onPlayerPitchATent (itemName) setElementData(source,itemName,getElementData(source,itemName)-1) setPedAnimation (source,"BOMBER","BOM_Plant",-1, false, false, false, false) local source = source setTimer( function () local x,y,z = getElementPosition(source) local xr,yr,zr = getElementRotation(source) px, py, pz = getElementPosition(source) prot = getPedRotation(source) local offsetRot = math.rad(prot+90) local vx = px + 5 * math.cos(offsetRot) local vy = py + 5 * math.sin(offsetRot) local vz = pz + 2 local vrot = prot+180 tent = createObject(3243,vx,vy,z-1,0,0,vrot) setObjectScale(tent,1.3) 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) setElementData(tentCol,"MAX_Slots",100) triggerClientEvent(source,"refreshInventoryManual",source) end,1500,1) end addEvent("onPlayerPitchATent",true) addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
Death Posted June 9, 2015 Posted June 9, 2015 tenta agora! elseif itemName == "Tent" then triggerServerEvent(getLocalPlayer(),"onPlayerPitchATent",getLocalPlayer(),itemName) function onPlayerPitchATent (source,itemName) setElementData(source,itemName,getElementData(source,itemName)-1) setPedAnimation (source,"BOMBER","BOM_Plant",-1, false, false, false, false) local source = source setTimer( function () local x,y,z = getElementPosition(source) local xr,yr,zr = getElementRotation(source) px, py, pz = getElementPosition(source) prot = getPedRotation(source) local offsetRot = math.rad(prot+90) local vx = px + 5 * math.cos(offsetRot) local vy = py + 5 * math.sin(offsetRot) local vz = pz + 2 local vrot = prot+180 tent = createObject(3243,vx,vy,z-1,0,0,vrot) setObjectScale(tent,1.3) 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) setElementData(tentCol,"MAX_Slots",100) triggerClientEvent(source,"refreshInventoryManual",source) end,1500,1) end addEvent("onPlayerPitchATent",true) addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
FelipeMallmann Posted June 9, 2015 Author Posted June 9, 2015 Nao funcionou, colocando o triggerServerEvent dessa forma ele não funciona
Banex Posted June 9, 2015 Posted June 9, 2015 tente isso e veja oque getElementInterior esta retornando no debugscript. function onPlayerPitchATent(itemName) setElementData(source,itemName,getElementData(source,itemName)-1) setPedAnimation (source,"BOMBER","BOM_Plant",-1, false, false, false, false) setTimer(function(player) if isElement(player) then local x,y,z = getElementPosition(player) local xr,yr,zr = getElementRotation(player) px, py, pz = getElementPosition(player) prot = getPedRotation(player) local offsetRot = math.rad(prot+90) local vx = px + 5 * math.cos(offsetRot) local vy = py + 5 * math.sin(offsetRot) local vz = pz + 2 local vrot = prot+180 tent = createObject(3243,vx,vy,z-1,0,0,vrot) outputDebugString(getElementInterior(player)) setElementInterior(tent,getElementInterior(player)) setObjectScale(tent,1.3) 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) setElementData(tentCol,"MAX_Slots",100) triggerClientEvent(player,"refreshInventoryManual",player) end end,1500,1,source) end addEvent("onPlayerPitchATent",true) addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
DNL291 Posted June 9, 2015 Posted June 9, 2015 Não da erro, ele simplesmente não executa isso, e quando ao inves de getElementInterior(source) eu coloco um numero inteiro, ai funciona! Acho estranho apenas não executar o código e não ter erros no debug, sendo que getElementInterior que não funcionou (já que você colocou um interior manualmente e funcionou). Imagino que seja realmente source que não é o jogador. Tem certeza que usou o comando debugscript 3? Sempre que se deparar com erros no script, use outputChatBox/outputDebugString até encontrar o que está errado.
FelipeMallmann Posted June 10, 2015 Author Posted June 10, 2015 Bom, fiz da forma como o Banex criou, porem modifiquei para aparecer no chat ao invés do debug, para facilitar mais. E ta acontecendo o seguinte. Quando estou no interior normal (0) ele cria a tenda no interior 0 e fala no chat: 0. Quando estou em algum outro interior (18 por exemplo) ele cria a tenda no interior 0 e fala no chat: 0. Ou seja, ele não está conseguindo identificar que o player está no interior, mas isso não faz sentido algum.. Edit: Tudo isso é feito no server side, conforme ta no wiki https://wiki.multitheftauto.com/wiki/GetElementInterior. Pensei que poderia está como client e ai não funcionava por isso, mas já verifiquei e está tudo de acordo Se ele não estivesse conseguindo pegar o player viria um nil, não? Ele não dá erro algum pois ele está pegar o interior 0 mesmo eu não estando nele Edit 2: O problema não era com o script.. Era o seguinte, eu estava usando um comando que mudava meu interior de player, e então tentando colocar a tenda, mas por algum motivo meu interior ainda fica como 1. Testei agora com os interiores padrões do gta e funcionou! Muito obrigado a todos que me ajudaram! Edit 3: Só que agora tem outro problema, ele não faz o attachElements ( tentCol, tent, 0, 0, 0 ), ou seja, não adiciona colisão no objeto. 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) setElementData(tentCol,"MAX_Slots",100)
#RooTs Posted June 10, 2015 Posted June 10, 2015 Teste meu exemplo, se funcionar ou quaisquer coisa já não sei ( apenas tente ) function onPlayerPitchATent(itemName) setElementData(source,itemName,getElementData(source,itemName)-1) setPedAnimation (source,"BOMBER","BOM_Plant",-1, false, false, false, false) setTimer(function(player) if isElement(player) then local px, py, pz = getElementPosition(player) local offsetRot = math.rad(getPedRotation(player)+90) tent = createObject(3243,px+5*math.cos(offsetRot),py+5*math.sin(offsetRot),pz-1,0,0,getPedRotation(player)+180) outputDebugString(getElementInterior(player)) setElementInterior(tent,getElementInterior(player)) setObjectScale(tent,1.3) tentCol = createColSphere(px, py, pz,4) attachElements ( tentCol, tent, 0, 0, 0 ) setElementData(tentCol,"parent",tent) setElementData(tent,"parent",tentCol) setElementData(tentCol,"tent",true) setElementData(tentCol,"vehicle",true) setElementData(tentCol,"MAX_Slots",100) triggerClientEvent(player,"refreshInventoryManual",player) end end,1500,1,source) end addEvent("onPlayerPitchATent",true) addEventHandler("onPlayerPitchATent",getRootElement(),onPlayerPitchATent)
FelipeMallmann Posted June 10, 2015 Author Posted June 10, 2015 Testei e nada, continua sem a colisão.
FelipeMallmann Posted June 11, 2015 Author Posted June 11, 2015 @Problema resolvido! Muito Obrigado a todos
#RooTs Posted June 11, 2015 Posted June 11, 2015 @Problema resolvido! Muito Obrigado a todos qual era o problema ? poste o seu roteiro aqui para todos ver
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