XenoBot Forums - Powered by vBulletin

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Follow - My First Script

  1. #1

    Join Date
    Jan 2016
    Posts
    3
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Follow - My First Script

    So, I decided to post my first lua script because it helped me a lot to play with mutiples Tibia Clients. It's 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:
    local target = ""
    
    Module("autoFollow", function(module)
    	local player = Creature(target)
    	print(target)
    	if player:isOnScreen(true) then
    		Creature.Follow(target)
    	end
    end, false)
    
    function onSpeak(chat, msg)
        chat:SendYellowMessage(Self.Name(), msg)
        if (msg == "start") then
            Module("autoFollow"):Start()
            chat:SendOrangeMessage("Console", string.format("Started following %s.", target ))
        elseif (msg == "stop") then
            Module("autoFollow"):Stop()
            chat:SendOrangeMessage("Console", "Stoped following.")
        elseif msg:match("^name") then
    		local name = msg:match("^follow (.+)")
    		if name then
    			Module("autoFollow"):Stop()
    			target = name
    			chat:SendOrangeMessage("Control", "New player added.")
    		end
        end
    end
    
    function onClose() end
      
    local chat = Channel("autoFollow", onSpeak, onClose)

  2. #2
    Mageq's Avatar
    Join Date
    Aug 2012
    Posts
    396
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    Problem with this is if the player that is being followed goes to a different floor :S

  3. #3

    Join Date
    Apr 2015
    Posts
    29
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Congratulations on this one! If you could make a script that auto-follow and also change floors, it would be amazing! Thanks!

  4. #4

    Join Date
    Apr 2012
    Posts
    20
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    @The_Miguelito ,
    You have to add stairs id etc. But the framework is working. :]

    Code:
    FollowThisPerson = "" -- Character name to follow. 
    
    FloorChangers = {
    	Ladders   = {Up   = {1948,},
    			     Down = {432, 412, 469, 369, 7478, 7182, 482, 8658}},
    	
    	Holes     = {Up   = {},
    	             Down = {293, 294, 595, 385, 594}},
    	
    	RopeSpots = {Up   = {386},
    	             Down = {}},
    	
    	Stairs    = {Up   = {1958, 7548, 7544, 1952, 1950, 1947, 7542, 1978, 8657, 1977, 1956, 1957, 1954},
    	             Down = {414, 413, 437, 7731, 469, 413, 434, 469, 438, 600, 4826, 8932, 6129}},
    	Sewers    = {Up   = {},
    	             Down = {435, }},
    }
    
    ---------------------------------------------
    -------------- END OF CONFIG ----------------
    ---------------------------------------------
    
    local target = FollowThisPerson
    local lastKnownPosition
    
    local function goLastKnown()
    	while Self.DistanceFromPosition(lastKnownPosition.x, lastKnownPosition.y, lastKnownPosition.z) > 1 do
    		Self.UseItemFromGround(lastKnownPosition.x, lastKnownPosition.y, lastKnownPosition.z)
    		wait(200, 700)
    	end
    end
    
    local function handleUse(pos)
    	goLastKnown()
    	local lastZ = Self.Position().z
    	while Self.Position().z == lastZ do
    		Self.UseItemFromGround(pos.x, pos.y, pos.z)
    		wait(400, 800)
    	end
    end
    
    local function handleStep(pos)
    	goLastKnown()
    	local lastZ = Self.Position().z
    	while Self.Position().z == lastZ do
    		Self.Step(Map.GetDirectionTo(Self.Position(), pos))
    		wait(400, 800)
    	end
    end
    
    local function getRope()
    	local ropes = {"rope", "elvenhair rope"}
    	for _, rope in ipairs(ropes) do
    		if Self.ItemCount(rope) > 0 then return Item.GetID(rope) end
    	end
    end
    
    local function handleRope(pos)
    	goLastKnown()
    	local lastZ = Self.Position().z
    	while Self.Position().z == lastZ do
    		Self.UseItemWithGround(getRope(), pos.x, pos.y, pos.z)
    		wait(400, 800)
    	end
    end
    
    local floorChangeSelector = {
    	Ladders = {Up=handleUse, Down=handleStep},
    	Holes = {Up=handleStep, Down=handleStep},
    	RopeSpots = {Up=handleRope, Down=handleRope},
    	Stairs = {Up=handleStep, Down=handleStep},
    	Sewers = {Up=handleUse, Down=handleUse},
    }
    
    
    Module("Follow-Renew", function(f)
    	local c = Creature(target)
    	if c and not c:isFollowed() then
    		c:Follow()
    	end
    end)
    
    local function checkTargetPos()
    	local c = Creature(target)
    	if c:Position().z == Self.Position().z then
    		lastKnownPosition = c:Position()
    	end
    end
    
    local function distance(pos1, pos2)
    	local pos2 = pos2 or lastKnownPosition or Self.Position()
    	return math.abs(pos1.x-pos2.x) + math.abs(pos1.y-pos2.y)
    end
    
    local function executeClosest(possibilities)
    	local closest
    	local closestDistance = 99999
    	for _, data in ipairs(possibilities) do
    		local dist = distance(data.pos)
    		if dist < closestDistance then
    			closest = data
    			closestDistance = dist
    		end
    	end
    	if closest then closest.changer(closest.pos) end
    end
    
    local function handleFloorChange()
    	local c = Creature(target)
    	local range = 2
    	local p = Self.Position()
    	local possibleChangers = {}
    	for _, dir in ipairs({"Down", "Up"}) do
    		for changer, data in pairs(FloorChangers) do
    			for x = -range, range do
    				for y = -range, range do
    					if table.find(data[dir], Map.GetTopUseItem(p.x+x, p.y+y, p.z).id) then
    						table.insert(possibleChangers, {changer=floorChangeSelector[changer][dir], pos={x=p.x+x, y=p.y+y, z=p.z}})
    					end
    				end
    			end
    		end
    	end
    	executeClosest(possibleChangers)
    end
    
    local function targetMissing()
    	for name, c in Creature.iPlayers() do
    		if name == target then
    			return c:Position().z ~= Self.Position().z
    		end
    	end
    	return true
    end
    
    Module("Handle floor change", function(f)
    	checkTargetPos()
    	if targetMissing() and lastKnownPosition then
    		handleFloorChange()
    	end
    end)
    @edit

    Hum, I think it's possible to glue the first script made by @wurcel and this one. :]
    Last edited by Adrstalik; 02-07-2016 at 11:11 AM.

  5. #5

    Join Date
    Feb 2012
    Posts
    124
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Im super horrible at lua, anyway someone can put the two together ? : )

    also if targeting is active, would it target as it follows?, or, anyway it can follow when its not targetting anything?
    Last edited by nacho_125; 02-12-2016 at 11:39 AM.

  6. #6

    Join Date
    Jun 2012
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Has anyone managed to get the level change follow script to stop following when a creature is targeted? That'd be awesome... I have mucked around with it but keep breaking the script

  7. #7
    Senior Member Trykon's Avatar
    Join Date
    Nov 2014
    Location
    UK
    Posts
    952
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I had the script to follow and fight without changing floors
    http://forums.xenobot.net/showthread...l=1#post485499
    All my full afk scripts are accessible at:
    My thread
    My store
    My project
    Looking for RL Tibia testers - RP and EK scripts for FREE. Link to info.

  8. #8

    Join Date
    Jun 2012
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks yeah I've seen that. Was hoping someone might've modded the level changing follow script to stop following when there are creatures to be attacked.

    I find that when using it my characters run back and forth between each other and the creature, and it affects targeting with spells, too (client seems to be confused and shoots blank squares despite targeting a creature)

  9. #9
    Senior Member Trykon's Avatar
    Join Date
    Nov 2014
    Location
    UK
    Posts
    952
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    On my script I was hunting old fortress on ~70 levels ek and ed. It was working fine so I supposey script is quite alright.
    All my full afk scripts are accessible at:
    My thread
    My store
    My project
    Looking for RL Tibia testers - RP and EK scripts for FREE. Link to info.

  10. #10

    Join Date
    Jun 2012
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Trykon View Post
    On my script I was hunting old fortress on ~70 levels ek and ed. It was working fine so I supposey script is quite alright.
    I get that your script works. What I was saying was the script which was posted above (that changes levels) doesn't stop following when attacking, which means characters run back and forth between the person they're following and the creature they're attacking. It also makes mage strikes attack the player they're following, too.


    I was hoping someone that can script might edit the follow script which changes levels to pause following when attacking a creature...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •