Ryuto Posted January 15, 2024 Share Posted January 15, 2024 Olá, estou tentando criar um script onde você possa perseguir um jogador com uma determinada animação. Há um tempo consegui recriar o sistema mas tive dois problemas... A primeira é que adiciono uma animação ao código do script, mas quando o link é reproduzido, o personagem aparece completamente estático, sem qualquer animação. E a segunda é que quando utilizo o bind em altura, o personagem vai para a posição do oponente mas enquanto está em altura e não para a posição no chão. Deixo aqui um vídeo dos erros mencionados para que seja mais fácil entendê-los. Aqui deixo um vídeo do meu problema. e este é o código do meu script local playerSelectedTarget local alpha = 255 local isChasing = false local chaseDuration = 10000 addEventHandler("onClientKey", root, function(key, state) if state and key == "1" and isElement(playerSelectedTarget) then startChasingPlayer() end end ) function startChasingPlayer() if not isChasing then isChasing = true setElementData(localPlayer, "Select", false) setPedAnimation(localPlayer, "ped", "run_player", -1, true, false, false) -- Change "run_player" to the animation name you want !!!!! setTimer(stopChasingPlayer, chaseDuration, 1) end end function stopChasingPlayer() isChasing = false setPedAnimation(localPlayer) end addEventHandler("onClientRender", root, function() if (getKeyState("mouse2") == true) then local x, y, z = getElementPosition(localPlayer) for k, target in ipairs(getElementsByType("player", root, true)) do if not (target == localPlayer) then local px, py, pz = getElementPosition(target) local distance = getDistanceBetweenPoints3D(px, py, pz, x, y, z) if playerSelectedTarget ~= localPlayer and (distance < 30) then playerSelectedTarget = target alpha = 255 setElementData(localPlayer, "Select", true) end end end if isElement(playerSelectedTarget) then local Px, Py, Pz = getCameraMatrix() local zhx, zhy, zhz = getPedBonePosition(playerSelectedTarget, 3) local dist = getDistanceBetweenPoints3D(Px, Py, Pz, zhx, zhy, zhz) if playerSelectedTarget ~= localPlayer and (dist < 30) then if (isLineOfSightClear(Px, Py, Pz, zhx, zhy, zhz, true, true, false, false, true, false, false, playerSelectedTarget)) then local sxx, syy = getScreenFromWorldPosition(zhx, zhy, zhz + 0.3) if sxx and syy then local size = 1300 / dist dxDrawImage(sxx - (size / 2), syy - (size / 4.5), size, size, "Effect/Select.webp", 0, 0, 0, tocolor(255, 255, 255, alpha), false) end end end end else if isElement(playerSelectedTarget) then alpha = 0 setElementData(localPlayer, "Select", false) end end if isChasing and isElement(playerSelectedTarget) then local px, py, pz = getElementPosition(localPlayer) local targetX, targetY, targetZ = getElementPosition(playerSelectedTarget) local angle = math.atan2(targetY - py, targetX - px) local speed = 0.1 local newX = px + math.cos(angle) * speed local newY = py + math.sin(angle) * speed setElementPosition(localPlayer, newX, newY, pz) end end ) Link to comment
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