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

NPC Visual Gambler NPC [TFS 1.x]

Now it should check the original bet and if the bet amount has been changed. Then it will not give reward.

You should consider to update your tfs else under:
Code:
local ITEM_BLOCKING = 8046

Add this:

Code:
local ITEM_GOLD_COIN = 2148
local ITEM_PLATINUM_COIN = 2152
local ITEM_CRYSTAL_COIN = 2160
i got no idea how to compile ;d and im using TFS 1.0 ;\
 
You're not going to compile anything, just add those line in the lua file where i described.
 
Well i had my uncle fix it cause it didnt work for me, if people have same problem as me here is the script ^^

works for TFS 1.0 (10.76-77 + 10.80-82)
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
function onThink()                          npcHandler:onThink() end

local function delayMoneyRemoval(item, pos)
    doRemoveItem(getTileItemById(pos, item).uid)
    return true
end

local function placeMoney(amount, table_middle_pos)
    local remain = amount
    local crystal_coins = 0
    local platinum_coins = 0

    if (math.floor(amount / 10000) >= 1) then
        crystal_coins = math.floor(amount / 10000)
        remain = remain - crystal_coins * 10000
    end
    if ((remain / 100) >= 1) then
        platinum_coins = remain / 100
    end
    addEvent(doCreateItem, 550, 2152, platinum_coins, table_middle_pos)
    addEvent(doCreateItem, 600, 2160, crystal_coins, table_middle_pos)
end

local function rollDice(roll, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
    local dice_ids = {5792, 5793, 5794, 5795, 5796, 5797}
    local random_rollval = math.random(1,6)
    local total_g = (10000 * cc_count) + (100 * pc_count)
    local prize_percent = 1.0 -- 100%

    if ((total_g) <= 25000 and (total_g) >= 1000) then
        doSendMagicEffect(table_left_pos, CONST_ME_CRAPS)

        for _, itemId in pairs(dice_ids) do
                if(getTileItemById(table_left_pos, itemId).uid > 0) then
                doTransformItem(getTileItemById(table_left_pos, itemId).uid, dice_ids[random_rollval])
            end
        end

        if (roll == 1 and random_rollval <= 3) then
            placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
        elseif (roll == 2 and random_rollval >= 4) then
            placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
        else
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_BLOCKHIT)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_BLOCKHIT)
            addEvent(doCreatureSay, 500, npc, "Better luck next time.", TALKTYPE_SAY, false, 0)
        end
        doCreatureSay(npc, string.format("%s rolled a %d.", getCreatureName(npc), random_rollval), TALKTYPE_ORANGE_1, false, 0, table_left_pos)
    else
        addEvent(doCreateItem, 100, 2160, cc_count, table_middle_pos)
        addEvent(doCreateItem, 150, 2152, pc_count, table_middle_pos)
        doCreatureSay(npc, "The minimum wager is 1k and the maximum wager is 25k.", TALKTYPE_SAY, false, 0)
    end
    return true
end

function creatureSayCallback(cid, type, msg)
    -- NPC userdata instance
    local npc = getNpcCid()

    -- Participating player userdata instance
    local position = {x = getNpcPos().x+2, y = getNpcPos().y, z = getNpcPos().z}
    position.stackpos = STACKPOS_TOP_CREATURE
    local player_uid = getThingfromPos(position).uid

    -- Game table position userdata instances
    local table_left_pos = {x = 32105, y = 32188, z = 7}
    local table_middle_pos = {x = 32106, y = 32188, z = 7}

    -- Search for coins on the left and middle tables and create item userdata instances
    local table_middle_cc = getTileItemById(table_middle_pos, 2160)
    local table_middle_pc = getTileItemById(table_middle_pos, 2152)

    -- Other variables
    local cc_count = 0
    local pc_count = 0
    local ROLL, LOW, HIGH = 0, 1, 2

    if (player_uid ~= 0) then
        if ((msgcontains(string.lower(msg), 'high') or msgcontains(string.lower(msg), 'h')) and (isPlayer(player_uid) and player_uid == cid)) then
            ROLL = HIGH
        elseif ((msgcontains(string.lower(msg), 'low') or msgcontains(string.lower(msg), 'l')) and (isPlayer(player_uid) and player_uid == cid)) then
            ROLL = LOW
        else
            return false
        end
        if (table_middle_cc.uid ~= 0) then
            cc_count = table_middle_cc.type
            doTeleportThing(table_middle_cc.uid, table_left_pos)
            addEvent(delayMoneyRemoval, 300, 2160, table_left_pos)
        end
        if (table_middle_pc.uid ~= 0) then
            pc_count = table_middle_pc.type
            doTeleportThing(table_middle_pc.uid, table_left_pos)
            addEvent(delayMoneyRemoval, 300, 2152, table_left_pos)
        end
        addEvent(rollDice, 500, ROLL, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
    else
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
Well i had my uncle fix it cause it didnt work for me, if people have same problem as me here is the script ^^

works for TFS 1.0 (10.76-77 + 10.80-82)
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
function onThink()                          npcHandler:onThink() end

local function delayMoneyRemoval(item, pos)
    doRemoveItem(getTileItemById(pos, item).uid)
    return true
end

local function placeMoney(amount, table_middle_pos)
    local remain = amount
    local crystal_coins = 0
    local platinum_coins = 0

    if (math.floor(amount / 10000) >= 1) then
        crystal_coins = math.floor(amount / 10000)
        remain = remain - crystal_coins * 10000
    end
    if ((remain / 100) >= 1) then
        platinum_coins = remain / 100
    end
    addEvent(doCreateItem, 550, 2152, platinum_coins, table_middle_pos)
    addEvent(doCreateItem, 600, 2160, crystal_coins, table_middle_pos)
end

local function rollDice(roll, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
    local dice_ids = {5792, 5793, 5794, 5795, 5796, 5797}
    local random_rollval = math.random(1,6)
    local total_g = (10000 * cc_count) + (100 * pc_count)
    local prize_percent = 1.0 -- 100%

    if ((total_g) <= 25000 and (total_g) >= 1000) then
        doSendMagicEffect(table_left_pos, CONST_ME_CRAPS)

        for _, itemId in pairs(dice_ids) do
                if(getTileItemById(table_left_pos, itemId).uid > 0) then
                doTransformItem(getTileItemById(table_left_pos, itemId).uid, dice_ids[random_rollval])
            end
        end

        if (roll == 1 and random_rollval <= 3) then
            placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
        elseif (roll == 2 and random_rollval >= 4) then
            placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
            addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
        else
            addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_BLOCKHIT)
            addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_BLOCKHIT)
            addEvent(doCreatureSay, 500, npc, "Better luck next time.", TALKTYPE_SAY, false, 0)
        end
        doCreatureSay(npc, string.format("%s rolled a %d.", getCreatureName(npc), random_rollval), TALKTYPE_ORANGE_1, false, 0, table_left_pos)
    else
        addEvent(doCreateItem, 100, 2160, cc_count, table_middle_pos)
        addEvent(doCreateItem, 150, 2152, pc_count, table_middle_pos)
        doCreatureSay(npc, "The minimum wager is 1k and the maximum wager is 25k.", TALKTYPE_SAY, false, 0)
    end
    return true
end

function creatureSayCallback(cid, type, msg)
    -- NPC userdata instance
    local npc = getNpcCid()

    -- Participating player userdata instance
    local position = {x = getNpcPos().x+2, y = getNpcPos().y, z = getNpcPos().z}
    position.stackpos = STACKPOS_TOP_CREATURE
    local player_uid = getThingfromPos(position).uid

    -- Game table position userdata instances
    local table_left_pos = {x = 32105, y = 32188, z = 7}
    local table_middle_pos = {x = 32106, y = 32188, z = 7}

    -- Search for coins on the left and middle tables and create item userdata instances
    local table_middle_cc = getTileItemById(table_middle_pos, 2160)
    local table_middle_pc = getTileItemById(table_middle_pos, 2152)

    -- Other variables
    local cc_count = 0
    local pc_count = 0
    local ROLL, LOW, HIGH = 0, 1, 2

    if (player_uid ~= 0) then
        if ((msgcontains(string.lower(msg), 'high') or msgcontains(string.lower(msg), 'h')) and (isPlayer(player_uid) and player_uid == cid)) then
            ROLL = HIGH
        elseif ((msgcontains(string.lower(msg), 'low') or msgcontains(string.lower(msg), 'l')) and (isPlayer(player_uid) and player_uid == cid)) then
            ROLL = LOW
        else
            return false
        end
        if (table_middle_cc.uid ~= 0) then
            cc_count = table_middle_cc.type
            doTeleportThing(table_middle_cc.uid, table_left_pos)
            addEvent(delayMoneyRemoval, 300, 2160, table_left_pos)
        end
        if (table_middle_pc.uid ~= 0) then
            pc_count = table_middle_pc.type
            doTeleportThing(table_middle_pc.uid, table_left_pos)
            addEvent(delayMoneyRemoval, 300, 2152, table_left_pos)
        end
        addEvent(rollDice, 500, ROLL, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
    else
        return false
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

How i can change the min and max bet?
 
Question, can you update to also remove trash over the dice? just excluding the dice adding a local value and do something like this:

Code:
local dicePosition = Position(npcPosition.x, npcPosition.y - 1, npcPosition.z)
if not isInArray({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN, ITEM_BLOCKING, ITEM_DICE }, itemId) and ItemType(itemId):isMovable() then

Tried by myself but now working, i keep testing

Also, instead of removing item, move back to +1 space to the right? incase player move an important item by accident (that one i don't know how)
 
Question, can you update to also remove trash over the dice? just excluding the dice adding a local value and do something like this:

Code:
local dicePosition = Position(npcPosition.x, npcPosition.y - 1, npcPosition.z)
if not isInArray({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN, ITEM_BLOCKING, ITEM_DICE }, itemId) and ItemType(itemId):isMovable() then

Tried by myself but now working, i keep testing

Also, instead of removing item, move back to +1 space to the right? incase player move an important item by accident (that one i don't know how)
Done and also improved the anti-cheat.
 
Done and also improved the anti-cheat.

Thanks Printer :)

Edit:

Now i can cheat using the Browse Field, before the edition i couldnt :(
Now it removes from dice spot too, thanks, but is possible to make the npc move the item instead of delete?

Thanks in advance
 
Last edited:
Can someone help me with getting the code for the NPC as well?
 
Can someone help me with getting the code for the NPC as well?

Use a basic one...

Here's mine:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Gambler" script="gambler.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100" />
    <look type="139" head="20" body="39" legs="45" feet="7" addons="0" />
</npc>

Just change the look type as u wish, as the name and the script name ofc...
 
Use a basic one...

Here's mine:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Gambler" script="gambler.lua" walkinterval="0" floorchange="0">
    <health now="100" max="100" />
    <look type="139" head="20" body="39" legs="45" feet="7" addons="0" />
</npc>

Just change the look type as u wish, as the name and the script name ofc...

Thanks man!!
 
Last edited:
This looks great! Will try it out when i get home from work :)


Now i use this on my server and i have lots of fun with it haha :) its nice to just stand in depot win some money for fun :) woorks great btw
 
Last edited:
Anyone having trouble with the max bet above 500,000? If you bet 1,000,000, max payout is 1,000,100 :/
 
Players can cheat using "browse field" fast if they bet and fastly take money to their bp from browse field. Would it be possible to edit like "u place money at center table, NPC takes it, then u call your bet and after that he gives you money or not"?
 
@yug0 You can make the position that the player has to put the gold in front of the NPC instead of between the two players.
 
Back
Top