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

Problem with casino npc, he withdraw low than i won

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i found casino npc for tfs 1.3 and i change him to play with others money Black Coin (1bc = 100cc) and all working but when i put 50bc to play i type number (if we type numer we can won 5x) and when i won, npc withdraw me only 100bc not 250 i don't know why :/


Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)              npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)           npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)      npcHandler:onCreatureSay(cid, type, msg)    end

local config = {
    bonusPercent = 2,
    bonusPercentt = 5,
    minimumBet = 1,
    maximumBet = 50
}

local storeMoneyAmount = 0 -- Do not touch [We store the amount cash which got betted here]
local ITEM_BLOCKING = 8046

local function getMoneyAmount(position)
    local moneyAmount = 0
    for _, item in ipairs(Tile(position):getItems()) do
        local itemId = item:getId()
        if itemId == 12543 then
            moneyAmount = moneyAmount + item.type
        end
    end

    return moneyAmount
end

local function handleMoney(cid, position, bonus)
    local npc = Npc(cid)
    if not npc then
        return
    end

    -- Lets remove the cash which was betted
    for _, item in ipairs(Tile(position):getItems()) do
        if isInArray({ITEM_BLACK_COIN, ITEM_BLOCKING}, item:getId()) then
            item:remove()
        end
    end

    -- We lost, no need to continue
    if bonus == 0 then
        npc:say(string.format("You lose: %d Black Coins! :(", storeMoneyAmount), TALKTYPE_MONSTER_SAY)
        position:sendMagicEffect(CONST_ME_POFF)
        return
    end

    -- Cash calculator
    local goldCoinAmount = storeMoneyAmount * bonus

    if goldCoinAmount ~= 0 then
        Game.createItem(12543, goldCoinAmount, position)
    end

    position:sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    npc:say(string.format("You won: %d Black Coins! :)", storeMoneyAmount * bonus), TALKTYPE_MONSTER_SAY)
end

local function startRollDice(cid, position, number)
    for i = 5792, 5797 do
        local dice = Tile(position):getItemById(i)
        if dice then
            dice:transform(5791 + number)
            break
        end
    end
    local npc = Npc(cid)
    if npc then
        npc:say(string.format("%s rolled a %d", npc:getName(), number), TALKTYPE_MONSTER_SAY)
    end
end

local function executeEvent(cid, dicePosition, number, moneyPosition, bonus)
    local npc = Npc(cid)
    if not npc then
        return
    end
   
    if getMoneyAmount(moneyPosition) ~= storeMoneyAmount then
        npc:say("Where is the money?!", TALKTYPE_MONSTER_SAY)
        return
    end
   
    -- Roll Dice
    addEvent(startRollDice, 400, cid, dicePosition, number)
    dicePosition:sendMagicEffect(CONST_ME_CRAPS)
   
    -- Handle Money
    addEvent(handleMoney, 600, cid, moneyPosition, bonus)
end

