• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Npc casino

lopez65

Member
Joined
May 10, 2012
Messages
294
Solutions
1
Reaction score
16
Location
Barcelona
Hi, I have a npc that I put on my server, and what happens to me is that there is a failure if someone can help me please and thank you. Bye greetings

Code:
Lua Script Error: [Npc interface]
data/npc/scripts/dicer.lua:onCreatureSay
data/npc/scripts/dicer.lua:39: attempt to call global 'getCreatureLookDirection'
(a nil value)
stack traceback:
        [C]: in function 'getCreatureLookDirection'
        data/npc/scripts/dicer.lua:39: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:426: in function 'onCreatureSay'
        data/npc/scripts/dicer.lua:8: in function <data/npc/scripts/dicer.lua:8>


I get that error when I'm going to use it

npc:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

local coins = {[2148] = 1, [2152] = 100, [2160] = 10000}

function countMoneyOnPos(pos)
local money = 0
for stack = 1, 255  do
  pos.stackpos = stack
  local item = getThingFromPos(pos)
  if item and item.uid > 0 then
   if coins[item.itemid] then
    money = money + coins[item.itemid] * item.type
   end
  end
end
return money
end

local posCoal = {x = 32913, y = 30636, z = 7} -- POSIÇÃO DO COAL, ONDE O GOLD DEVE ESTAR
local posNpc = {x = 32913, y = 30635, z = 7} -- POSIÇÃO DO NPC
local pos = getPosByDir(getThingPos(cid), getCreatureLookDirection(cid), 1) -- NÃO ALTERAR

if msgcontains(msg, 'l') or msgcontains(msg, 'L') or msgcontains(msg, 'low') or msgcontains(msg, 'Low') then
if countMoneyOnPos(pos) > 0 then
if math.random(1, 6) <= 3 then
doPlayerAddMoney(cid, countMoneyOnPos(pos)*2)
doSendMagicEffect(posNpc, 26)
doSendMagicEffect(posNpc, 28)
doCreatureSay(getNpcId(), getCreatureName(cid)..' tirou o numero '..math.random(1, 3)..', parabéns!', TALKTYPE_ORANGE_1)
else
doSendMagicEffect(posNpc, 2)
doSendMagicEffect(posNpc, 26)
doCreatureSay(getNpcId(), getCreatureName(cid)..' tirou o numero '..math.random(4, 6)..', tente novamente!', TALKTYPE_ORANGE_1)
end
for stack = 1, 255  do
  pos.stackpos = stack
  local item = getThingFromPos(pos)
  if item and item.uid > 0 then
   if coins[item.itemid] then
doRemoveItem(item.uid)
   end
  end
end
else
doCreatureSay(getNpcId(), getCreatureName(cid)..', coloque uma quantia de gold no recipiente para começar a apostar!', TALKTYPE_ORANGE_1)
end
elseif msgcontains(msg, 'h') or msgcontains(msg, 'H') or msgcontains(msg, 'high') or msgcontains(msg, 'High') then
if countMoneyOnPos(pos) > 0 then
if math.random(1, 6) <= 3 then
doPlayerAddMoney(cid, countMoneyOnPos(pos)*2)
doSendMagicEffect(posNpc, 26)
doSendMagicEffect(posNpc, 28)
doCreatureSay(getNpcId(), getCreatureName(cid)..' tirou o numero '..math.random(4, 6)..', parabéns!', TALKTYPE_ORANGE_1)
else
doSendMagicEffect(posNpc, 2)
doSendMagicEffect(posNpc, 26)
doCreatureSay(getNpcId(), getCreatureName(cid)..' tirou o numero '..math.random(1, 3)..', tente novamente!', TALKTYPE_ORANGE_1)
end
for stack = 1, 255  do
  pos.stackpos = stack
  local item = getThingFromPos(pos)
  if item and item.uid > 0 then
   if coins[item.itemid] then
