• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TFS 1.1 Functions [GetPositionTowardsTarget, MoveCreaturesInArea, Dungeon System]

kyoushirou

I like trains
Joined
Apr 29, 2009
Messages
224
Reaction score
58
Hi! These are my TFS 1.1 Functions I made to make my life easier. Just place them in global.lua if you want to use them.
They are not professional, I'm just a self-taught amateur and this is not the best way to do this, I'm sure.
Also, some of them are just to save me the trouble of repeating longer code that I use a lot.

If you'd like to share them somewhere else, credit me please. Zealan or Kyoushirou is fine, I go by both.

function GetPositionTowardsTarget(cid)
Returns the position closest to you that is in the direction towards your target.
Code:
function GetPositionTowardsTarget(cid)
    if (not isCreature(cid)) or (getCreatureTarget(cid) == nil) then
        print('You have either not defined target or cid.')
        return false
    else
        local PlayerPos = getCreaturePosition(cid)
        local targetPos = getCreaturePosition(getCreatureTarget(cid))
                    if(PlayerPos.x == targetPos.x) and (PlayerPos.y < targetPos.y) then
                        return {x = PlayerPos.x, y = PlayerPos.y+1, z = PlayerPos.z}
                    elseif(PlayerPos.x == targetPos.x) and (PlayerPos.y > targetPos.y) then
                        return {x = PlayerPos.x, y = PlayerPos.y-1, z = PlayerPos.z}
                    elseif(PlayerPos.x < targetPos.x) and (PlayerPos.y == targetPos.y) then
                        return {x = PlayerPos.x+1, y = PlayerPos.y, z = PlayerPos.z}
                    elseif(PlayerPos.x > targetPos.x) and (PlayerPos.y == targetPos.y) then
                        return {x = PlayerPos.x-1, y = PlayerPos.y, z = PlayerPos.z}
                    elseif(PlayerPos.x > targetPos.x) and (PlayerPos.y > targetPos.y) then
                        return {x = PlayerPos.x-1, y = PlayerPos.y-1, z = PlayerPos.z}
                    elseif(PlayerPos.x > targetPos.x) and (PlayerPos.y < targetPos.y) then
                        return {x = PlayerPos.x-1, y = PlayerPos.y+1, z = PlayerPos.z}
                    elseif(PlayerPos.x < targetPos.x) and (PlayerPos.y < targetPos.y) then
                        return {x = PlayerPos.x+1, y = PlayerPos.y+1, z = PlayerPos.z}
                    elseif(PlayerPos.x < targetPos.x) and (PlayerPos.y > targetPos.y) then
                        return {x = PlayerPos.x+1, y = PlayerPos.y-1, z = PlayerPos.z}
                    end
    end
end


MoveCreaturesInArea(AreaCenterPosition, rangeX, rangeY, destination)
Moves any creatures inside target area to target position.

Code:
function MoveCreaturesInArea(AreaCenterPosition, rangeX, rangeY, destination)
local creatures = getSpectators(AreaCenterPosition, rangeY, rangeX, nil, nil)
    if creatures ~= nil then
        for i, pid in ipairs(creatures) do
            doTeleportThing(pid, destination)
        end
    end 
end


function MoveCreaturesInAreaWithEffect(AreaCenterPosition, rangeX, rangeY, destination, effect)
Same as the previous, but also sends a distanceshoot to the target positon.

Code:
function MoveCreaturesInAreaWithEffect(AreaCenterPosition, rangeX, rangeY, destination, effect)
local creatures = getSpectators(AreaCenterPosition, rangeY, rangeX, nil, nil)
    if creatures ~= nil then
        for i, pid in ipairs(creatures) do
            doTeleportThing(pid, destination)
            doSendDistanceShoot(getCreaturePosition(pid), destination, effect)
        end
    end 
end

function IsBossAlive(dungeonPosition, rangeX, rangeY, AcceptedNamesArray)
Simply checks if creature is alive in certain area, checks by name. Uses an array of names that you have to define. Eg: local AcceptedNamesArray = {'bla', 'bla2'}

Code:
function IsBossAlive(dungeonPosition, rangeX, rangeY, AcceptedNamesArray)
local Boss = getSpectators(dungeonPosition, rangeY, rangeX, nil, nil)
    if Boss ~= nil then 
        for i, pid in ipairs(Boss) do
            if not isInArray(AcceptedNamesArray, getCreatureName(pid)) then
                return false
            else
                return true
            end
        end
    else 
        return false
    end
end


function IsDungeonFree(dungeonPosition, rangeX, rangeY, AcceptedNamesArray)
Same thing as previous function, but this one returns true if theres nobody with a different name inside.

Code:
function IsDungeonFree(dungeonPosition, rangeX, rangeY, AcceptedNamesArray)
local creaturesinside = getSpectators(dungeonPosition, rangeY, rangeX, nil, nil)
    if creaturesinside ~= nil then 
        for i, pid in ipairs(creaturesinside) do
            if not isInArray(AcceptedNamesArray, getCreatureName(pid)) then
                return false
            else
                return true
            end
        end
    else 
        return true
    end
end

function CleanDungeon(dungeonPosition, rangeX, rangeY)
Removes creatures in an area

Code:
function CleanDungeon(dungeonPosition, rangeX, rangeY)
local creatures = getSpectators(dungeonPosition, rangeY, rangeX, nil, nil)
    if creatures ~= nil then
        for i, pid in ipairs(creatures) do
            doRemoveCreature(pid)
        end
    end 
end
 
Back
Top