• 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 The Gambling Man, the interactive dicer

Yeh dude, just give a try, if you have any error, try to read it, understand it, and fix it... otherwise post it here and we will try to help you.
 
Did not work on 0.4 r3884.
Error:
Code:
[14:26:05.992] [Error - NpcScript Interface]
[14:26:05.992] In a timer event called from:
[14:26:05.992] data/npc/scripts/dice_gamble.lua:onCreatureSay
[14:26:05.992] Description:
[14:26:05.992] (luaDoCreateItem) Tile not found

Wherever i threw out the cash he wouldn't accept it, think i got everything right.
 
Works great! I love it! This game is so addicting >.< !
 
I love it, fucking amazing. I'm having one problem however. If players place let's say like 500cc in the middle_pos then they stack 30cc on the top after thay they spam high/low the server crashes.

Any idea how i can prevent that from happening?

Like is there a way where i can make it so if the player tries to place more than 30cc in the middle stack then it will deny them and send them a cancel message. Even if it's a seperate script where I can just add the XYZ coordinates of the middle_pos

@Evan
@Ninja
@Limos

Thanks for your time
 
Last edited:
@Evan I have TFS 0.3.6

and getting this error

Code:
[05/06/2014 15:05:27] [Error - Npc interface] 
[05/06/2014 15:05:27] data/npc/scripts/interactivedicer.lua:onCreatureSay
[05/06/2014 15:05:27] Description: 
[05/06/2014 15:05:27] data/npc/scripts/interactivedicer.lua:70: attempt to call global 'Npc' (a nil value)
[05/06/2014 15:05:27] stack traceback:
[05/06/2014 15:05:27]     data/npc/scripts/interactivedicer.lua:70: in function 'callback'
[05/06/2014 15:05:27]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[05/06/2014 15:05:27]     data/npc/scripts/interactivedicer.lua:7: in function <data/npc/scripts/interactivedicer.lua:7>

Trying to talk!
 
Last edited:
hey, im using TFS 1.0 and i have an error which says > expected near then
(on this line)

Code:
if ((msgcontains(string.lower(msg), 'high') and (player:isPlayer() and player:getId() == cid)) then
ROLL = HIGH
elseif ((msgcontains(string.lower(msg), 'low') and (player:isPlayer() and player:getId() == cid)) then
ROLL = LOW
else
 
hey, im using TFS 1.0 and i have an error which says > expected near then
(on this line)

Code:
if ((msgcontains(string.lower(msg), 'high') and (player:isPlayer() and player:getId() == cid)) then
ROLL = HIGH
elseif ((msgcontains(string.lower(msg), 'low') and (player:isPlayer() and player:getId() == cid)) then
ROLL = LOW
else

Use this

Code:
    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
 
@Evan I have TFS 0.3.6

and getting this error

Code:
[05/06/2014 15:05:27] [Error - Npc interface]
[05/06/2014 15:05:27] data/npc/scripts/interactivedicer.lua:onCreatureSay
[05/06/2014 15:05:27] Description:
[05/06/2014 15:05:27] data/npc/scripts/interactivedicer.lua:70: attempt to call global 'Npc' (a nil value)
[05/06/2014 15:05:27] stack traceback:
[05/06/2014 15:05:27]     data/npc/scripts/interactivedicer.lua:70: in function 'callback'
[05/06/2014 15:05:27]     data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay'
[05/06/2014 15:05:27]     data/npc/scripts/interactivedicer.lua:7: in function <data/npc/scripts/interactivedicer.lua:7>

Trying to talk!

The script is only for 1.0, not 0.3.6. If you want to use it in 0.3.6, use Xagul's post (2nd post in this thread). That's why Npc is not found, it just doesn't exist in 0.3.6.
 
The script is only for 1.0, not 0.3.6. If you want to use it in 0.3.6, use Xagul's post (2nd post in this thread). That's why Npc is not found, it just doesn't exist in 0.3.6.

I used his and I get this error when writing Hi to the NPC :/

@Xagul

can you fix it?
 
First of all, thank for the script, its working fine on 1.o, buy i have a little bug, if i throw the money in the same sqm of dice (for error of course) the npc don't give back me the money, (the system keep working, but you can't get your money from top op the dice. if you can solve i will be agreed, thank you for all!
!
 
Pretty awesome npc!


Edit:
For those of you interested, here is the script converted for older versions of TFS (semi-tested on 0.4) Please do not nag Evan for support with this, I am just providing it AS IS for those of you who would like a jump start on the conversion.
I think I changed everything that needs to be but make sure to test well before use.

Edit 2:
Btw Evan, it really annoyed me that he didn't say if you win or lose (even though it is sorta obvious if u don't get money back) but I added it anyway. :)

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 = 0.8 -- 80%

    if ((total_g) <= 300000 and (total_g) >= 5000) 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 5K and the maximum wager is 300K.", 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 = 120, y = 50, z = 7}
    local table_middle_pos = {x = 121, y = 50, 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)
does this work on 0.3.6
 
80% of these replies are regarding 0.3 and 0.4 :(


really nice work evan, will definitely use on my server :)
 
yes, and it work. but it's always better to ask if it work and not test it and complaining about all the bugs ....
It's better to test and see if it works. Then if it does not work, politely ask if someone could help make it work and of course post the errors/bugs.

The reason I say this is because what I got out of your post was:
"Hey I am too lazy to copy and paste this script into my server to see if it works, could you do it for me and tell me if it works so I can do it myself once you confirm it is a possibility."
I do apologize if I was mistaken in that assumption however I do not feel I was alone in that thinking as in nearly 2 days the only responses you received were trolls.
 
Back
Top