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

Action .::1-Row Slot Machine::. TFS [0.3/0.4/1.0/1.2]

i did it and it works , but i have other problem.
How to make second machine with other prize ?
i tried do it but it doesn't work. I made new 'slot2.lua' and changed there positions and added uniqueid and
added to actions.xml new uniqueid but it doesn't work :(

when i want use new slot machine i see:

[9/3/2015 16:14:36] [Error - Action Interface]
[9/3/2015 16:14:36] data/actions/scripts/slot.lua:eek:nUse
[9/3/2015 16:14:36] Description:
[9/3/2015 16:14:36] data/actions/scripts/slot2.lua:70: attempt to index local 'pos' (a nil value)
[9/3/2015 16:14:36] stack traceback:
[9/3/2015 16:14:37] data/actions/scripts/slot2.lua:70: in function 'verifyRow'
[9/3/2015 16:14:37] data/actions/scripts/slot.lua:149: in function <data/actions/scripts/slot.lua:91>

CAN YOU HELP ME PLEASE? :rolleyes::rolleyes::rolleyes:
 
lpXykPg.png
This is so old, but those arrows and boxes are fucking fabulous.
 
Can this be fixed for tfs 1.1?

I have it "semi" working for 1.1 but the fruits are not appearing :(

blz Halp.

-Martin
 
Code updated for TFS 1.2, check main post and follow the specifications. That might work too for TFS 1.1 too but I haven't tested.
If you have TFS 1.2, add the missing line at data/lib/core/position.lua
Find function Position.getNextPosition, replace it with:
Code:
function Position:getNextPosition(direction, steps)
    local offset = Position.directionOffset[direction]
    if offset then
        steps = steps or 1
        self.x = self.x + offset.x * steps
        self.y = self.y + offset.y * steps
    end
    return self
end

TFS 1.2 requires you to compile player method onMove:
https://github.com/otland/forgottenserver/commit/55dba115fc4f351af9416b06d9711ed8680933be

data/actions/actions.xml

tfs 1.0/1.2
Code:
<action fromuid="6297" touid="6301" script="slot.lua"/>

data/actions/scripts/slot.lua
tfs 1.2

Code:
--[[
    .::1-Row Slot Machine::.
          For TFS 1.2
      by Cybermaster (cbrm)
]]--

--    1. FRUITS
TEMP, FRUITS = {
    ['APPLE'] = 2674,    ['BANANA'] = 2676,    ['BERRY'] = 2680,
    ['CHERRY'] = 2679,    ['LEMON'] = 8841,    ['MANGO'] = 5097,
    ['MELON'] = 2682,    ['ORANGE'] = 2675,    ['PUMPKIN'] = 2683
}, {}

for name, id in pairs(TEMP) do
    _G[name] = id
    table.insert(FRUITS, id)
end

--    2. CONFIGURATION
SETUP = {
    MONEY = 1000, --REQUIRED MONEY(gp) TO PLAY SLOT MACHINE
    TIME = 200, --MILLISECONDS TO SWITCH FRUITS
    LIMIT = 20, --COUNTER TO STOP CHANGING FRUIT IF PLAYER DOESN'T (decreases each SETUP.TIME)
    LEVER = {6297, 6298},
    WIN = {
    -- [FRUITS] = {PRIZE,#PRIZE}]
        --MIXED COMBINATIONS
            [{CHERRY,PUMPKIN,CHERRY}] = {2160,2},
            [{LEMON,MELON,LEMON}] = {2160,1},
        --TRIPLE COMBINATIONS
            [{BERRY,BERRY,BERRY}] = {2152,80},
            [{MANGO,MANGO,MANGO}] = {2152,60},
            [{PUMPKIN,PUMPKIN,PUMPKIN}] = {2152,80},
            [{MELON,MELON,MELON}] = {2152,50},
            [{BANANA,BANANA,BANANA}] = {2152,40},
            [{LEMON,LEMON,LEMON}] = {2152,25},
            [{CHERRY,CHERRY,CHERRY}] = {2152,20},
            [{ORANGE,ORANGE,ORANGE}] = {2152,30},
            [{APPLE,APPLE,APPLE}] = {2152,10},
        --ANY COMBINATIONS
            [{ANY,PUMPKIN,PUMPKIN}] = {2152,5},
            [{PUMPKIN,PUMPKIN,ANY}] = {2152,5},
            [{PUMPKIN,ANY,PUMPKIN}] = {2152,10},
            [{ANY,CHERRY,CHERRY}] = {2152,4},
            [{CHERRY,CHERRY,ANY}] = {2152,4},
            [{CHERRY,ANY,CHERRY}] = {2152,8},
            [{ANY,LEMON,LEMON}] = {2152,5},
            [{LEMON,LEMON,ANY}] = {2152,5},
            [{LEMON,ANY,LEMON}] = {2152,5},
        },
    MSG = {'Bingo!','Lucky!','Jackpot!','Win!'},
    POS = {    --[LEVER.UNIQUEID] = {direction to row, distance from lever to row, position of lever}
        [6297] = {direction = SOUTH, distance = 2, pos = Position(97, 83, 7)},
        [6299] = {direction = EAST, distance = 2, pos = Position(105, 78, 7)},
        [6300] = {direction = NORTH, distance = 2, pos = Position(99, 76, 7)},
        [6301] = {direction = WEST, distance = 2, pos = Position(95, 78, 7)},
    },
}

for lever, row in pairs(SETUP.POS) do
    local position = row.pos:getNextPosition(row.direction, row.distance)
    for tile = 0, 2 do
        if row.direction % 2 == 0 then
            SETUP.POS[lever][tile+101] = Position(position.x+tile, position.y, position.z, 1)
        else
            SETUP.POS[lever][tile+101] = Position(position.x, position.y+tile, position.z, 1)
        end
    end
end

--    3. FUNCTIONS
MAY_NOT_MOVE = 20155
function mayNotMove(cid, bool)
    Player(cid):setStorageValue(MAY_NOT_MOVE, bool and 1 or -1)
end

function choose(...)
    local arg, ret = {...}
    if type(arg[1]) == 'table' then
        ret = arg[1][math.random(#arg[1])]
    else
        ret = arg[math.random(#arg)]
    end
    return ret
end

local function switchLever(lev)
    return doTransformItem(lev.uid, lev.itemid == SETUP.LEVER[1] and SETUP.LEVER[2] or SETUP.LEVER[1])
end

local function verifyRow(cid, pos)
    local result = false
    for combo, profit in pairs(SETUP.WIN) do
        if (getTileItemById(pos[101], combo[1]).uid > 0) or (combo[1] == ANY) then
            if (getTileItemById(pos[102], combo[2]).uid > 0) or (combo[2] == ANY) then
                if (getTileItemById(pos[103], combo[3]).uid > 0) or (combo[3] == ANY) then
                    result = true
                    doPlayerAddItem(cid, profit[1], profit[2] or 1, true)
                    doCreatureSay(cid, choose(SETUP.MSG), TALKTYPE_ORANGE_1)
                    doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'Congratulations!! You won ' .. profit[2] .. ' ' .. getItemDescriptions(profit[1]).plural ..'!')
                    break
                end
            end
        end
    end

    for tile = 101, 103 do
        doRemoveItem(getTileThingByPos(pos[tile]).uid)
        doSendMagicEffect(pos[tile], result and CONST_ME_GIFT_WRAPS or CONST_ME_EXPLOSIONHIT)
    end

    return not result and doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, 'You have lost in the Slot Machine :( Try again')
end

local function getDirectionTo(pos1, pos2)
    local dir = SOUTH
    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end
    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end
    elseif(pos1.y > pos2.y) then
        dir = NORTH
    elseif(pos1.y < pos2.y) then
        dir = SOUTH
    end
    return dir
end

--    4. SCRIPT
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if getDirectionTo(player:getPosition(), fromPosition) > 3 then
        return true
    end

      local pid = player:getId()
    local function getLever()
        for _, id in ipairs(SETUP.LEVER) do
            local lever = getTileItemById(fromPosition, id)
            if lever.uid > 0 then
                return lever
            end
        end    
    end

    if item.actionid == 0 then
        doSetItemActionId(item.uid, 100)
    end
    local function doFruit(pos, id, limit)
        if not player:isPlayer() then
            doSetItemActionId(item.uid, 100)
            for tile = 100, 103 do
                if getTileThingByPos(pos[tile]).uid > 0 then
                    doRemoveItem(getTileThingByPos(pos[tile]).uid)
                end
            end
            return true
        end
   
        if getTileThingByPos(pos[id]).itemid < 1 then
            doSendMagicEffect(pos[id], CONST_ME_POFF)
            local fruit = doCreateItemEx(choose(FRUITS))
            doSetItemActionId(fruit, 100)
            doTileAddItemEx(pos[id], fruit)
        else
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
        end
   
        if limit < 1 then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            switchLever(getLever())
            doSetItemActionId(getLever().uid, getLever().actionid+1)
        elseif getLever().actionid > id then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
        else
            addEvent(doFruit, SETUP.TIME, pos, id, limit-1)
        end
    end

    if item.actionid == 100 then    
        if not player:removeMoney(SETUP.MONEY) then
            return player:sendTextMessage(MESSAGE_STATUS_WARNING, 'You need ' .. SETUP.MONEY ..' gps to play Slot Machine.')
        end
   
        doSetItemActionId(item.uid, 101)
        mayNotMove(pid, true)
        switchLever(item)
        player:say('-$' .. SETUP.MONEY, TALKTYPE_ORANGE_1)
        for tile = 101, 103 do
            doFruit(SETUP.POS[item.uid], tile, (tile-100)*SETUP.LIMIT)
        end
    elseif isInArray({101,102,103}, item.actionid) then
        switchLever(item)
        doSetItemActionId(item.uid, item.actionid+1)
    elseif item.actionid == 104 then
        switchLever(item)
        mayNotMove(pid, false)
        verifyRow(pid, SETUP.POS[item.uid])
        doSetItemActionId(item.uid, 100)
    end
    return true
end

tfs 1.2
1. Add @data/creaturescripts/login.lua
Code:
player:setStorageValue(MAY_NOT_MOVE, -1)

2. Make sure player methods onMoveItem and onMove are enabled:

data/events/events.xml
Code:
<event class="Player" method="onMoveItem" enabled="1" />
<event class="Player" method="onMove" enabled="1"/>

3. Then edit those two player methods
data/events/scripts/player.lua
Code:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = Tile(toPosition)
    if tile and tile:getGround() and (tile:getGround().actionid == 6577) then
        self:sendCancelMessage('Sorry, not possible.')
        return false
    end
    return true
end

function Player:onMove(direction)
    if self:getStorageValue(MAY_NOT_MOVE) == 1 then
        return false
    end
    return true
end
 
Code updated for TFS 1.2, check main post and follow the specifications. That might work too for TFS 1.1 too but I haven't tested.
well done bro, as always
btw you should know that if you try to move (100 times) you will be disconnected
Code:
127.0.0.1 disconnected for exceeding packet per second limit.
you can reproduce it
 
I noticed that late, I chose onMove instead of re-adding mayNotMove because it was less hassle editing the sources :p
 
Good morning, I have the following query, what happens if the character clicks on the lever and then disconnects? Here in my tfs rev.0.4 3777, I do not empty the spaces again and I have to wait for the character to click again, because then it does not work. Pd: there is no error in console, only that is the inconvenience
 
fruits dont appear =x
tfs 1.2 10.99
Sem título.png
Lua:
[6300] = {direction = NORTH, distance = 2, pos = Position(32386, 32183, 8)},
[6301] = {direction = NORTH, distance = 2, pos = Position(32390, 32183, 8)},
[6302] = {direction = NORTH, distance = 2, pos = Position(32394, 32183, 8)},
 
fruits dont appear =x
tfs 1.2 10.99
View attachment 30207
Lua:
[6300] = {direction = NORTH, distance = 2, pos = Position(32386, 32183, 8)},
[6301] = {direction = NORTH, distance = 2, pos = Position(32390, 32183, 8)},
[6302] = {direction = NORTH, distance = 2, pos = Position(32394, 32183, 8)},
That actionid is for tfs 1.0, please read headers.
And I suppose the source code has not varied much, so it should still be working for you once you add the scripts well.
 
Just tested it again, doesn't work on tfs 1.2.

Seems to work if you remove the actionid from the lever.
 
Last edited by a moderator:
I'm having trouble making it work, my lever dissapears when I use it.

Nvm it works.
 
Last edited by a moderator:
Back
Top