Как сделать так чтобы можно было тянуть игроков за собой при нажатии по ниму E и чтобы он был в наручниках
ply:GetNWBool( "BES_CUFFED", true )
функция когда на игроке надеты наручники
dsr_handcuffs
Свеп наручников
hook.Add("KeyPress", "HandcuffDrag", function(ply, key)
if key == IN_USE then
if ply:GetNWBool("BES_CUFFED", true) then
ply:SetMoveType(MOVETYPE_WALK)
ply:SetLocalVelocity(Vector(0, 0, 0))
ply:Give("dsr_handcuffs")
ply:SelectWeapon("dsr_handcuffs")
ply:GetActiveWeapon():SetNWBool("cuffed", true)
else
ply:SetMoveType(MOVETYPE_OBSERVER)
end
end
end)
hook.Add("PlayerDeath", "HandcuffRelease", function(ply)
ply:StripWeapon("dsr_handcuffs")
ply:SetMoveType(MOVETYPE_WALK)
end)
Не проверял,если работает радуйся)
я уже вижу и понимаю что работать как я написал оно не будит мне нужна именно функция которая будит тащить игрока за тем кто нажал по человеку который в наручниках на E а не если человек в наручниках нажимает на е выдавали наручники и другое что присутствует в данном скрипте
Не проверял, но можешь попробовать. Думаю основная логика понятна, настройки сверху.
local CONST_KEY = KEY_E
local CONST_HANDCUFFS = "dsr_handcuffs"
local CONST_DISTANCE = 100
local distanceSquared = CONST_DISTANCE * CONST_DISTANCE
local dragingPlayers = {}
hook.Add( "PlayerButtonDown", "DragPlayersButton", function( ply, button )
if CLIENT then return end
if button ~= CONST_KEY then return end
local target = ply:GetEyeTrace().Entity
if not IsValid(target) or not target:IsPlayer() or target:GetActiveWeapon():GetClass() ~= CONST_HANDCUFFS or not target:GetNWBool( "BES_CUFFED", true ) then return end
if target:GetPos():DistToSqr(ply:GetPos()) > distanceSquared then return end
if dragingPlayers[target] and dragingPlayers[target] == ply then
dragingPlayers[target] = nil
target:SetMoveType(MOVETYPE_WALK)
return
end
dragingPlayers[target] = ply
target:SetMoveType(MOVETYPE_NONE)
end)
hook.Add("Think", "DragPlayersThink", function()
for target, ply in pairs(dragingPlayers) do
if not IsValid(target) or not IsValid(ply) or not target:GetNWBool( "BES_CUFFED", true ) then
dragingPlayers[target] = nil
continue
end
if target:GetPos():DistToSqr(ply:GetPos()) > distanceSquared then
dragingPlayers[target] = nil
target:SetMoveType(MOVETYPE_WALK)
continue
end
local plyPos = ply:GetPos()
local targetAng = target:GetAngles()
local plyAng = ply:GetAngles()
target:SetPos(plyPos)
target:SetAngles(Angle(targetAng.x, plyAng.y, targetAng.z))
end
end)
всё работает спасибо
А как ещё сделать чтобы он именно привязан к камере того человека который ведёт его а именно чтобы он был в отдалении на 30 координат в том направлении в которое смотрит человек которого тот ведёт
Немного не понял вопроса. Просто предположу что тебе нужно вот такое решение:
local CONST_KEY = KEY_E
local CONST_HANDCUFFS = "dsr_handcuffs"
local CONST_DISTANCE = 100
local CONST_SPEED_OF_CHANGE = 0.5
local distanceSquared = CONST_DISTANCE * CONST_DISTANCE
local dragingPlayers = {}
hook.Add( "PlayerButtonDown", "DragPlayersButton", function( ply, button )
if CLIENT then return end
if button ~= CONST_KEY then return end
local target = ply:GetEyeTrace().Entity
if not IsValid(target) or not target:IsPlayer() or target:GetActiveWeapon():GetClass() ~= CONST_HANDCUFFS or not target:GetNWBool( "BES_CUFFED", true ) then return end
if target:GetPos():DistToSqr(ply:GetPos()) > distanceSquared then return end
if dragingPlayers[target] and dragingPlayers[target] == ply then
dragingPlayers[target] = nil
target:SetMoveType(MOVETYPE_WALK)
return
end
dragingPlayers[target] = ply
target:SetMoveType(MOVETYPE_NONE)
end)
hook.Add("Think", "DragPlayersThink", function()
for target, ply in pairs(dragingPlayers) do
if not IsValid(target) or not IsValid(ply) or not target:GetNWBool( "BES_CUFFED", true ) then
dragingPlayers[target] = nil
continue
end
local targetPos = target:GetPos()
local plyPos = ply:GetPos()
if targetPos:DistToSqr(plyPos) > distanceSquared then
dragingPlayers[target] = nil
target:SetMoveType(MOVETYPE_WALK)
continue
end
if targetPos:DistToSqr(plyPos) <= CONST_DISTANCE then
return
end
local newPosX = math.Approach(targetPos.x, plyPos.x, CONST_SPEED_OF_CHANGE)
local newPosY = math.Approach(targetPos.y, plyPos.y, CONST_SPEED_OF_CHANGE)
local newPosZ = math.Approach(targetPos.z, plyPos.z, CONST_SPEED_OF_CHANGE)
local targetAng = target:GetAngles()
local plyAng = ply:GetAngles()
target:SetPos(Vector(newPosX, newPosY, newPosZ))
target:SetAngles(Angle(targetAng.x, plyAng.y, targetAng.z))
end
end)
Можешь поиграть со значением CONST_SPEED_OF_CHANGE
что бы был желаемый результат.