• 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!

Lua Football System

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,470
Solutions
27
Reaction score
844
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi! I use TFS 1.4 8.6 by nekiros and would like to request a simple football system.

  • First, I will set the pickupable flag off the football item so players won't be able to pick the ball in their inventories.
  • The football item is going to have a custom ID registered on items.otb and .xml
  • The idea is to have a frompos - topos area that limits the football field (red)
  • If the football item gets out of the frompos - to pos area , the ball will be automatically teleported to the middle of the field (yellow)
  • There's no need to set a limit to blue area, it only refers to space that is outside red area
  • The grey marked areas are going to have "nothing special" floor so balls won't be able to be thrown there
  • The light blue can be moveevent tiles that sends the football item to the middle with a different effect (ex. "goal!") (a good example as moveevent can be scarab tokens script from ankrahmun tombs)
  • There's also something important, players shouldn't be able to throw items inside red area
  • Player should only be able to move football item 1 SQM, not sure if function onMoveItem can be usefull here
1630430147639.png

In advance, thanks
Regards!
 
Last edited:
Solution
View attachment bandicam 2021-09-01 07-07-30-436.mp4
Quick video to show functionality.
  • Items that are not the football cannot be thrown into the arena
  • football can only be thrown 1 sqm
  • football goal area, and out of bounds area
  • tiles directly adjacent to the goal area have 'nothing special', and therefore don't trigger the out of bounds rule

data/scripts/eventcallbacks/player/football_onMoveItem.lua
Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7)...
View attachment bandicam 2021-09-01 07-07-30-436.mp4
Quick video to show functionality.
  • Items that are not the football cannot be thrown into the arena
  • football can only be thrown 1 sqm
  • football goal area, and out of bounds area
  • tiles directly adjacent to the goal area have 'nothing special', and therefore don't trigger the out of bounds rule

data/scripts/eventcallbacks/player/football_onMoveItem.lua
Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            return false
        end
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    return true
end

football:register()
 
Solution
View attachment 61705
Quick video to show functionality.
  • Items that are not the football cannot be thrown into the arena
  • football can only be thrown 1 sqm
  • football goal area, and out of bounds area
  • tiles directly adjacent to the goal area have 'nothing special', and therefore don't trigger the out of bounds rule

data/scripts/eventcallbacks/player/football_onMoveItem.lua
Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            return false
        end
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    return true
end

football:register()

I have this error. TFS 1.3 OTG PREMIUM. Anyway nice script :)

aaa.png
 
View attachment 61705
Quick video to show functionality.
  • Items that are not the football cannot be thrown into the arena
  • football can only be thrown 1 sqm
  • football goal area, and out of bounds area
  • tiles directly adjacent to the goal area have 'nothing special', and therefore don't trigger the out of bounds rule

data/scripts/eventcallbacks/player/football_onMoveItem.lua
Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            return false
        end
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    return true
end

football:register()
it does not work and does not give errors in console
 
it does not work and does not give errors in console
I've added a print for every action that can take place.

