Advertisement
tok124

roll command

Oct 7th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. local command = "#roll"; -- command used
  2. local roll_item_ID = 60030; -- id of the roll item
  3. local ItemName = GetItemLink(roll_item_ID);
  4. local cost = 1;
  5. local remove_roll_item_delay = 100;
  6.  
  7. local Item_Drops = { -- {chance_Value {item_id_1, item_id_2, item_id_3, item_id_4, item_id_5....}},
  8.         [1] = {60,{49917, 45629}}, -- green 60% deop rate.
  9.         [2] = {30,{51997, 48945}}; -- blue 30% drop chance.
  10.         [3] = {10,{48737, 48738}}; -- purple 10% drop chance.
  11.     };
  12.  
  13. local time = tonumber(os.time());
  14. math.randomseed(time*time);
  15.  
  16. local function RemoveItemRollItem(event, _, _, player)
  17.  
  18.     player:RemoveItem(roll_item_ID, cost)
  19. end
  20.  
  21. local function ItemRoll(event, player, msg, Type, lang)
  22.  
  23.     if(msg == command)then
  24.  
  25.         if(player:HasItem(roll_item_ID, cost) == false)then
  26.             player:SendBroadcastMessage("You need "..cost.." of "..ItemName..".");
  27.         end
  28.  
  29.         if(player:HasItem(roll_item_ID, cost))then
  30.        
  31.             local roll = math.random(1, 100);
  32.             local chance = nil;
  33.             local comp = 0;
  34.            
  35.                 for comp = 1, #Item_Drops do
  36.            
  37.                     if(roll <= Item_Drops[comp][1])then
  38.                    
  39.                         chance = comp;
  40.                     end
  41.                 end
  42.  
  43.                 if(chance == nil)then
  44.                
  45.                      ItemRoll(event, player, msg, Type, lang);
  46.                 end
  47.            
  48.                 if(chance)then
  49.                
  50.                     local item = math.random(1, #Item_Drops[chance][2]);
  51.                    
  52.                         if(player:AddItem(Item_Drops[chance][2][item], 1)==true)then
  53.            
  54.                             player:RegisterEvent(RemoveItemRollItem, remove_roll_item_delay, 1, player);
  55.                         end
  56.                 end
  57.             end
  58.     return false;
  59.     end
  60. end
  61.  
  62. RegisterPlayerEvent (18, ItemRoll)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement