Jump to content

Ajuda para finalizar mod barbearia


Recommended Posts

Posted

Estou fazendo um mod de barbearia, tudo está funcionando, mas precisa dos ajustes finais, não sei como fazer para cobrar o corte, funcionamento atual do mod:

O jogador só consegue entrar se estiver com a skin do CJ, caso contrário recebe uma mensagem informando o mesmo. Ao entrar na barbearia o painel já fica disponivel segue a imagem:

Spoiler

TTddI8Q.png

Ao clicar nas setas ele pode alternar entre os cortes, mas quando ele sai do estabelecimento, ele permanece com o corte e o painel obviamente some.

O que eu preciso é dar utilidade para a tesoura, no caso ela seria quem iria confirmar o corte e cobrar, mas não sei bem como fazer isso, vou mostrar o código atual e o que eu penso em fazer, aceito criticas e sugestões.

Client-Side:

local screenW, screenH = guiGetScreenSize()

function draw()
    dxDrawImage((screenW - 400) / 2, (screenH - 200) / 2, 100, 100, "img/arrow.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)       -- Button Left
    dxDrawImage((screenW + 200) / 2, (screenH - 200) / 2, 100, 100, "img/arrow.png", 180, 0, 0, tocolor(255, 255, 255, 255), false)     -- Button Right
    dxDrawImage((screenW - 100) / 2, (screenH + 200) / 2, 100, 100, "img/scissors.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)    -- Button Confim
end

-- ignore essa função
function isCursorOnElement( posX, posY, width, height )
	if isCursorShowing( ) then
		local mouseX, mouseY = getCursorPosition( )
		local clientW, clientH = guiGetScreenSize( )
		local mouseX, mouseY = mouseX * clientW, mouseY * clientH
		if ( mouseX > posX and mouseX < ( posX + width ) and mouseY > posY and mouseY < ( posY + height ) ) then
			return true
		end
	end
	return false
end


function barbershop(status)
    if not type(status) == "boolean" then
        return false
    end
    
    if status then
    	-- timer para esperar a animação de fade que acontece com a camera
        setTimer ( function()
            addEventHandler("onClientRender", root, draw)
        end, 700, 1 )
        
        addEventHandler ( "onClientClick", getRootElement(), function(_,state)
            if state == "down" then
                if isCursorOnElement((screenW - 400) / 2, (screenH - 200) / 2, 80, 80) then
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "left" )
                elseif isCursorOnElement((screenW + 200) / 2, (screenH - 200) / 2, 80, 80) then
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "right" )
                elseif isCursorOnElement((screenW - 100) / 2, (screenH + 200) / 2, 80, 80) then
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "confirm" )
                end
            end
        end)
    elseif status == false then
        removeEventHandler("onClientRender", root, draw)
    end
end
addEvent( "showPanel", true )
addEventHandler( "showPanel", localPlayer, barbershop)

Server-side: 

-- Posição dos markers
markers = {
    [1] = {createMarker(2070.85, -1793.88147, 13.54688-0.92, "cylinder", 1, 0, 200, 200, 160)}, -- Entrada Reece's Barbershop
    [2] = {createMarker(411.59732, -23, 1001.80469-0.90, "cylinder", 1, 0, 200,200,0)}, -- Saida Reece's Barbershop
}
setElementInterior(markers[2][1], 2) -- Seta o interior do marker de saída
createBlipAttachedTo(markers[1][1], 7) -- Blip na entrada Reece's Barbershop.

-- Transição do mundo para o interior
function teleportPlayer(playerSource, int, x, y , z, r)
    fadeCamera(playerSource, false, 0.5)
    setTimer(fadeCamera, 500, 1, playerSource, true, 1)
    setCameraTarget( playerSource, playerSource )
    setTimer(setElementInterior, 500, 1, playerSource, int, x, y , z)
    setTimer(setElementRotation, 500, 1, playerSource, 0, 0, r)
end