local function creatureSayCallback(cid, type, msg)
    if not isInArray({"high", "low", "l", "h", "1", "2", "3", "4", "5", "6"}, msg) then -- Ignore other replies
        return false
    end

    -- Npc Variables
    local npc = Npc()
    local npcPosition = npc:getPosition()

    -- Check if player stand in position
    local playerPosition = Position(npcPosition.x - 2, npcPosition.y, npcPosition.z)
    local topCreature = Tile(playerPosition):getTopCreature()
    if not topCreature then
        playerPosition:sendMagicEffect(CONST_ME_TUTORIALARROW)
        playerPosition:sendMagicEffect(CONST_ME_TUTORIALSQUARE)
        return false
    end

    -- Make sure also the player who stand there, is the one who is betting. To keep out people from disturbing
    if topCreature:getId() ~= cid then
        return false
    end
    -- High or Low numbers
    local rollType = 0
    if msgcontains(msg, "low") then
        rollType = 1
    elseif msgcontains(msg, "high") then
        rollType = 2
    elseif msgcontains(msg, "h") then
        rollType = 2
    elseif msgcontains(msg, "l") then
        rollType = 1
    elseif msgcontains(msg, "1") then
        rollType = 3
    elseif msgcontains(msg, "2") then
        rollType = 4
    elseif msgcontains(msg, "3") then
        rollType = 5
    elseif msgcontains(msg, "4") then
        rollType = 6
    elseif msgcontains(msg, "5") then
        rollType = 7
    elseif msgcontains(msg, "6") then
        rollType = 8
    else
        return false
    end

    -- Check money Got betted
    local moneyPosition = Position(npcPosition.x - 1, npcPosition.y - 1, npcPosition.z)
        storeMoneyAmount = getMoneyAmount(moneyPosition)
    if storeMoneyAmount < config.minimumBet then
        npc:say(string.format("Min: 1 Black Coin", config.minimumBet/10000, config.maximumBet/10000), TALKTYPE_MONSTER_SAY)
        return false
    elseif storeMoneyAmount > config.maximumBet then
        npc:say(string.format("Max: 50 Black Coins", config.minimumBet/10000, config.maximumBet/10000), TALKTYPE_MONSTER_SAY)
        return false
    end
    -- Money is betted, lets block them from getting moved // This is one way, else we can set actionid, on the betted cash.
    Game.createItem(ITEM_BLOCKING, 1, moneyPosition)

    -- Roll Number
    local rollNumber = math.random(6)

    -- Win or Lose
    local bonus = 0
    if rollType == 1 and isInArray({1, 2, 3}, rollNumber) then
        bonus = config.bonusPercent
    elseif rollType == 2 and isInArray({4, 5, 6}, rollNumber) then
        bonus = config.bonusPercent
    elseif rollType == 3 and isInArray({1}, rollNumber) then
        bonus = config.bonusPercentt
    elseif rollType == 4 and isInArray({2}, rollNumber) then
        bonus = config.bonusPercentt
    elseif rollType == 5 and isInArray({3}, rollNumber) then
        bonus = config.bonusPercentt
    elseif rollType == 6 and isInArray({4}, rollNumber) then
        bonus = config.bonusPercentt
    elseif rollType == 7 and isInArray({5}, rollNumber) then
        bonus = config.bonusPercentt
    elseif rollType == 8 and isInArray({6}, rollNumber) then
        bonus = config.bonusPercentt
    end
   
    -- Money handle and roll dice
    addEvent(executeEvent, 100, npc:getId(), Position(npcPosition.x, npcPosition.y - 1, npcPosition.z), rollNumber, moneyPosition, bonus)
    return true
end

function onThink()
    -- Anti trash
    local npcPosition = Npc():getPosition()
    local moneyPosition = Position(npcPosition.x - 1, npcPosition.y - 1, npcPosition.z)

    for _, item in ipairs(Tile(moneyPosition):getItems()) do
        local itemId = item:getId()
        if not isInArray({12543, ITEM_BLOCKING}, itemId) and ItemType(itemId):isMovable() then
            item:remove()
        end
    end
   
    local dicePosition = Position(npcPosition.x, npcPosition.y - 1, npcPosition.z)
    for _, item in ipairs(Tile(dicePosition):getItems()) do
        local itemId = item:getId()
        if not isInArray({5792, 5793, 5794, 5795, 5796, 5797}, itemId) and ItemType(itemId):isMovable() then
            item:remove()
        end
    end

    npcHandler:onThink()                   
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Solution
You can use this
I try add this money to bank but i got player nil error :/
In this function i try it:
Code:
local function handleMoney(cid, position, bonus)
    local npc = Npc(cid)
    if not npc then
        return
    end

    -- Lets remove the cash which was betted
    for _, item in ipairs(Tile(position):getItems()) do
        if isInArray({ITEM_BLACK_COIN, ITEM_BLOCKING}, item:getId()) then
            item:remove()
        end
    end

    -- We lost, no need to continue
    if bonus == 0 then
        npc:say(string.format("You Lose: %d Black Coins! :(", storeMoneyAmount), TALKTYPE_MONSTER_SAY)
        position:sendMagicEffect(CONST_ME_POFF)
        return
    end

    -- Cash calculator
    local player = Player(cid)
    local goldCoinAmount = storeMoneyAmount * bonus

    if goldCoinAmount ~= 0 then
        if goldCoinAmount > 100 then
            player:setBankBalance(player:getBankBalance() + goldCoinAmount)
        else Game.createItem(12543, goldCoinAmount, position)
    end
end

    position:sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE))
    npc:say(string.format("You Won: %d Black Coins! :)", storeMoneyAmount * bonus), TALKTYPE_MONSTER_SAY)
end
 
In this part:
Lua:
    if goldCoinAmount ~= 0 then
        Game.createItem(12543, goldCoinAmount, position)
    end

You should actually loop it in case there are more than 100 goldCoinAmount

Im in phone right now, but it should be something like:

CODE=lua] if goldCoinAmount > 0 then
repeat
If(goldCoinAmount>=100) then
Game.createItem(12543, 100, position)
goldCoinAmount = goldCoinAmount - 100
elseif goldCoinAmount > 0 then
Game.createItem(12543, goldCoinAmount, position)
goldCoinAmount = 0
end
until goldCoinAmount == 0
end[/CODE]
 
You can use this
 
Solution
You can use this

Holy shit, thanks! I don't know why I didn't find it before.
 

Similar threads

Back
Top