View Full Version : Follow Script
alexsik30
05-31-2016, 02:11 PM
Hello, can somebody help me ? I wanna script which all the time follow my character, walk into portals, on stairs. Thank u very much. Regards :cool:
martintokio
05-31-2016, 10:33 PM
-- Settings
FollowThisPerson = "CHARNAME"
FloorChangers = {
Ladders = {Up = {1948, 5542},
Down = {432, 412, 469, 8932, 411}},
Holes = {Up = {0},
Down = {293, 294, 595, }},
RopeSpots = {Up = {386,},
Down = {}},
Stairs = {Up = {1958, 7548, 7544, 1952, 1950, 1947, 7542, 8657},
Down = {414, 413, 437, 7731, 469, 413, 434, 469,}},
Sewers = {Up = {0},
Down = {435}},
}
-- Functions
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)
alexsik30
05-31-2016, 10:36 PM
THANK YOU !
Trykon
05-31-2016, 10:45 PM
Man... THANKS
I wrote my own script, but only for following on one level :)
shax121
06-01-2016, 10:14 AM
FollowThisPerson = "CHAR NAME!"
FloorChangers = {
Ladders = {Up = {1948,}, -------Ladders Here
Down = {432, 412, 469, 1949}},
Holes = {Up = {},
Down = {293, 294, 595, 4728, 385}}, -------Holes
RopeSpots = {Up = {386,}, -------Rope up(need rope) ...you get the point, add more id's if needed
Down = {}},
Stairs = {Up = {1958, 7548, 7544, 1952, 1950, 1947, 7542, 855, 856, 1978, 1977, 6911, 6915, 1954, 5259},
Down = {414, 413, 437, 7731, 469, 413, 434, 469, 859, 438, 6127}},
Sewers = {Up = {},
Down = {435}},
}
---------------------------------------------
-------------- END OF CONFIG Shax------------
------------------Script starts below--------
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)
shax121
06-01-2016, 05:54 PM
ive gave this script to so many people, but i am so new, it has 1 flaw, sometimes it just goes diagonal for days, literally and u have to stop it...
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.