doRemoveItem(item.uid)
   end
  end
end
else
doCreatureSay(getNpcId(), getCreatureName(cid)..', coloque uma quantia de gold no recipiente para começar a apostar!', TALKTYPE_ORANGE_1)
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

LUA:
<?xml version="1.0"?>
<npc name="Dicer" script="dicer.lua" walkinterval="1000" floorchange="0">
<health now="100" max="100"/>
<look type="132" head="114" body="0" legs="0" feet="114" addons="3"/>
<parameters>
<parameter key="message_greet" value="Ola {|PLAYERNAME|}, caso queria tentar a sorte diga {L} ou {Low} para apostar nos numeros {1}, {2} ou {3} ||| {H} ou {High} para apostar nos numeros {4}, {5} ou {6}!" />
</parameters>
</npc>

my server is 10.76 please help :)
 
if you're using tfs 1.2 use player:getDirection()
you have to have local player = Player(cid) in the creatureSayCallback though or else it wont work
 
new error

LUA:
Lua Script Error: [Npc interface]
data/npc/scripts/dicer.lua:onCreatureSay
data/npc/scripts/dicer.lua:39: attempt to index global 'player' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/npc/scripts/dicer.lua:39: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:426: in function 'onCreatureSay'
        data/npc/scripts/dicer.lua:8: in function <data/npc/scripts/dicer.lua:8>


I put on the line what I said aora I get this error
 
Hello again maybe under your point of view be a rookie but I do not give the explanation or do not understand if someone can modify me I noticed that you touched to learn thanks :(
 
Hello again maybe under your point of view be a rookie but I do not give the explanation or do not understand if someone can modify me I noticed that you touched to learn thanks :(

try changing

Code:
local pos = getPosByDir(getThingPos(cid), getCreatureLookDirection(cid), 1) -- NÃO ALTERAR

to

Code:
local pos = getPosByDir(getThingPos(cid), Player(cid):getDirection(), 1) -- NÃO ALTERAR
 
Thanks, I've changed it but I get this


CSS:
Lua Script Error: [Npc interface]
data/npc/scripts/dicer.lua:onCreatureSay
data/npc/scripts/dicer.lua:39: attempt to call global 'getPosByDir' (a nil value
)
stack traceback:
        [C]: in function 'getPosByDir'
        data/npc/scripts/dicer.lua:39: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:426: in function 'onCreatureSay'
        data/npc/scripts/dicer.lua:8: in function <data/npc/scripts/dicer.lua:8>
 
This is the formula to work with 10.77 ^^

LUA:
 local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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) <= 500000 and (total_g) >= 30000) 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 30K and the maximum wager is 500K.", TALKTYPE_SAY, false, 0)
        end
        return true
end
function onThink()
    local cid = getNpcCid()
    local npc = Creature(cid)
    local npcpos = {x = 32348, y = 32219, z = 6}
   
    local creature = Tile(32350, 32219, 6):getTopCreature()
    if creature and creature:isPlayer() then
    selfTurn(EAST)
    --doCreatureSay(npc, "Hello |PLAYERNAME|, Do your bets.", TALKTYPE_SAY, false, 0)
    else
    selfTurn(SOUTH)
    --doCreatureSay(npc, "Goodbye |PLAYERNAME|!.", TALKTYPE_SAY, false, 0)
    end
   
    if npc then
        local outfit = npc:getOutfit()
        outfit.lookHead = math.random(0, 132)
        outfit.lookBody = math.random(0, 132)
        outfit.lookLegs = math.random(0, 132)
        outfit.lookFeet = math.random(0, 132)
        npc:setOutfit(outfit)
        addEvent(doSendMagicEffect, 700, npcpos, CONST_ME_GIFT_WRAPS)
    end
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)

       -- if  isInArray({"Roll", "Up"}, msg) then
              --  local l = 1
              --  while l > 0 do l = l + 1 end
      --  end
        -- NPC userdata instance
        local npc = getNpcCid()
        -- Game table position userdata instances
        local table_left_pos = {x = 32913, y = 30635, z = 7} -- Pos da frente do Npc onde gira o dado 32008, 31897, 7
        local table_middle_pos = {x = 32913, y = 30636, z = 7} -- Pos do meio onde vai o dinheiro 32009, 31897, 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
        posplayer = {x = 32913, y = 30637, z = 7} -- Pos onde o player precisa estar 32010, 31898, 7
                local ppos = getPlayerPosition(cid)
        if ppos.x == posplayer.x and ppos.y == posplayer.y then
        if isInArray({"H", "HIGH", "high", "h"}, msg) then
                        ROLL = HIGH
                elseif  isInArray({"L", "LOW", "l", "low"}, msg) then
                        ROLL = LOW
