Jump to content

Recommended Posts

Galera to fazendo um sistema de painel q vc digita no painel tipo

255, 0, 0 dentro de um carro e seta a cor vermelha no carro q e do rgb 255, 0, 0 e etc.

mas da forma que achei que era possivel ao abrir o painel e digitar a cor em rgb eu fiz uma função que na teoria era pra pegar oq foi digitado na editbox e setar oq foi digitado na editbox como cor do carro usando setVehicleColor so q n aparece nada e n seta cor no carro mais se o carro ta vermelho e coloca tipo 255, 0, 0 na editbox e da ok a cor sempre muda pra preto espero q de para entender

function SetarCor (playerSource, getMsg)
    --local mensagem = tonumber(getMsg)
    local uVehicle = getPedOccupiedVehicle( playerSource )

             
                if isPedInVehicle( playerSource ) then
            if uVehicle then
            --    if mensagem == "Vermelho" then
                setVehicleColor( uVehicle, tonumber(getMsg))
             end
         end
     --end
     end
addEvent("SetarCor", true)
addEventHandler("SetarCor", getRootElement(), SetarCor)

PARTE DO CLIENT


function rgbtrigger (button, state)
    if painel == true then
        if button == "left" and state == "down" then
            if isCursorOnElement(screenW * 0.6384, screenH * 0.5885, screenW * 0.7379, screenH * 0.6185) then
                local getMsg = tostring(getElementData(msgstaff, "CMT_Txt"))
                removeEventHandler("onClientRender", root, dx)
                triggerServerEvent("SetarCor", getLocalPlayer(), localPlayer, getMsg)
                painel = false
                showCursor(false)
            end
        end
    end
end
addEventHandler("onClientClick", root, rgbtrigger)

 

Link to comment
  • Scripting Moderators

Moving this to the Portuguese scripting section so you can get better results in your native language. If you'd like to receive help in the international scripting section, make sure to always post your topics in English.

Link to comment
  • Other Languages Moderators

@DaddyMTAvocê não pode converter um texto único em 3 números usando apenas o tonumber. Se o texto possuir algum símbolo entre os números, dará erro.

Você pode fazer de 2 formas:

  1. Mais recomendada: criar 3 editboxes. Um para a cor Red, outro pra cor Green e outro pra cor Blue. E depois use tonumber em cada valor.
    1. Opcional: Limite o número de caracteres deles em no máximo 3. Bloqueie qualquer caractere que não seja número de ser digitado nos campos. Considere campos vazios como 0. Evitando erros.
  2. Mais fácil: pegue o texto digitado nos campos e separe-o em 3 sub-textos usando a função split. Para isso ser possível, é necessário que o texto tenha algum caractere separando os valores, por exemplo uma vírgula. Então é só dar tonumber em cada uma delas.
    1. Opcional: Verifique sempre se o split retornou 3 valores. Se só encontrar 2 strings, considere o terceiro como 0. Se encontrar só 1 string, considere o segundo e terceiro como 0.
Edited by Lord Henry
Link to comment

Não sei se esta correto coloquei assim para testar dai coloquei um print para ver o valor que retorna no debugscript e retornal nil quando eu coloco na editbox 255, 0, 0 ou 255 0 0

function SetarCor (playerSource, getMsg)
	local uVehicle = getPedOccupiedVehicle( playerSource )
 			
				if isPedInVehicle( playerSource ) then
			if uVehicle then
			local teste = split(getMsg, ',')
				setVehicleColor(uVehicle, teste)

							print(tonumber(teste))
 			end
 		end
 	end
addEvent("SetarCor", true)
addEventHandler("SetarCor", getRootElement(), SetarCor)

 

Link to comment
  • Other Languages Moderators

Desculpe, esqueci de mencionar que a função split retorna uma tabela em vez dos valores separados. Dai você precisa acessar os valores da tabela pelos índices.

function SetarCor (playerSource, getMsg)
    local uVehicle = getPedOccupiedVehicle (playerSource)
    if (uVehicle) then
        local cores = split (getMsg, ',')
        local r = cores[1] or 0
        local g = cores[2] or 0
        local b = cores[3] or 0
        setVehicleColor (uVehicle, r, g, b)
        iprint (r, g, b)
    end
end
addEvent ("SetarCor", true)
addEventHandler ("SetarCor", root, SetarCor)

 

  • Like 1
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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