-- Quando o jogador entra no marker
function hitarMarker(marker, dim)
    if dim and not isPedInVehicle(source) then
        if getElementModel(source) ~= 0 then outputChatBox("#ff3b3b[ERRO] #ffffffCorte somente para a skin do CJ", source, 255, 255, 255, true) return end
        if marker == markers[1][1] then -- Se for o marker de entrada
            outputChatBox("Bem-vindo ao Reece's Barbershop", source, 127,255,212, true)
            teleportPlayer(source, 2, 411.61981, -22.34467, 1001.80469 , 0)  
            triggerClientEvent(source, "showPanel", source, true)
        elseif marker == markers[2][1] then -- Se for o marker de saída.
            teleportPlayer(source, 0, 2071.88013, -1793.78210, 13.54688, -90)
            triggerClientEvent(source, "showPanel", source, false)
        end
    end
end
addEventHandler("onPlayerMarkerHit", getRootElement(), hitarMarker)

haircuts = {
        -- Textura, Modelo
    [1] = {"player_face", "head"},
    [2] = {"hairblond", "head"},
    [3] = {"hairred", "head"},
    [4] = {"hairblue", "head"},
    [5] = {"hairgreen", "head"},
    [6] = {"hairpink", "head"},
    [7] = {"bald", "head"},
    [8] = {"baldbeard", "head"},
    [9] = {"baldtash", "head"},
    [10] = {"baldgoatee", "head"},
    [11] = {"highfade", "head"},
}

local valorAtual = 1 -- Tem algum problema ficar aqui?? Se outros player forem cortar o cabelo qual vai ser o valor?? 
function haircut (playerSource, status)
    
    if status == "left" then
        valorAtual = valorAtual - 1
    	if valorAtual == 0 then valorAtual = #haircuts end
        addPedClothes(playerSource, haircuts[valorAtual][1], "head", 1)
    end
    if status == "right" then
        valorAtual = valorAtual + 1
    	if valorAtual >= #haircuts then valorAtual = 1 end
        addPedClothes(playerSource, haircuts[valorAtual][1], "head", 1)
    end
end
addEvent( "haircut", true )
addEventHandler( "haircut", resourceRoot, haircut )

A primeira dúvida é a váriavel valorAtual ela está fora da função haircut e é serverside, se um jogador alterar o valor dela, vai alterar o valor da váriavel (valorAtual) de todos?

Como estou pensando em fazer para cobrar o jogador, criar uma váriavel paid, quando o jogador entrar no marker de entrada, salvar o corte atual dele, e quando ele sair verificar se paid é == true se for mantem o corte se não volta para o que foi salvo quando ele entrou, seria isso? Alguma sugestão?

 

 

Posted
1 hour ago, Gaimo said:

A primeira dúvida é a váriavel valorAtual ela está fora da função haircut e é serverside, se um jogador alterar o valor dela, vai alterar o valor da váriavel (valorAtual) de todos?

Como estou pensando em fazer para cobrar o jogador, criar uma váriavel paid, quando o jogador entrar no marker de entrada, salvar o corte atual dele, e quando ele sair verificar se paid é == true se for mantem o corte se não volta para o que foi salvo quando ele entrou, seria isso? Alguma sugestão?

1. Sim, faça no lado cliente, mantenha server side apenas o addPedClothes, getPlayerMoney e takePlayerMoney

2. Acho ok... mas seria bom ao menos informar o valor do corte ao jogador. E deve-se também atualizar o "corte atual" após cada compra com sucesso.

  • Thanks 1
Posted

Estou com um problema, quando o jogador sai e entra meio que dobra a função, estou suspeitando que é o evento onClientClick acho que ele está sendo criado infinitamente, vou mostrar os script e descrever melhor o problema.

 

Quando o jogador entra no marker abre o painel, ele clica para escolher algum lado, esquerda ou direita, troca o corte e exibe no outputchatbox o valor da variavel valorAtual, que tem como utilidade selecionar o corte na table haircuts, ele sai do estabelecimento e retorna, quando ele aperta para algum dos lados sai 2 outputchatbox e assim vai aumentado conforme ele vai saindo e entrando, exemplo:

Entrou uma vez

valorAtual = 1

Entrou pela segunda vez

valorAtual = 1

valorAtual = 2

Ele repete o valorAtual da anterior e cria um novo, se ele deixou no corte 8 e entrou novamente vai aparecer o 8 e o 1

valorAtual = 8

valorAtual = 1 ( esse eh o que eh aplicado) mas da uns bug depois de entrar umas 4 vzs ou mais pq ele troca varias vezes mt rapido de corte.

 

Minha suspeita esta no client-side esta marcado para facilitar.

 

