EW1611 Posted September 24, 2019 Share Posted September 24, 2019 Olá, fiz o seguinte script no lado client, porém, da esse erro de que a função, invés de ser localPlayer ele pega a string do comando, "colher" dff = engineLoadDFF("grassplant01.dff") engineReplaceModel(dff, 3409) addCommandHandler("devmode", function() setDevelopmentMode(true) end ) plantas = { {-1014, -1609.2, 75.36}, {-1010, -1609.242, 75.367}, {-1006, -1609.19, 75.36}, {-1002, -1609.104, 75.36}, {-998, -1609.082, 75.36}, {-994, -1609.037, 75.36}, {-990, -1609.037, 75.36}, {-1014, -1613, 75.36}, {-1010, -1613, 75.367}, {-1006, -1613, 75.36}, {-1002, -1613, 75.36}, {-998, -1613, 75.36}, {-994, -1613, 75.36}, {-990, -1613, 75.36}, {-1014, -1617, 75.36}, {-1010, -1617, 75.367}, {-1006, -1617, 75.36}, {-1002, -1617, 75.36}, {-998, -1617, 75.36}, {-994, -1617, 75.36}, {-990, -1617, 75.36}, {-1014, -1621, 75.36}, {-1010, -1621, 75.367}, {-1006, -1621, 75.36}, {-1002, -1621, 75.36}, {-998, -1621, 75.36}, {-994, -1621, 75.36}, {-990, -1621, 75.36}, } for i, v in ipairs ( plantas ) do plantas = createObject(3409, v[1],v[2],v[3]) colP = createColCircle(v[1],v[2],1.5) end function fcm1(localPlayer, commandname) if isElementWithinColShape(localPlayer, colP) then setPedAnimation(localPlayer,"INT_HOUSE","wash_up",10000,false,false,true,false) setTimer(function () star = getPlayerWantedLevel() setPlayerWantedLevel(localPlayer) setPedAnimation(localPlayer) givePlayerMoney(math.random(500,1000)) end,10000,1) end end addCommandHandler("colher", fcm1) erro: Bad argument @ 'isElementWithinColShape' [Expected element at argument 1,got string 'colher'] Link to comment
Furzy Posted September 24, 2019 Share Posted September 24, 2019 (edited) Eu acho que voce nao precisa especificar o localPlayer no paramentro da função só o ( commandname ) se n o comando vai ler o localPlayer tb exemplo /colher [localPlayer] [comando] e nao entendi tb pq o commandname ali se voce nao ta especificando ele em lugar nenhum testa sem function fcm1() nao tenho certeza nunca usei assim em client Edited September 24, 2019 by Furzy 1 Link to comment
Other Languages Moderators Lord Henry Posted September 24, 2019 Other Languages Moderators Share Posted September 24, 2019 Assim nunca vai dar certo. Você está usando funções client-side e server-side no mesmo script. 1 Link to comment
EW1611 Posted September 24, 2019 Author Share Posted September 24, 2019 @Furzy Deu certo, obrigado e @Lord Henry nem percebi que o setPlayerWantedLevel era server-side, obrigado por me avisar Link to comment
EW1611 Posted September 25, 2019 Author Share Posted September 25, 2019 (edited) Fiz algumas mudanças, colocando invés de colCircle, coloquei markers, e por algum motivo não está mais funcionando dff = engineLoadDFF("grassplant01.dff") engineReplaceModel(dff, 3409) addCommandHandler("devmode", function() setDevelopmentMode(true) end ) plantas = { {-1014, -1609.2, 75.36}, {-1010, -1609.242, 75.367}, {-1006, -1609.19, 75.36}, {-1002, -1609.104, 75.36}, {-998, -1609.082, 75.36}, {-994, -1609.037, 75.36}, {-990, -1609.037, 75.36}, {-1014, -1613, 75.36}, {-1010, -1613, 75.367}, {-1006, -1613, 75.36}, {-1002, -1613, 75.36}, {-998, -1613, 75.36}, {-994, -1613, 75.36}, {-990, -1613, 75.36}, {-1014, -1617, 75.36}, {-1010, -1617, 75.367}, {-1006, -1617, 75.36}, {-1002, -1617, 75.36}, {-998, -1617, 75.36}, {-994, -1617, 75.36}, {-990, -1617, 75.36}, {-1014, -1621, 75.36}, {-1010, -1621, 75.367}, {-1006, -1621, 75.36}, {-1002, -1621, 75.36}, {-998, -1621, 75.36}, {-994, -1621, 75.36}, {-990, -1621, 75.36}, } for i, v in ipairs ( plantas ) do plantas = createObject(3409, v[1],v[2],v[3]) colP = createMarker(v[1],v[2],v[3],"cylinder",2.5,0,0,0,0) end function fcm1() if isElementWithinMarker(localPlayer, colP) then setPedAnimation(localPlayer,"INT_HOUSE","wash_up",10000,true,false,true,false,10) setTimer(function () setPedAnimation(localPlayer) givePlayerMoney(math.random(500,1000)) end,10000,1) end end addCommandHandler("colher", fcm1) edit:Não há nenhum erro no debugscript, e o script está no lado client Edited September 26, 2019 by EW1611 Link to comment
Other Languages Moderators Lord Henry Posted September 26, 2019 Other Languages Moderators Share Posted September 26, 2019 Sua lógica de criação do plantas e colP está errada. Você precisa colocá-los em uma table vazia antes de criá-los. Senão a variável sempre será substituída a cada execução do loop. Isso significa que ao final do loop, você criou vários plantas e vários colP, mas somente o último pode ser acessado pelo script, pois são os únicos que estão nas variáveis plantas e colP, os outros ficaram sem variável para serem chamados. Dessa forma, somente 1 planta e 1 colP funcionam. dff = engineLoadDFF("grassplant01.dff") engineReplaceModel(dff, 3409) addCommandHandler("devmode", function() setDevelopmentMode(true) end ) plantas = { {-1014, -1609.2, 75.36}, {-1010, -1609.242, 75.367}, {-1006, -1609.19, 75.36}, {-1002, -1609.104, 75.36}, {-998, -1609.082, 75.36}, {-994, -1609.037, 75.36}, {-990, -1609.037, 75.36}, {-1014, -1613, 75.36}, {-1010, -1613, 75.367}, {-1006, -1613, 75.36}, {-1002, -1613, 75.36}, {-998, -1613, 75.36}, {-994, -1613, 75.36}, {-990, -1613, 75.36}, {-1014, -1617, 75.36}, {-1010, -1617, 75.367}, {-1006, -1617, 75.36}, {-1002, -1617, 75.36}, {-998, -1617, 75.36}, {-994, -1617, 75.36}, {-990, -1617, 75.36}, {-1014, -1621, 75.36}, {-1010, -1621, 75.367}, {-1006, -1621, 75.36}, {-1002, -1621, 75.36}, {-998, -1621, 75.36}, {-994, -1621, 75.36}, {-990, -1621, 75.36}, } plant = {} colP = {} for i, v in ipairs (plantas) do plant[i] = createObject(3409, v[1],v[2],v[3]) colP[i] = createMarker(v[1],v[2],v[3],"cylinder",2.5,0,0,0,0) end function fcm1 () for i, col in ipairs (colP) do if isElementWithinMarker (localPlayer, col) then setPedAnimation (localPlayer, "INT_HOUSE", "wash_up", 10000, true, false, true, false, 10) setTimer(function () setPedAnimation (localPlayer) givePlayerMoney (math.random (500, 1000)) destroyElement (plant[i]) plant[i] = nil destroyElement (colP[i]) colP[i] = nil end, 10000, 1) break end end end addCommandHandler ("colher", fcm1) Outro problema que percebi, é que você estava criando as plantas na mesma variável da table plantas. 1 Link to comment
EW1611 Posted September 26, 2019 Author Share Posted September 26, 2019 Obrigado, funcionou, mas você consegue me explicar melhor como q funciona uma table, ou me recomendar algo para ler? Link to comment
DNL291 Posted September 29, 2019 Share Posted September 29, 2019 On 26/09/2019 at 18:10, EW1611 said: Obrigado, funcionou, mas você consegue me explicar melhor como q funciona uma table, ou me recomendar algo para ler? Tem alguns tutoriais de Lua nesse tópico: https://forum.multitheftauto.com/topic/116681-informações-úteis-scriptingconfiguraçõestutoriais-para-o-mta/ 1 Link to comment
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