#DeltaSCR Posted March 19, 2019 Posted March 19, 2019 Olá, olha eu aqui novamente rsrs... Então, estou desenvolvendo um Script de uma espécie de Seguradora, só que chegou á um ponto que me deparei que vou ter que usar setElementData e TriggerEvent, porém estou com muita dúvida. A parte de Abrir e Fechar o Painel está funcionando normalmente, porém onde eu quero chegar: Quando o jogador clicar no botão de Compra (Especificado no Código), seja setado nele uma data, que seria a String e mais um Número, no caso esse número seria um Kit a mais para esse jogador, e também que possa ter no máximo 3 kits... Sinceramente, estou bem perdido nessa parte, se puderem me ajudar agradeço... client-side: local screenW, screenH = guiGetScreenSize() DeltaSCRPainel = false function DeltaSCRDirectX () -- @Comprar-Prata dxDrawRectangle(screenW * 0.3969, screenH * 0.5833, screenW * 0.0977, screenH * 0.0417, tocolor(50, 200, 50, 255), false) end function DeltaSCRAbrir () if DeltaSCRPainel == false then DeltaSCRPainel = true showCursor (true) showChat (false) addEventHandler ("onClientRender", getRootElement(), DeltaSCRDirectX) else DeltaSCRPainel = false showCursor (false) showChat (true) removeEventHandler ("onClientRender", getRootElement(), DeltaSCRDirectX) end end addEvent ("DeltaSCR:OC", true) addEventHandler ("DeltaSCR:OC", getRootElement(), DeltaSCRAbrir) -- @Comprar-Prata function DeltaComprarPrata (button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if DeltaSCRPainel == true then if state == "down" then if isCursorOnElement (screenW * 0.3203, screenH * 0.2667, screenW * 0.3594, screenH * 0.4667) then -- //Aqui eu acho que começaria a funcionalidade em si... end end end end addEventHandler ("onClientClick", getRootElement(), DeltaComprarPrata) -- @Cursor function cursorPosition (x, y, w, h) if (not isCursorShowing()) then return false end local mx, my = getCursorPosition() local fullx, fully = guiGetScreenSize() cursorx, cursory = mx*fullx, my*fully if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true else return false end end function isCursorOnElement (x, y, w, h) local mx,my = getCursorPosition () local fullx,fully = guiGetScreenSize() cursorx,cursory = mx*fullx,my*fully if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then return true else return false end end
#DaNiLiN Posted March 19, 2019 Posted March 19, 2019 Não é preciso passar por triggerEvent :\ ai vai um exemplo. function Verificar_Kits () local Kits = tonumber(getElementData(localPlayer, "Kit")) or 0 -- Verifica a quantia de kits if Kits < 3 then -- OS kits do jogador deve ser menor que 3 setElementData(localPlayer, "Kit", Kits +1) -- setar mais 1 de kit else -- caso for maior que 3 retornar os kit pra 3 (Evitar Bugs) setElementData(localPlayer, "Kit", 3) -- Seta Kit 3 No jogador end -- FIm end -- Fim
#DeltaSCR Posted March 19, 2019 Author Posted March 19, 2019 (edited) Uma dúvida, o debug acusa que na linha 145, é esperado '=' para o ')', eis a linha a seguir: local money = getPlayerMoney (localPlayer) if money =< 750 then Edited March 19, 2019 by #DeltaSCR
#DaNiLiN Posted March 19, 2019 Posted March 19, 2019 No caso seria if getPlayerMoney (source) <= 750 then o sinal de maior > menor < sempre vem na frente do sinal de igual =
Other Languages Moderators Lord Henry Posted March 19, 2019 Other Languages Moderators Posted March 19, 2019 Caso queira saber mais sobre operadores relacionais, leia na documentação LUA em português: http://www.lua.org/manual/5.1/pt/manual.html#2.5.2
#DeltaSCR Posted March 19, 2019 Author Posted March 19, 2019 6 hours ago, #DaNiLiN said: No caso seria if getPlayerMoney (source) <= 750 then o sinal de maior > menor < sempre vem na frente do sinal de igual = Mas source nao seria apenas para server-side?
Jonas^ Posted March 19, 2019 Posted March 19, 2019 Não, pois você não definiu nem um parametro pra função, então é source como padrão.
DNL291 Posted March 19, 2019 Posted March 19, 2019 Se for no lado cliente getPlayerMoney não recebe nenhum argumento, só lado server.
#DeltaSCR Posted March 19, 2019 Author Posted March 19, 2019 Estou obtendo pelo lado do Client, então sem argumentos né?
#DaNiLiN Posted March 19, 2019 Posted March 19, 2019 Pelo cliente if getPlayerMoney (localPlayer) <= 750 then 1
DNL291 Posted March 19, 2019 Posted March 19, 2019 Na verdade não precisa de localPlayer no cliente pra essa função. Isto já basta: if getPlayerMoney() <= 750 then Na própria wiki tem essa informação. 1
#DeltaSCR Posted March 19, 2019 Author Posted March 19, 2019 Na real não deu sucesso, tentei aqui e estou obtendo o restante do código sem ter dinheiro... function DeltaComprarPrata (button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if DeltaSCRPainel == true then if state == "down" then if isCursorOnElement (screenW * 0.3203, screenH * 0.2667, screenW * 0.3594, screenH * 0.4667) then if getPlayerMoney (localPlayer) <= 750 then verifyKits () DeltaSCRAbrir () outputChatBox ("Sucess") else outputChatBox ("notMoney") end end end end end addEventHandler ("onClientClick", getRootElement(), DeltaComprarPrata) function verifyKits () local Kits = tonumber(getElementData(localPlayer, "Kit")) or 0 if Kits < 3 then setElementData(localPlayer, "Kit", Kits +1) else setElementData(localPlayer, "Kit", 3) end end
DNL291 Posted March 19, 2019 Posted March 19, 2019 == Igual >= Maior ou igual <= Menor ou igual > Maior < Menor Acho que você quis verificar se é maior ou igual, e ali no código tá menor ou igual. 1
#DeltaSCR Posted March 20, 2019 Author Posted March 20, 2019 Agora em outra parte do código o debug está acusando o seguinte erro: Bad argument @ 'getPedOccupiedVehicle' [Expected ped at argument 1, got none] function DeltaSCRFix (localPlayer) if getPedOccupiedVehicle(localPlayer) == true then outputChatBox ("#C83200╔═════════════════════════════════════════════════╗", 255, 255, 255, true) outputChatBox ("#C83200ERRO: #FFFFFFVocê usou seu Kit de Reparo com Sucesso", 255, 255, 255, true) outputChatBox ("#C83200╚═════════════════════════════════════════════════╝", 255, 255, 255, true) else outputChatBox ("#C83200╔═════════════════════════════════════════════════╗", 255, 255, 255, true) outputChatBox ("#C83200ERRO: #FFFFFFVocê precisa estar em um veículo para usar o Seguro", 255, 255, 255, true) outputChatBox ("#C83200╚═════════════════════════════════════════════════╝", 255, 255, 255, true) end end addCommandHandler ("seguro", DeltaSCRFix)
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 Nunca se usa localPlayer como parâmetro de função. Ele é uma variável nativa do client.
#DeltaSCR Posted March 20, 2019 Author Posted March 20, 2019 1 minute ago, Lord Henry said: Nunca se usa localPlayer como parâmetro de função. Ele é uma variável nativa do client. Ok, tirei o localPlayer dos parametros, só que agora, mesmo eu estando eu um veículo, está executando o else, no caso a mensagem que eu preciso estar em um veiculo...
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 Tente assim: function DeltaSCRFix () if getPedOccupiedVehicle(localPlayer) then outputChatBox ("╔═════════════════════════════════════════════════╗", 200, 50, 0) outputChatBox ("ERRO: #FFFFFFVocê usou seu Kit de Reparo com Sucesso", 200, 50, 0, true) outputChatBox ("╚═════════════════════════════════════════════════╝", 200, 50, 0) else outputChatBox ("╔═════════════════════════════════════════════════╗", 200, 50, 0) outputChatBox ("ERRO: #FFFFFFVocê precisa estar em um veículo para usar o Seguro", 200, 50, 0, true) outputChatBox ("╚═════════════════════════════════════════════════╝", 200, 50, 0) end end addCommandHandler ("seguro", DeltaSCRFix) 1
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 (edited) 4 minutes ago, #DeltaSCR said: Ok, tirei o localPlayer dos parametros, só que agora, mesmo eu estando eu um veículo, está executando o else, no caso a mensagem que eu preciso estar em um veiculo... Nesse caso ele estava entrando no else pois getPedOccupiedVehicle não retorna true se existir um veículo, ele retorna o próprio veículo. Logo aquela primeira condição sempre seria false. Edited March 20, 2019 by Lord Henry
#DeltaSCR Posted March 20, 2019 Author Posted March 20, 2019 Só que tipo, como eu faria pra toda vez que o Jogador entrasse e saísse do Servidor, essa data fosse salva?
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 (edited) onPlayerLogin - Carrega os dados da conta dele com getAccountData. onPlayerLogout - Salva os dados na conta dele com setAccountData. Mas essas funções são server-side, vc precisará de triggers. Edited March 20, 2019 by Lord Henry
#DeltaSCR Posted March 20, 2019 Author Posted March 20, 2019 Agora o Debug Acusa: Spoiler Attempt to compare number with nil function DeltaSCRFix () if getPedOccupiedVehicle(localPlayer) then Kits = tonumber(getElementData(localPlayer, "Kit")) or 0 if Kits > 0 then setElementData(localPlayer, "Kit", Kits -1) outputChatBox ("╔═════════════════════════════════════════════════╗", 200, 50, 0) outputChatBox ("INFO: #FFFFFFVocê usou seu Kit de Reparo com Sucesso.", 200, 50, 0, true) outputChatBox ("INFO: #FFFFFFVocê agora tem mais "..Kits.." usos.", 200, 50, 0, true) outputChatBox ("╚═════════════════════════════════════════════════╝", 200, 50, 0) end end end addCommandHandler ("seguro", DeltaSCRFix)
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 Na linha 4?
#DeltaSCR Posted March 20, 2019 Author Posted March 20, 2019 Just now, Lord Henry said: Na linha 4? Sim
Other Languages Moderators Lord Henry Posted March 20, 2019 Other Languages Moderators Posted March 20, 2019 Bem estranho... Era pra Kits ser igual a 0 em caso de falha do tonumber...
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