Server-side:

-- Posição dos markers
markers = {
    [1] = {createMarker(2070.85, -1793.88147, 13.54688-0.92, "cylinder", 1, 0, 200, 200, 160)}, -- Entrada Reece's Barbershop
    [2] = {createMarker(411.59732, -23, 1001.80469-0.90, "cylinder", 1, 0, 200,200,0)}, -- Saida Reece's Barbershop
}
setElementInterior(markers[2][1], 2) -- Seta o interior do marker de saída
createBlipAttachedTo(markers[1][1], 7) -- Blip na entrada Reece's Barbershop.

-- Transição do mundo para o interior
function teleportPlayer(playerSource, int, x, y , z, r)
    fadeCamera(playerSource, false, 0.5)
    setTimer(fadeCamera, 500, 1, playerSource, true, 1)
    setCameraTarget( playerSource, playerSource )
    setTimer(setElementInterior, 500, 1, playerSource, int, x, y , z)
    setTimer(setElementRotation, 500, 1, playerSource, 0, 0, r)
end

-- Salva o corte de cabelo do player na conta.
function saveCut (playerSource, model, texture)
    account = getPlayerAccount(playerSource)
    setAccountData(account, "1_model", model)
    setAccountData(account, "1_texture", texture)
end

-- Quando o jogador entra no marker
function hitarMarker(marker, dim)
    if dim and not isPedInVehicle(source) then
        if getElementModel(source) ~= 0 then outputChatBox("#ff3b3b[ERRO] #ffffffCorte somente para a skin do CJ", source, 255, 255, 255, true) return end

        if marker == markers[1][1] then -- Se for o marker de entrada
            local model, texture = getPedClothes(source, 1) -- Pega o corte atual do player quando entrou no marker
            saveCut(source, model, texture) -- Salva o corte que o jogador entrou
            outputChatBox("Bem-vindo ao Reece's Barbershop", source, 127,255,212, true) -- Envia a mensagem
            teleportPlayer(source, 2, 411.61981, -22.34467, 1001.80469 , 0)  -- Teleporta o jogador.
            triggerClientEvent(source, "showPanel", source, true) -- Abre o painel.
        elseif marker == markers[2][1] then -- Se for o marker de saída.
            account = getPlayerAccount(source) -- Pega a conta do jogador
            local model = getAccountData(account, "1_model")
            local texture = getAccountData(account, "1_texture")
            addPedClothes(source, model, texture, 1) -- Era pra adicionar o corte que está salvo na conta do player.
            teleportPlayer(source, 0, 2071.88013, -1793.78210, 13.54688, -90)
            triggerClientEvent(source, "showPanel", source, false)
        end
    end
end
addEventHandler("onPlayerMarkerHit", getRootElement(), hitarMarker)

haircuts = {
        -- Textura, Modelo
    [1] = {"player_face", "head"},
    [2] = {"hairblond", "head"},
    [3] = {"hairred", "head"},
    [4] = {"hairblue", "head"},
    [5] = {"hairgreen", "head"},
    [6] = {"hairpink", "head"},
    [7] = {"bald", "head"},
    [8] = {"baldbeard", "head"},
    [9] = {"baldtash", "head"},
    [10] = {"baldgoatee", "head"},
    [11] = {"highfade", "head"},
}

function haircut (playerSource, status, valorAtual)

    if status == "left" then	
        outputChatBox("valorAtualL = "..valorAtual)
        addPedClothes(playerSource, haircuts[valorAtual][1], "head", 1)
    end
    if status == "right" then
        outputChatBox("valorAtualR = "..valorAtual)
        addPedClothes(playerSource, haircuts[valorAtual][1], "head", 1)
    end
    if status == "confirm" then
        local model, texture getPedClothes(playerSource, 1)
        if getPlayerMoney(playerSource) >= 25 then
            takePlayerMoney(playerSource, 25)
            saveCut(playerSource, model, texture)
            outputChatBox("Compra realizada com sucesso.")
        else
            outputChatBox("[ERRO] Você não tem dinheiro suficiente!" )
        end
    end
end
addEvent( "haircut", true )
addEventHandler( "haircut", resourceRoot, haircut )

Client-side:

local screenW, screenH = guiGetScreenSize()
local valorAtual = 1

function draw()
    dxDrawImage((screenW - 400) / 2, (screenH - 200) / 2, 100, 100, "img/arrow.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)       -- Button Left
    dxDrawImage((screenW + 200) / 2, (screenH - 200) / 2, 100, 100, "img/arrow.png", 180, 0, 0, tocolor(255, 255, 255, 255), false)     -- Button Right
    dxDrawImage((screenW - 100) / 2, (screenH + 200) / 2, 100, 100, "img/scissors.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)    -- Button Confim
    dxDrawText("Custo: R$ 25,00", (screenW - 200) / 2, (screenH + 230) / 2, ((screenW - 200) / 2) + 200, ( (screenH - 40) / 2) + 40, tocolor(45, 199, 29, 255), 1.00, "pricedown", "center", "center", false, false, false, false, false)
end

function isCursorOnElement( posX, posY, width, height )
	if isCursorShowing( ) then
		local mouseX, mouseY = getCursorPosition( )
		local clientW, clientH = guiGetScreenSize( )
		local mouseX, mouseY = mouseX * clientW, mouseY * clientH
		if ( mouseX > posX and mouseX < ( posX + width ) and mouseY > posY and mouseY < ( posY + height ) ) then
			return true
		end
	end
	return false
end

function barbershop(status)
    if not type(status) == "boolean" then
        return false
    end
    
    if status then
        local sizeTable = 11
        setTimer ( function()
            addEventHandler("onClientRender", root, draw)
        end, 1000, 1 )
        -- ESTOU SUSPEITANDO DISSO AQUI -----------------------------------------
        addEventHandler ( "onClientClick", getRootElement(), function(_,state)
            if state == "down" then
                if isCursorOnElement((screenW - 400) / 2, (screenH - 200) / 2, 80, 80) then
                    valorAtual = valorAtual - 1
                    if valorAtual <= 0 then valorAtual = sizeTable end
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "left", valorAtual)
                elseif isCursorOnElement((screenW + 200) / 2, (screenH - 200) / 2, 80, 80) then
                    valorAtual = valorAtual + 1
                    if valorAtual >= sizeTable then valorAtual = 1 end
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "right", valorAtual)
                elseif isCursorOnElement((screenW - 100) / 2, (screenH + 200) / 2, 80, 80) then
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "confirm" )
                end
            end
        end)
    --------------------------------------------------------------------------------------------------------
    elseif status == false then
        removeEventHandler("onClientRender", root, draw)
    end
end
addEvent( "showPanel", true )
addEventHandler( "showPanel", localPlayer, barbershop)

 

Posted

@Gaimo bom isto acontece porque a sua variável valorAtual não reseta.

 Onde esta status == false após o then coloque  "valorAtual = 1", que assim sempre que o painel for fechado ira atribuir-se o valor 1 a esta variável.

Posted

Esse não é o problema, o que acontece é que ele repete a função várias vezes conforme entra e sai, exemplo:

Tem um outputchatbox, que informa em qual corte ele está, quando ele sai e entra em vez de aparecer apenas um está saindo dois, e assim vai repetindo quantas vezes ele sai e entra, se ele entrar e sair 10 vezes, vai trocar de cabelo bem rápido 10 vezes e vai sair 10 outputchatbox, sendo que era pra sair apenas um e trocar uma vez de cabelo.

Testei o que você disse mas não funcionou.

Encontrei o problema, era onde eu estava suspeitando, transformei em uma função e adicionei um removeEventHandler, estava criando um novo sempre que o player entrava.

 

function panel(_,state)
            if state == "down" then
                if isCursorOnElement((screenW - 400) / 2, (screenH - 200) / 2, 80, 80) then
                    valorAtual = valorAtual - 1
                    if valorAtual <= 0 then valorAtual = sizeTable end
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "left", valorAtual)
                elseif isCursorOnElement((screenW + 200) / 2, (screenH - 200) / 2, 80, 80) then
                    valorAtual = valorAtual + 1
                    if valorAtual >= sizeTable then valorAtual = 1 end
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "right", valorAtual)
                elseif isCursorOnElement((screenW - 100) / 2, (screenH + 200) / 2, 80, 80) then
                    triggerServerEvent ( "haircut", resourceRoot, localPlayer, "confirm" )
                end
            end
        end
        addEventHandler ( "onClientClick", getRootElement(), panel)

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...