elseif  isInArray({"play", "game"}, msg) then
doCreatureSay(npc, "Ola, vamos jogar? low ou high? Sendo Low=1,2,3 e High=4,5,6.", TALKTYPE_SAY, false, 0) 

                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)
--npcHandler:addModule(FocusModule:new())

Thanks for your inconvenience
 
This is the formula to work with 10.77 ^^

LUA:
 local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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) <= 500000 and (total_g) >= 30000) 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 30K and the maximum wager is 500K.", TALKTYPE_SAY, false, 0)
        end
        return true
end
function onThink()
    local cid = getNpcCid()
    local npc = Creature(cid)
    local npcpos = {x = 32348, y = 32219, z = 6}
 
    local creature = Tile(32350, 32219, 6):getTopCreature()
    if creature and creature:isPlayer() then
    selfTurn(EAST)
    --doCreatureSay(npc, "Hello |PLAYERNAME|, Do your bets.", TALKTYPE_SAY, false, 0)
    else
    selfTurn(SOUTH)
    --doCreatureSay(npc, "Goodbye |PLAYERNAME|!.", TALKTYPE_SAY, false, 0)
    end
 
    if npc then
        local outfit = npc:getOutfit()
        outfit.lookHead = math.random(0, 132)
        outfit.lookBody = math.random(0, 132)
        outfit.lookLegs = math.random(0, 132)
        outfit.lookFeet = math.random(0, 132)
        npc:setOutfit(outfit)
        addEvent(doSendMagicEffect, 700, npcpos, CONST_ME_GIFT_WRAPS)
    end
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)

       -- if  isInArray({"Roll", "Up"}, msg) then
              --  local l = 1
              --  while l > 0 do l = l + 1 end
      --  end
        -- NPC userdata instance
        local npc = getNpcCid()
        -- Game table position userdata instances
        local table_left_pos = {x = 32913, y = 30635, z = 7} -- Pos da frente do Npc onde gira o dado 32008, 31897, 7
        local table_middle_pos = {x = 32913, y = 30636, z = 7} -- Pos do meio onde vai o dinheiro 32009, 31897, 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
        posplayer = {x = 32913, y = 30637, z = 7} -- Pos onde o player precisa estar 32010, 31898, 7
                local ppos = getPlayerPosition(cid)
        if ppos.x == posplayer.x and ppos.y == posplayer.y then
        if isInArray({"H", "HIGH", "high", "h"}, msg) then
                        ROLL = HIGH
                elseif  isInArray({"L", "LOW", "l", "low"}, msg) then
                        ROLL = LOW
elseif  isInArray({"play", "game"}, msg) then
doCreatureSay(npc, "Ola, vamos jogar? low ou high? Sendo Low=1,2,3 e High=4,5,6.", TALKTYPE_SAY, false, 0)

                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)
--npcHandler:addModule(FocusModule:new())

Thanks for your inconvenience

have fun getting future help from people
XDDDDDDDDDD
 

Similar threads

  • Question Question
Replies
0
Views
174
Back
Top