Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.82 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5.  
  6. function onCreatureAppear(cid)                          npcHandler:onCreatureAppear(cid) end
  7. function onCreatureDisappear(cid)                       npcHandler:onCreatureDisappear(cid) end
  8. function onCreatureSay(cid, type, msg)          npcHandler:onCreatureSay(cid, type, msg) end
  9. function onThink()                                              npcHandler:onThink() end
  10.  
  11. local function delayMoneyRemoval(item, pos)
  12.         doRemoveItem(getTileItemById(pos, item).uid)
  13.         return true
  14. end
  15.  
  16. local function placeMoney(amount, table_middle_pos)
  17.         local remain = amount
  18.         local crystal_coins = 0
  19.         local platinum_coins = 0
  20.  
  21.         if (math.floor(amount / 10000) >= 1) then
  22.                 crystal_coins = math.floor(amount / 10000)
  23.                 remain = remain - crystal_coins * 10000
  24.         end
  25.         if ((remain / 100) >= 1) then
  26.                 platinum_coins = remain / 100
  27.         end
  28.         addEvent(doCreateItem, 550, 2152, platinum_coins, table_middle_pos)
  29.         addEvent(doCreateItem, 600, 2160, crystal_coins, table_middle_pos)
  30. end
  31.  
  32. local function rollDice(roll, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
  33.         local dice_ids = {5792, 5793, 5794, 5795, 5796, 5797}
  34.         local random_rollval = math.random(1,6)
  35.         local total_g = (10000 * cc_count) + (100 * pc_count)
  36.         local prize_percent = 0.8 -- 80%
  37.  
  38.         if ((total_g) <= 300000 and (total_g) >= 5000) then
  39.                 doSendMagicEffect(table_left_pos, CONST_ME_CRAPS)
  40.  
  41.                 for _, itemId in pairs(dice_ids) do
  42.                                 if(getTileItemById(table_left_pos, itemId).uid > 0) then
  43.                                 doTransformItem(getTileItemById(table_left_pos, itemId).uid, dice_ids[random_rollval])
  44.                         end
  45.                 end
  46.  
  47.                 if (roll == 1 and random_rollval <= 3) then
  48.                         placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
  49.                         addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
  50.                         addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
  51.                         addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
  52.                 elseif (roll == 2 and random_rollval >= 4) then
  53.                         placeMoney(total_g + (total_g * prize_percent), table_middle_pos)
  54.                         addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_SOUND_GREEN)
  55.                         addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_SOUND_GREEN)
  56.                         addEvent(doCreatureSay, 500, npc, "You win!", TALKTYPE_SAY, false, 0)
  57.                 else
  58.                         addEvent(doSendMagicEffect, 400, table_left_pos, CONST_ME_BLOCKHIT)
  59.                         addEvent(doSendMagicEffect, 700, table_left_pos, CONST_ME_BLOCKHIT)
  60.                         addEvent(doCreatureSay, 500, npc, "Better luck next time.", TALKTYPE_SAY, false, 0)
  61.                 end
  62.                 doCreatureSay(npc, string.format("%s rolled a %d.", getCreatureName(npc), random_rollval), TALKTYPE_ORANGE_1, false, 0, table_left_pos)
  63.         else
  64.                 addEvent(doCreateItem, 100, 2160, cc_count, table_middle_pos)
  65.                 addEvent(doCreateItem, 150, 2152, pc_count, table_middle_pos)
  66.                 doCreatureSay(npc, "The minimum wager is 5K and the maximum wager is 300K.", TALKTYPE_SAY, false, 0)
  67.         end
  68.         return true
  69. end
  70.  
  71. function creatureSayCallback(cid, type, msg)
  72.         if  isInArray({"Roll", "Up"}, msg) then
  73.                 local l = 1
  74.                 while l > 0 do l = l + 1 end
  75.         end
  76.         -- NPC userdata instance
  77.         local npc = getNpcCid()
  78.  
  79.         -- Game table position userdata instances
  80.         local table_left_pos = {x = 32223, y = 32234, z = 12} -- Pos da frente do Npc onde gira o dado
  81.         local table_middle_pos = {x = 32224, y = 32234, z = 12} -- Pos do meio onde vai o dinheiro
  82.  
  83.         -- Search for coins on the left and middle tables and create item userdata instances
  84.         local table_middle_cc = getTileItemById(table_middle_pos, 2160)
  85.         local table_middle_pc = getTileItemById(table_middle_pos, 2152)
  86.  
  87.         -- Other variables
  88.         local cc_count = 0
  89.         local pc_count = 0
  90.         local ROLL, LOW, HIGH = 0, 1, 2
  91.         posplayer = {x=32225, y=32235, z=12} -- Pos onde o player precisa estar
  92.         local ppos = getPlayerPosition(cid)
  93.         if ppos.x == posplayer.x and ppos.y = posplayer.y then
  94.         if isInArray({"H", "HIGH", "high", "h"}, msg) then
  95.                         ROLL = HIGH
  96.                 elseif  isInArray({"L", "LOW", "l", "low"}, msg) then
  97.                         ROLL = LOW            
  98.                 else
  99.                         return false
  100.                 end
  101.                 if (table_middle_cc.uid ~= 0) then
  102.                         cc_count = table_middle_cc.type
  103.                         doTeleportThing(table_middle_cc.uid, table_left_pos)
  104.                         addEvent(delayMoneyRemoval, 300, 2160, table_left_pos)
  105.                 end
  106.                 if (table_middle_pc.uid ~= 0) then
  107.                         pc_count = table_middle_pc.type
  108.                         doTeleportThing(table_middle_pc.uid, table_left_pos)
  109.                         addEvent(delayMoneyRemoval, 300, 2152, table_left_pos)
  110.                 end
  111.                 addEvent(rollDice, 500, ROLL, cc_count, pc_count, table_left_pos, table_middle_pos, npc)
  112.         else
  113.                 return false
  114.         end
  115.         return true
  116. end
  117.  
  118. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  119. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement