Postado Dezembro 13, 2015 9 anos Preview Informações Configuravel quantidade minima e máxima de aposta. Configuravel bonus caso a pessoa ganhe a aposta. Não é necessário editar a posição, apenas deixe o NPC à esquerda e o player à direita. Conversão automática do money. Anti-Trash. Script <?xml version="1.0" encoding="UTF-8"?> <npc name="Dicer" script="dicer.lua" walkinterval="0" floorchange="0"> <health now="100" max="100"/> <look type="144" head="0" body="0" legs="0" feet="0" addons="0"/> </npc> 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, minimumBet = 100, maximumBet = 10000000 } local storeMoneyAmount = 0 -- Do not touch [We store the amount cash which got betted here] local function getMoneyAmount(position) local moneyAmount = 0 for _, item in ipairs(Tile(position):getItems()) do local itemId = item:getId() if itemId == ITEM_GOLD_COIN then moneyAmount = moneyAmount + item.type elseif itemId == ITEM_PLATINUM_COIN then moneyAmount = moneyAmount + item.type * 100 elseif itemId == ITEM_CRYSTAL_COIN then moneyAmount = moneyAmount + item.type * 10000 end end storeMoneyAmount = moneyAmount return moneyAmount end local function handleMoney(cid, position, bonus) -- Lets remove the cash which was betted for _, item in ipairs(Tile(position):getItems()) do if isInArray({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN}, item:getId()) then item:remove() end end local npc = Npc(cid) if not npc then return end -- We lost, no need to continue if bonus == 0 then npc:say("You lost!", TALKTYPE_SAY) position:sendMagicEffect(CONST_ME_POFF) return end -- Cash calculator local goldCoinAmount = storeMoneyAmount * bonus local crystalCoinAmount = math.floor(goldCoinAmount / 10000) goldCoinAmount = goldCoinAmount - crystalCoinAmount * 10000 local platinumCoinAmount = math.floor(goldCoinAmount / 100) goldCoinAmount = goldCoinAmount - platinumCoinAmount * 100 if goldCoinAmount > 0 then Game.createItem(ITEM_GOLD_COIN, goldCoinAmount, position) end if platinumCoinAmount > 0 then Game.createItem(ITEM_PLATINUM_COIN, platinumCoinAmount, position) end if crystalCoinAmount > 0 then Game.createItem(ITEM_CRYSTAL_COIN, crystalCoinAmount, position) end position:sendMagicEffect(math.random(CONST_ME_FIREWORK_YELLOW, CONST_ME_FIREWORK_BLUE)) npc:say("You Win!", TALKTYPE_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 creatureSayCallback(cid, type, msg) -- 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 npc:say("Please go stand next to me.", TALKTYPE_SAY) 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 -- Check money Got betted local moneyPosition = Position(npcPosition.x + 1, npcPosition.y - 1, npcPosition.z) if getMoneyAmount(moneyPosition) < config.minimumBet or getMoneyAmount(moneyPosition) > config.maximumBet then npc:say(string.format("You can only bet min: %d and max: %d gold coins.", config.minimumBet, config.maximumBet), TALKTYPE_SAY) return false end -- High or Low numbers local rollType = 0 if msgcontains(msg, "low") then rollType = 1 elseif msgcontains(msg, "high") then rollType = 2 else return false end -- Roll Number local rollNumber = math.random(6) -- Dice local dicePosition = Position(npcPosition.x, npcPosition.y - 1, npcPosition.z) addEvent(startRollDice, 500, npc:getId(), dicePosition, rollNumber) dicePosition:sendMagicEffect(CONST_ME_CRAPS) rolledDice = true -- 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 end -- Money Handeling addEvent(handleMoney, 700, npc:getId(), moneyPosition, bonus) return true end function onThink() local npcPosition = Npc():getPosition() local moneyPosition = Position(npcPosition.x + 1, npcPosition.y - 1, npcPosition.z) for _, item in ipairs(Tile(moneyPosition):getItems()) do if not isInArray({ITEM_GOLD_COIN, ITEM_PLATINUM_COIN, ITEM_CRYSTAL_COIN}, item:getId()) and ItemType(item:getId()):isMovable() then item:remove() end end npcHandler:onThink() end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) Créditos à Printer.
Postado Dezembro 25, 2015 9 anos Autor @G3 Yuri Tem certeza que seu TFS é 1.x? Aqui funcionou normal...
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.