strutZ
Australian OT Member {AKA Beastn}
- Joined
- Nov 16, 2014
- Messages
- 1,393
- Solutions
- 7
- Reaction score
- 552
Hello Otland!
So I have been working on a modal window system that allows players to buy potions easier but i'm having some issues... If i buy 100 health potions then try and buy 100 of any other potion it will always give me health potions... Also is there a way to keep the window open until you press cancel? (i don't think so but maybe there is a trick i don't know)
ANYWAYS Here is the scripts. Thanks in advance.
action
Creature
So I have been working on a modal window system that allows players to buy potions easier but i'm having some issues... If i buy 100 health potions then try and buy 100 of any other potion it will always give me health potions... Also is there a way to keep the window open until you press cancel? (i don't think so but maybe there is a trick i don't know)
ANYWAYS Here is the scripts. Thanks in advance.
action
Code:
local potions = {
[1] = {potion = "Health Potion", itemID = 7618, price10 = 450, price50 = 2250, price100 = 4500},
[2] = {potion = "Strong Health Potion", itemID = 7588, price10 = 1000, price50 = 5000, price100 = 10000},
[3] = {potion = "Great Health Potion", itemID = 7591, price10 = 1900, price50 = 9500, price100 = 19000},
[4] = {potion = "Ultimate Health Potion", itemID = 8473, price10 = 3100, price50 = 15500, price100 = 31000},
[5] = {potion = "Supreme Health Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
[6] = {potion = "Mana Potion", itemID = 7620, price10 = 500, price50 = 2500, price100 = 5000},
[7] = {potion = "Strong Mana Potion", itemID = 7589, price10 = 800, price50 = 4000, price100 = 8000},
[8] = {potion = "Great Mana Potion", itemID = 7590, price10 = 1200, price50 = 6000, price100 = 12000},
[9] = {potion = "Ultimate Mana Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
[10] = {potion = "Great Spirit Potion", itemID = 8472, price10 = 1900, price50 = 9500, price100 = 19000},
[11] = {potion = "Ultimate Spirit Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
}
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
player:registerEvent("mwBuyPotions")
local title = "Choose your Potion"
local message = "Please select how many potions you would like to buy."
local window = ModalWindow(1000, title, message)
window:addButton(100, "Buy 50")
window:addButton(101, "Buy 100")
window:addButton(102, "Buy 10")
window:addButton(103, "Cancel")
window:setDefaultEnterButton(101)
window:setDefaultEscapeButton(103)
for i = 1, #potions do
local o = potions[i].potion
window:addChoice(i, o)
end
window:sendToPlayer(player)
return true
end
Creature
Code:
local potions = {
[1] = {potion = "Health Potion", itemID = 7618, price10 = 450, price50 = 2250, price100 = 4500},
[2] = {potion = "Strong Health Potion", itemID = 7588, price10 = 1000, price50 = 5000, price100 = 10000},
[3] = {potion = "Great Health Potion", itemID = 7591, price10 = 1900, price50 = 9500, price100 = 19000},
[4] = {potion = "Ultimate Health Potion", itemID = 8473, price10 = 3100, price50 = 15500, price100 = 31000},
[5] = {potion = "Supreme Health Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
[6] = {potion = "Mana Potion", itemID = 7620, price10 = 500, price50 = 2500, price100 = 5000},
[7] = {potion = "Strong Mana Potion", itemID = 7589, price10 = 800, price50 = 4000, price100 = 8000},
[8] = {potion = "Great Mana Potion", itemID = 7590, price10 = 1200, price50 = 6000, price100 = 12000},
[9] = {potion = "Ultimate Mana Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
[10] = {potion = "Great Spirit Potion", itemID = 8472, price10 = 1900, price50 = 9500, price100 = 19000},
[11] = {potion = "Ultimate Spirit Potion", itemID = 7618, price10 = 760, price50 = 760, price100 = 760},
}
local moneyMsg = "You do not have enough money!" -- This is the message the player will recieve when he does not have enough money.
local capacityMsg = "I need more cap" -- This is the message the player will recieve when he does not have enough capactiy.
local buyMsg = "You have bought "
function onModalWindow(player, modalWindowId, buttonId, choiceId)
player:unregisterEvent("mwBuyPotions")
if modalWindowId == 1000 then
-- Buy 50 Potions
if buttonId == 100 then
-- Check is player has enough money
if player:getMoney() < (potions[choiceId].price50) then
player:say(moneyMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Check if player has enough room/capacity to hold the items if true give items
local potionEx = Game.createItem(potions[choiceId].itemID, 50)
if player:addItemEx(potionEx) ~= RETURNVALUE_NOERROR then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:say(capacityMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Remove money from player and send buy confirmation
player:removeMoney(potions[choiceId].price50)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, buyMsg.."50x "..potions[choiceId].potion.."s")
-- Buy 100 Potions
elseif buttonId == 101 then
-- Check is player has enough money
if player:getMoney() < (potions[choiceId].price100) then
player:say(moneyMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Check if player has enough room/capacity to hold the items if true give items
local potionEx = Game.createItem(potions[choiceId].itemID, 100)
if player:addItemEx(potionEx) ~= RETURNVALUE_NOERROR then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:say(capacityMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Remove money from player and send buy confirmation
player:removeMoney(potions[choiceId].price100)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, buyMsg.."100x "..potions[choiceId].potion.."s")
-- Buy 10 Potions
elseif buttonId == 102 then
-- Check is player has enough money
if player:getMoney() < (potions[choiceId].price10) then
player:say(moneyMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Check if player has enough room/capacity to hold the items if true give items
local potionEx = Game.createItem(potions[choiceId].itemID, 10)
if player:addItemEx(potionEx) ~= RETURNVALUE_NOERROR then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:say(capacityMsg, TALKTYPE_MONSTER_SAY)
return true
end
-- Remove money from player and send buy confirmation
player:removeMoney(potions[choiceId].price10)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, buyMsg.."10x "..potions[choiceId].potion.."s")
end
end
end