Log in

View Full Version : lua scrip for event



taituvn
01-22-2017, 09:05 AM
MerchantsAndItems ={BlueDjinn = {"birthday backpack", "bar of chocolate", "stuffed dragon", "suprise bag"},GreenDjinn = {"Ancient Shield"},Rashid = {"wyvern Fang"},}BackpacksToSortTo ={BlueDjinn = "grey backpack",GreenDjinn = "grey Backpack",Rashid = "grey backpack",Others = "backpack",Main = "reward container"}function itemMoveHelper(contFrom, fromSpot, contTo)print("Moving from %s spot %d to %s", contFrom:Name(), fromSpot, contTo:Name())if (contTo:ItemCount() == contTo:ItemCapacity()) then --opens the next containerlocal openAt = contTo:ItemCount() - 1if (Item.isContainer(contTo:GetItemData(openAt).id)) thencontTo:UseItem(openAt, true)wait(1500)elseprint("No more room for items in %s. Please fix the problem and restart the script.", contTo:Name())wait(99999999)endendcontFrom:MoveIte mToContainer(fromSpot, contTo:Index(), contTo:ItemCapacity() - 1)endfunction itemFound(nameTable, itemId)local itemName = string.upper(Item.GetName(itemId))for _, name in pairs(nameTable) doif (itemName == string.upper(name)) thenreturn trueendendreturn falseendlocal error = falselocal backpacks = {}for merchant, bpName in pairs(BackpacksToSortTo) dobackpacks[merchant] = Container.GetByName(bpName)if (not backpacks[merchant]:isOpen()) thenerror = trueprint("You must open a %s as your %s backpack. Please fix the problem and restart the script.", bpName, merchant)breakendendif (not error) thenrepeatwhile (backpacks["Main"]:ItemCount() > 0) dolocal item = backpacks["Main"]:GetItemData(0)if (Item.isContainer(item.id) and backpacks["Main"]:ItemCount() == 1) then --open next backpack of lootbackpacks["Main"]:UseItem(backpacks["Main"]:ItemCount()-1, true)wait(1000)breakelse --move it the lootlocal foundBp = backpacks["Others"]for merchant, _ in pairs(MerchantsAndItems) doif (itemFound(MerchantsAndItems[merchant], item.id)) thenfoundBp = backpacks[merchant]breakendenditemMoveHelper(backpacks["Main"], 0, foundBp)wait(500, 900)endenduntil (backpacks["Main"]:ItemCount() == 10)end


how can fix it for open next reward box ? please help :D