Jump to content

o que há de errado?


Recommended Posts

Posted

Alguém pode me dizer oq há de errado com esse script?  WARNING: [Mods]GlueX\glues.lua:2: Bad argument @ 'attachElements' [Expected at argument 2]

function gluePlayer(slot, vehicle, x, y, z, rotX, rotY, rotZ)
    attachElements(source, vehicle, x, y, z, rotX, rotY, rotZ)
    setPedWeaponSlot(source, slot)
end
addEvent("gluePlayer",true)
addEventHandler("gluePlayer",getRootElement(),gluePlayer)

function ungluePlayer()
    detachElements(source)
end
addEvent("ungluePlayer",true)
addEventHandler("ungluePlayer",getRootElement(),ungluePlayer)

 

Posted

Tem um problema com o parâmetro da função, 'vehicle' não está retornando um elemento.

  • Thanks 1

Please do not PM me with scripting related question nor support, use the forums instead.

  • Moderators
Posted

Colocando um verificador antes.

if getElementType (vehicle) == "vehicle" then

 

  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

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.

Posted

Estou com outro problema nesse mesmo Mod, tentei procurar alguma função pra isso porém não achei, é o seguinte. Esse mod ele é aquele mod de Glue X que encontra por ai na internet, após o player apertar a letra X ele ficará grudado em cima do veículo. Porém recentemente descobri um bug nele, no qual a pessoa aperta a letra X pra grudar e depois cria um veículo pelo painel, como o veículo é spawnado junto com o player, acaba que mesmo depois de spawnado o veículo, ele continua no local que grudou com o X. Aqui está um vídeo sobre como funciona isso: https://www.youtube.com/watch?v=Ubnrwa8nmh4 , se alguém poder me ajudar a solucionar isso de alguma forma, agradeço.

Código:

 

--client-side

function glue()
    local player = getLocalPlayer()
    if not getPedOccupiedVehicle(player) then
        local vehicle = getPedContactElement(player)
        if vehicle then
        if getElementType(vehicle) == "vehicle" then
            
            local px, py, pz = getElementPosition(player)
            local vx, vy, vz = getElementPosition(vehicle)
            local sx = px - vx
            local sy = py - vy
            local sz = pz - vz
            
            local rotpX = 0
            local rotpY = 0
            local rotpZ = getPedRotation(player)
            
            local rotvX,rotvY,rotvZ = getElementRotation(vehicle)
            
            local t = math.rad(rotvX)
            local p = math.rad(rotvY)
            local f = math.rad(rotvZ)
            
            local ct = math.cos(t)
            local st = math.sin(t)
            local cp = math.cos(p)
            local sp = math.sin(p)
            local cf = math.cos(f)
            local sf = math.sin(f)
            
            local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy
            local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy
            local y = st*sz - sf*ct*sx + cf*ct*sy
            
            local rotX = rotpX - rotvX
            local rotY = rotpY - rotvY
            local rotZ = rotpZ - rotvZ
            
            local slot = getPedWeaponSlot(player)
            
            triggerServerEvent("gluePlayer", player, slot, vehicle, x, y, z, rotX, rotY, rotZ)
            
            unbindKey("x","down",glue)
            bindKey("x","down",unglue)
            bindKey("jump","down",unglue)
            end
        end
    end
end

addCommandHandler("glue",glue)

function unglue ()
    local player = getLocalPlayer()
    triggerServerEvent("ungluePlayer", player)
    unbindKey("jump","down",unglue)
    unbindKey("x","down",unglue)
    bindKey("x","down",glue)
end

addCommandHandler("unglue",unglue)

bindKey("x","down",glue)




--server-side
function gluePlayer(slot, vehicle, x, y, z, rotX, rotY, rotZ)
    if getElementType (vehicle) == "vehicle" then
	attachElements(source, vehicle, x, y, z, rotX, rotY, rotZ)
	setPedWeaponSlot(source, slot)
end
end
addEvent("gluePlayer",true)
addEventHandler("gluePlayer",getRootElement(),gluePlayer)

function ungluePlayer()
	detachElements(source)
end
addEvent("ungluePlayer",true)
addEventHandler("ungluePlayer",getRootElement(),ungluePlayer)

 

 

  • Moderators
Posted

Adicione isso ao resource de grudar, no script server-side:

addEventHandler ("onVehicleEnter", getRootElement(), function (thePlayer)
	local attach = getElementAttachedTo (thePlayer) -- attach = elemento que o jogador está grudado. Será false se não estiver grudado em algo.
	if attach then -- Se o jogador está grudado em algo, então:
		outputChatBox ("Não é possível entrar em um veículo enquanto está grudado em algo!", thePlayer, 255, 150, 0) -- Manda isso pra ele.
		removePedFromVehicle (thePlayer) -- Remove o Ped do veículo que ele acabou de entrar.
	end
end)

 

E no script client-side, ali na linha 8.

Substitua isso:

if getElementType(vehicle) == "vehicle" then

Por isso:

if vehicle and getElementType(vehicle) == "vehicle" then

Isso fará com que não gere mais erro ao tentar grudar em nada.

  • Thanks 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.png

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.

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...