WeeD1 Posted March 4, 2019 Posted March 4, 2019 Opa, estou tentando solucionar o erro de todos os mods do meu servidor, porém apareceu um aqui que eu não consigo solucionar, aparentemente não vi nada de errado, alguém poderia me ajudar a solucionar isso? pfv WARNING: Loja1\server.lua:25: Bad argument @ 'givePlayerMoney' [Expected element at argument 1] WARNING: Loja1\server.lua:26: Bad argument @ 'outputChatBox' [Expected element at argument 2] function comandoloja (source) if isElementWithinMarker (source, roubarloja ) then for _,players in pairs(getElementsByType("player")) do for i, k in pairs(corps) do local ContaACL = getAccountName ( getPlayerAccount ( players ) ) if isObjectInACLGroup ("user."..ContaACL, aclGetGroup (k)) then outputChatBox("#ffffff*#FF0000Atenção - O Jogador:#ffffff " .. getPlayerName(source) .. " #FF0000Está Roubando a Loja1.", players,255,255,255,true) end end end setPlayerWantedLevel ( source, 6 ) setElementPosition ( lojasair1, 834.66760, 7.45359, 1050) setElementPosition ( roubarloja, 822.74316, -0.47490, 1050) outputChatBox ('#ffffffAguarde Enquanto Você Pega O Dinheiro!',source,255,255,255,true) setPedAnimation(source, "SHOP", "ROB_Loop_Threat", 40000, true, false, false, false) setPedRotation(source,90 ) setPedAnimation( ped, "SHOP", "SHP_Rob_HandsUp") triggerClientEvent ( root, "roubar", root) setElementVisibleTo ( blipalarme, root, true ) setTimer ( function() setElementPosition ( lojasair1, 834.664418,7.3,1005.18701) setElementInterior ( roubarloja, 3) setPedAnimation(ped,false) setElementPosition ( ped, 819.40869, -0.45965, 1004.17969) givePlayerMoney ( source, 1300 ) outputChatBox ('#ffffffVocê Roubou a Loja 1 e Pegou #00ff00R$1.000',source,255,255,255,true) end, 40000, 1 ) setTimer ( function() setElementVisibleTo ( blipalarme, root, false ) setElementPosition( roubarloja, 822.74316, -0.47490, 1003.2) end, 80000, 1 ) end end addCommandHandler ( "assaltar", comandoloja )
DNL291 Posted March 4, 2019 Posted March 4, 2019 Tente: function comandoloja (source) if isElementWithinMarker (source, roubarloja ) then for _,players in pairs(getElementsByType("player")) do for i, k in pairs(corps) do local ContaACL = getAccountName ( getPlayerAccount ( players ) ) if isObjectInACLGroup ("user."..ContaACL, aclGetGroup (k)) then outputChatBox("#ffffff*#FF0000Atenção - O Jogador:#ffffff " .. getPlayerName(source) .. " #FF0000Está Roubando a Loja1.", players,255,255,255,true) end end end setPlayerWantedLevel ( source, 6 ) setElementPosition ( lojasair1, 834.66760, 7.45359, 1050) setElementPosition ( roubarloja, 822.74316, -0.47490, 1050) outputChatBox ('#ffffffAguarde Enquanto Você Pega O Dinheiro!',source,255,255,255,true) setPedAnimation(source, "SHOP", "ROB_Loop_Threat", 40000, true, false, false, false) setPedRotation(source,90 ) setPedAnimation( ped, "SHOP", "SHP_Rob_HandsUp") triggerClientEvent ( root, "roubar", root) setElementVisibleTo ( blipalarme, root, true ) setTimer ( function(player) setElementPosition ( lojasair1, 834.664418,7.3,1005.18701) setElementInterior ( roubarloja, 3) setPedAnimation(ped,false) setElementPosition ( ped, 819.40869, -0.45965, 1004.17969) givePlayerMoney ( player, 1300 ) outputChatBox ('#ffffffVocê Roubou a Loja 1 e Pegou #00ff00R$1.000',player,255,255,255,true) end, 40000, 1, source ) setTimer ( function() setElementVisibleTo ( blipalarme, root, false ) setElementPosition( roubarloja, 822.74316, -0.47490, 1003.2) end, 80000, 1 ) end end addCommandHandler ( "assaltar", comandoloja ) 1 Please do not PM me with scripting related question nor support, use the forums instead.
WeeD1 Posted March 4, 2019 Author Posted March 4, 2019 (edited) Ele está dando isso, tentei também trocar para thePlayer e mesmo assim continuou WARNING: Loja1\server.lua:26: Bad argument @ 'givePlayerMoney' [Expected element at argument 1, got nil] Edited March 4, 2019 by WeeD1
Tommy. Posted March 4, 2019 Posted March 4, 2019 (edited) 1 hour ago, WeeD1 said: Ele está dando isso, tentei também trocar para thePlayer e mesmo assim continuou WARNING: Loja1\server.lua:26: Bad argument @ 'givePlayerMoney' [Expected element at argument 1, got nil] Tente isso: function comandoloja (source) if isElementWithinMarker (source, roubarloja ) then for _,players in pairs(getElementsByType("player")) do for i, k in pairs(corps) do local ContaACL = getAccountName ( getPlayerAccount ( players ) ) if isObjectInACLGroup ("user."..ContaACL, aclGetGroup (k)) then outputChatBox("#ffffff*#FF0000Atenção - O Jogador:#ffffff " .. getPlayerName(source) .. " #FF0000Está Roubando a Loja1.", players,255,255,255,true) end end end setPlayerWantedLevel ( source, 6 ) setElementPosition ( lojasair1, 834.66760, 7.45359, 1050) setElementPosition ( roubarloja, 822.74316, -0.47490, 1050) outputChatBox ('#ffffffAguarde Enquanto Você Pega O Dinheiro!',source,255,255,255,true) setPedAnimation(source, "SHOP", "ROB_Loop_Threat", 40000, true, false, false, false) setPedRotation(source,90 ) setPedAnimation( ped, "SHOP", "SHP_Rob_HandsUp") triggerClientEvent ( root, "roubar", root) setElementVisibleTo ( blipalarme, root, true ) setTimer ( function(source) setElementPosition ( lojasair1, 834.664418,7.3,1005.18701) setElementInterior ( roubarloja, 3) setPedAnimation(ped,false) setElementPosition ( ped, 819.40869, -0.45965, 1004.17969) givePlayerMoney ( source, 1300 ) outputChatBox ('#ffffffVocê Roubou a Loja 1 e Pegou #00ff00R$1.000',source,255,255,255,true) end, 40000, 1, source ) setTimer ( function() setElementVisibleTo ( blipalarme, root, false ) setElementPosition( roubarloja, 822.74316, -0.47490, 1003.2) end, 80000, 1 ) end end addCommandHandler ( "assaltar", comandoloja ) EDIT 1: Não testei! Edited March 4, 2019 by Tommy. 1 DID I HELP YOU? ________________________________________________________________________ ム MY STEAM ________________________________________________________________________ MY SITE www.tommy.br.com
Moderators Lord Henry Posted March 4, 2019 Moderators Posted March 4, 2019 O erro acontece pois dentro do setTimer, o source deixa de existir. Pois ele pertence somente à função principal e no setTimer é outra função. 1 Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
DNL291 Posted March 4, 2019 Posted March 4, 2019 Testei meu código e ele funciona. Tente por aqui: https://pastebin.com/05ZwD3k9 Please do not PM me with scripting related question nor support, use the forums instead.
[M]ister Posted March 4, 2019 Posted March 4, 2019 7 hours ago, Lord Henry said: O erro acontece pois dentro do setTimer, o source deixa de existir. Pois ele pertence somente à função principal e no setTimer é outra função. Como a função do timer está dentro de uma função principal as variáveis da principal são acessíveis também nela.
Moderators Lord Henry Posted March 4, 2019 Moderators Posted March 4, 2019 3 hours ago, MaligNos said: Como a função do timer está dentro de uma função principal as variáveis da principal são acessíveis também nela. Não quando a variável é parâmetro de função, ela só funciona dentro dela mesma. Por isso é necessário passar o source para a função do setTimer, pois naturalmente ela não vai funcionar. Ou então vc coloca o source em uma variável local e dai usa essa variável local dentro da função do setTimer, que por estar dentro do escopo da função principal, dai funciona. Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
[M]ister Posted March 4, 2019 Posted March 4, 2019 27 minutes ago, Lord Henry said: Não quando a variável é parâmetro de função, ela só funciona dentro dela mesma. Por isso é necessário passar o source para a função do setTimer, pois naturalmente ela não vai funcionar. Ou então vc coloca o source em uma variável local e dai usa essa variável local dentro da função do setTimer, que por estar dentro do escopo da função principal, dai funciona. Acabei de testar: -- https://www.lua.org/cgi-bin/demo function teste(var) function teste2() print(var) end teste2() end teste("oie") -- output: oie
Moderators Lord Henry Posted March 5, 2019 Moderators Posted March 5, 2019 (edited) Teste isso então: function teste (enteringPlayer, seat, jacked, door) -- source = veículo setTimer (function () print (getElementModel(source)) -- ERRO: source = nil end, 100, 1) end addEventHandler ("onVehicleStartEnter", getRootElement(), teste) function teste (enteringPlayer, seat, jacked, door) -- source = veículo -- setTimer (function () print (getElementModel(source)) -- source = veículo -- end, 100, 1) end addEventHandler ("onVehicleStartEnter", getRootElement(), teste) 1 hour ago, Lord Henry said: Não quando a variável é parâmetro de função, ela só funciona dentro dela mesma. Por isso é necessário passar o source para a função do setTimer, pois naturalmente ela não vai funcionar. Ou então vc coloca o source em uma variável local e dai usa essa variável local dentro da função do setTimer, que por estar dentro do escopo da função principal, dai funciona. No caso me equivoquei quando eu disse parâmetro de função. Na verdade só perde se for source de evento. Edited March 5, 2019 by Lord Henry Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
Moderators Lord Henry Posted March 5, 2019 Moderators Posted March 5, 2019 (edited) function teste (enteringPlayer, seat, jacked, door) -- source = veículo setTimer (function () print (getElementModel(enteringPlayer)) -- enteringPlayer ainda existe. Mas o source do evento não. print (getElementModel(source)) -- ERRO: source = nil end, 100, 1) end addEventHandler ("onVehicleStartEnter", getRootElement(), teste) Edited March 5, 2019 by Lord Henry Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment Discord Oficial do MTA: https://mtasa.com/discord Blacklist e Whitelist de Scripters: Planilha Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.
[M]ister Posted March 5, 2019 Posted March 5, 2019 Não é muito lógico ele deixar de existir, dei uma olhada aqui e notei que e o source só se “perde” na função do setTimer: function teste (enteringPlayer, seat, jacked, door) -- source = veículo (function() print (getElementModel(source)) -- ok end)() setTimer (function () print (getElementModel(source)) -- fail end, 100, 1) end addEventHandler ("onVehicleStartEnter", getRootElement(), teste) As variáveis globais do addEventHandler: this, client, eventName, etc, também deixam de existir. Meu palpite é que no código fonte do setTimer existe algum método resetando essas variáveis (talvez aqui). No caso do tópico em que não existe a variável predefinida source de um evento, mas sim uma variável que foi declarada com o mesmo nome no parâmetro, acaba por não influenciar: addCommandHandler("oie", function(source) setTimer (function () print(source) -- ok end, 100, 1) end ) 1
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