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

Lua Dicer Npc script tfs 0.3.7

Blysco

New Member
Joined
Oct 12, 2013
Messages
163
Reaction score
2
Hey, ive tried this : http://otland.net/threads/the-gambling-man-the-interactive-dicer.197833/#post-1904704
But the script dont works for me, i get no errors but the Npc dont turn himself around and dont take the money.
He cann only say 1 sentence. Min 5k max 300k blablabla.
At the moment i use this :
Code:
NPC = <?xml version="1.0" encoding="UTF-8"?>
<npc name="The Gambling Man" script="data/npc/scripts/dice_gamble.lua" walkinterval="0" floorchange="0">
<health now="100" max="100"/>
<look type="494" head="38" body="87" legs="46" feet="46" addons="3"/>
</npc>

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

function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
function onPlayerEndTrade(cid) npcHandler:eek:nPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid) npcHandler:eek:nPlayerCloseChannel(cid) end

local function delayMoneyRemoval(delayRemovedItem)
delayRemovedItem:remove(delayRemovedItem:getCount())
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
table_left_pos:sendMagicEffect(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(Position.sendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
addEvent(Position.sendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
elseif (roll == 2 and random_rollval >= 4) then
placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
addEvent(Position.sendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
addEvent(Position.sendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
else
addEvent(Position.sendMagicEffect, 400, table_left_pos, CONST_ME_BLOCKHIT)
addEvent(Position.sendMagicEffect, 700, table_left_pos, CONST_ME_BLOCKHIT)
end
npc:say(string.format("%s rolled a %d.", npc:getName(), random_rollval), TALKTYPE_ORANGE_1, false, 0, npc:getPosition())
else
addEvent(doCreateItem, 100, 2160, cc_count, table_middle_pos)
addEvent(doCreateItem, 150, 2152, pc_count, table_middle_pos)
npc:say("The minimum wager is 5K and the maximum wager is 300K.", TALKTYPE_SAY, false, 0, npc:getPosition())
end
return true
end

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

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

-- Game table position userdata instances
local table_left_pos = Position(1110, 994, 8)
local table_middle_pos = Position(1111, 994, 8)

-- Search for coins on the left and middle tables and create item userdata instances
local table_left_cc_uid = getTileItemById(table_left_pos, 2160).uid
local table_middle_cc_uid = getTileItemById(table_middle_pos, 2160).uid
local table_left_pc_uid = getTileItemById(table_left_pos, 2152).uid
local table_middle_pc_uid = getTileItemById(table_middle_pos, 2152).uid

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

if (player_uid ~= 0) then
player = Player(player_uid)
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
return false
end
if (table_middle_cc_uid ~= 0) then
table_middle_cc = Item(table_middle_cc_uid)
cc_count = table_middle_cc:getCount()
table_middle_cc:moveTo(table_left_pos)
addEvent(delayMoneyRemoval, 300, table_middle_cc)
end
if (table_middle_pc_uid ~= 0) then
table_middle_pc = Item(table_middle_pc_uid)
pc_count = table_middle_pc:getCount()
table_middle_pc:moveTo(table_left_pos)
addEvent(delayMoneyRemoval, 300, table_middle_pc)
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)
end
end
Could someone give me or make me a Npc Gambling Script ?
For Dice Games.
Would be awseome thanks
 
Last edited:
Okay i brought it to work.
But the Item remover Script wont for me.
Please give me some solutions how to fix it or give me another script to use.
I use Tfs 0.3.7
The console give me no errors.
Moveevents
Code:
    <movevent event="AddItem" pos="591;652;7" script="trash_prevent.lua"/>
    <movevent event="AddItem" pos="591;651;7" script="trash_prevent.lua"/>
<movevent event="AddItem" pos="592;652;7" script="trash_prevent.lua"/>

trash_prevent.lua
Code:
local item_exceptions = {2152, 2160, 5792, 5793, 5794, 5795, 5796, 5797}

function onAddItem(item, tile, pos)
if not isInArray(item_exceptions, item.itemid) then
doTeleportThing(item.uid, {x = pos.x + 1, y = pos.y, z = pos.z})
end
return true
end
 
Try with
Code:
<movevent type="AddItem" pos="591;652;7" event="script" value="trash_prevent.lua"/> 
<movevent type="AddItem" pos="591;651;7" event="script" value="trash_prevent.lua"/> 
<movevent type="AddItem" pos="592;652;7" event="script" value="trash_prevent.lua"/>
 
Try with
Code:
<movevent type="AddItem" pos="591;652;7" event="script" value="trash_prevent.lua"/>
<movevent type="AddItem" pos="591;651;7" event="script" value="trash_prevent.lua"/>
<movevent type="AddItem" pos="592;652;7" event="script" value="trash_prevent.lua"/>

Still dont works.
 
Back
Top