Player Follow script [lua]

Posts 1–7 of 7 · Page 1 of 1
Player Follow script [lua]
Just a script to follow the closest player

pretty cool for trolling in darkrp

Code:
local should_follow = CreateClientConVar( "follow", "0")
local should_draw = CreateClientConVar( "follow_draw", "1")
local follow_team = CreateClientConVar( "follow_team", "0", true, false, "0 follow any team, 1 follow same team as localplayer, 2 follow opposite team as localplayer")


function is_movement_keys_down()
	return input.IsButtonDown( 33 ) or input.IsButtonDown( 65 ) or input.IsButtonDown( 11 ) or input.IsButtonDown( 29 ) or input.IsButtonDown( 14 )
end


function moveToPos(cmd, pos)
	local world_forward = pos - LocalPlayer():GetPos()
	local ang_LocalPlayer = cmd:GetViewAngles()

	cmd:SetForwardMove( ( (math.sin(math.rad(ang_LocalPlayer[2]) ) * world_forward[2]) + (math.cos(math.rad(ang_LocalPlayer[2]) ) * world_forward[1]) ) * 300 )
	cmd:SetSideMove( ( (math.cos(math.rad(ang_LocalPlayer[2]) ) * -world_forward[2]) + (math.sin(math.rad(ang_LocalPlayer[2]) ) * world_forward[1]) ) * 300 )
end


function closest_player(team)
	best = 99999999
	current_e = nil
	for k, v in pairs(player.GetAll()) do
		dist = v:GetPos():Distance(LocalPlayer():GetPos())
		if LocalPlayer():Alive() and v:Alive() and v ~= LocalPlayer() and dist < best and v:Health() > 0 and v:GetObserverMode() == 0 then
			if team == nil then
				best = dist
				current_e = v
			elseif not team and LocalPlayer():Team() ~= v:Team() then
				best = dist
				current_e = v
			elseif team and LocalPlayer():Team() == v:Team() then
				best = dist
				current_e = v
			end
		end
	end
	return current_e
end

local target = nil
hook.Add("CreateMove", "PlayerFollow", function(cmd)
	if should_follow:GetInt() == 1 then
		if is_movement_keys_down() then return end
		
		if follow_team:GetInt() == 0 then
			target = closest_player()
		elseif follow_team:GetInt() == 1 then
			target = closest_player(true)
		elseif follow_team:GetInt() == 2 then
			target = closest_player(false)
		end
		
		if not target then return end
		moveToPos(cmd, target:GetPos())
	end
end)

hook.Add("HUDPaint", "PlayerFollow_Draw", function()
	if should_follow:GetInt() == 1 and should_draw:GetInt() == 1 then
		local pos = target:GetPos():ToScreen()
		surface.DrawCircle( pos["x"], pos["y"], 7, 0, 255, 0)
	end
end)
https://streamable.com/i04ie

console commands
Code:
follow - 0 is off, 1 is on
follow_draw,  0 is off, 1 is on
follow_team, 0 follow any and all teams, 1 follow same team as localplayer, 2 follow opposite team as localplayer
//approved
Quite interesting little script but why not just make simple blockbot instead ?

Many people will just run behind a prop at which point you will get stuck with this since there's no actual pathfinding or obstacle avodation in the code.

Note: You forgot dormant check
Quote Originally Posted by SemixOfficial View Post
Quite interesting little script but why not just make simple blockbot instead ?

Many people will just run behind a prop at which point you will get stuck with this since there's no actual pathfinding or obstacle avodation in the code.

Note: You forgot dormant check

You can comment out
Code:
cmd:SetForwardMove( ( (math.sin(math.rad(ang_LocalPlayer[2]) ) * world_forward[2]) + math.cos(math.rad(ang_LocalPlayer[2]) ) * world_forward[1]) ) * 300 )
and it'll act like a block bot.

yeah it's to tricky to get stuck behind a prop if you're right on the player, unless it's a door or they spawn a prop to block you, but then you can just manually press W A S D or space and it'll stop the following the target while you're pressing the keys,

and yeah oops, wish I could edit my thread w/o having to contact a mod, cba
Can u add a blockbot because what u told us to do didnt work
Player Follow script lua
So, I decided to post my first lua script because it helped me a lot to play with mutiples Tibia Clients. Its a really basic script to follow other players.

Commands:

follow "player name"
start
stop

If you are following one player and wants to follow another one, you must stop it first then use the command follow again.

Code:
Player Follow script lua
How do I kill a script in lua?

Example:

For start script:

dofile"name.lua"

And for stop script?

Sorry my bad english.

I resolved with the following code:

loadSettings"name settings", "All"
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?