Let us know what prints to console.

Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            print("non-football item attempted to be moved into the game arena. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        print("non-football item moved outside of game area. Allowing action.")
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        print("Football attempted to be moved more then 1 tile. Cancelling Action.")
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        print("Football moved into goal area. Cancelling action. Teleporting Football to middle of field.")
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        print("Football moved outside play area. Cancelling action.")
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    print("Football moved to a valid play area location. Allowing Action.")
    return true
end

football:register()
 
Last edited:
@Xikini sorry for the delay! As always, amazing outcome :D
Did a little video with the test results, you always there to solve this kind of requests, thanks for real!!


Regards!
Did you do any other installation apart from putting them in eventacallbacks? because I try but nothing happens not even an error but the system does not work
Post automatically merged:

I've added a print for every action that can take place.

Let us know what prints to console.

Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            print("non-football item attempted to be moved into the game arena. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        print("non-football item moved outside of game area. Allowing action.")
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        print("Football attempted to be moved more then 1 tile. Cancelling Action.")
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        print("Football moved into goal area. Cancelling action. Teleporting Football to middle of field.)
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        print("Football moved outside play area. Cancelling action.)
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    print("Football moved to a valid play area location. Allowing Action.")
    return true
end

football:register()
Now it works but it doesn't score, nothing happens when I throw the ball into the goal, but it does restrict the amount of square meters that I move the ball
Post automatically merged:

1687308908821.png

Maybe it's because I'm playing the field in another position? and not up and down?
 
Last edited:
Did you do any other installation apart from putting them in eventacallbacks? because I try but nothing happens not even an error but the system does not work
Nope, at all! Here's my football camp in RME
1687308830699.png

1687308764058.png

Get sure you have configured well the coordinates. I'm about to sleep, send me a message on discord if you have troubles with the other coordinates (felipe23). The from/to pos are the interior tiles, not the edges. And for the goals, place the position just in the line that must be passed to achieve the goal. It works perfectly ^^

Regards
 
Did you do any other installation apart from putting them in eventacallbacks? because I try but nothing happens not even an error but the system does not work
Post automatically merged:


Now it works but it doesn't score, nothing happens when I throw the ball into the goal, but it does restrict the amount of square meters that I move the ball

It would help immensely if you showed us what is printing to the console when you move the football.
There is 7 different things that can print.. which will tell us where the problem is.
 
nothing prints :(
Alright. There is no way it can't not print something now..

Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    print("Something is being moved..")
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            print("non-football item attempted to be moved into the game arena. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        print("non-football item moved outside of game area. Allowing action.")
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        print("Football attempted to be moved more then 1 tile. Cancelling Action.")
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        print("Football moved into goal area. Cancelling action. Teleporting Football to middle of field.")
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        print("Football moved outside play area. Cancelling action.")
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    print("Football moved to a valid play area location. Allowing Action.")
    return true
end

football:register()
 
Alright. There is no way it can't not print something now..

Lua:
local footballId = 10522
local gameArea = {
    main = {
        from = Position(241, 238, 7),
        to = Position(253, 246, 7)
    },
    goals = {
        top = {
            from = Position(240, 241, 7),
            to = Position(240, 243, 7)
        },
        bottom = {
            from = Position(254, 241, 7),
            to = Position(254, 243, 7)
        }
    },
    middle = Position(247, 242, 7)
}

local football = EventCallback

football.onMoveItem = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    print("Something is being moved..")
    -- disable players from throwing items in gameArea
    if item:getId() ~= footballId then
        if toPosition:isInRange(gameArea.main.from, gameArea.main.to) then
            print("non-football item attempted to be moved into the game arena. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        if toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
            print("non-football item attempted to be moved into the goal area's. Cancelling action.")
            return false
        end
        print("non-football item moved outside of game area. Allowing action.")
        return true
    end
    -- distance check
    if fromPosition:getDistance(toPosition) > 1 then
        print("Football attempted to be moved more then 1 tile. Cancelling Action.")
        return false
    end
    -- goal check
    if toPosition:isInRange(gameArea.goals.top.from, gameArea.goals.top.to) or toPosition:isInRange(gameArea.goals.bottom.from, gameArea.goals.bottom.to) then
        print("Football moved into goal area. Cancelling action. Teleporting Football to middle of field.")
        item:moveTo(gameArea.middle)
        self:say("Goal!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        toPosition:sendMagicEffect(CONST_ME_FIREAREA)
        return false
    end
    -- out of bounds check
    if not toPosition:isInRange(gameArea.main.from, gameArea.main.to) and Tile(toPosition):isWalkable() then
        print("Football moved outside play area. Cancelling action.")
        item:moveTo(gameArea.middle)
        self:say("Out of Bounds!", TALKTYPE_MONSTER_SAY, false, nil, toPosition)
        return false
    end
    print("Football moved to a valid play area location. Allowing Action.")
    return true
end

football:register()
It doesn't print anything and players can drop items on the floor, surely it's not because the map isn't from above?
 
It doesn't print anything and players can drop items on the floor, surely it's not because the map isn't from above?
Discord. Add me.

xikini

--
and no. The orientation of your field should not matter.
Post automatically merged:

resolved. had to move it into data/events/scripts/player.lua directly, as the event wasn't properly triggering from the scripts folder.
 
Last edited:
Back
Top