psychonaut04
New Member
- Joined
- Mar 10, 2017
- Messages
- 5
- Reaction score
- 2
Lucky Coins
Lucky Coins is a system to configure certain creatures or all creatures of your server to drop Lucky Coins with a determined rate, so you can set items to be bought with Lucky Coins.
Instalation
creaturescripts.xml:
Lucky Coins is a system to configure certain creatures or all creatures of your server to drop Lucky Coins with a determined rate, so you can set items to be bought with Lucky Coins.
Instalation
creaturescripts.xml:
Code:
<event type="kill" name="LuckyPoints" script="luckypoints.lua"/>
<event type="ModalWindow" name="ModalWindow_LuckyCoins" script="modalluckycoins.lua"/>
talkactions.xml
Code:
<!-- lucky coins -->
<talkaction words="!luckycoins" separator=" " script="luckycoinstalk.lua" />
creaturescripts/scripts/
luckypoints.lua
luckypoints.lua
Lua:
--: Configs :--
local storage = 32143 --: Script Storage
local msg = "You have found a lucky coin, say !luckycoins for more info." --: Message when a player find a lucky coin
local showqtd = 1 --: Show coin quantity on above message? 1-Yes, 0-No
local qtdtext = "You have" --: Text can be changed here for translation
--: VISUAL :--
local enableeffect = 1 --: Show effects when user get a coin? 1-Yes, 0-No
local effect = CONST_ME_FERUMBRAS --: Effect to show, if enableeffect = 1
--: RATES :--
local boost = 1 --: Boots lucky coins rate by this value, don't works with ignorecfg/anycrate yet. 1 = 1x, 2 = 2x etc...
local anycreature = 1 --: All creatures can drop lucky coins. 0 - No, 1 - Yes.
local anycrate = 20 --: Lucky Coins drop rate on every creature 200 = 0,005%
local ignorecfg = 1 --: Ignore rates of below table? 1-Yes, 0-No
--: Note: with ignorecfg = 1 all rates will be from anycrate value
--: Change the monster, the name and the drop rate :--
local config = {
-- Higher value = Low drop rate. Drop Rate = 1 / chance
["Demon"] = {chance = 600}, -- 600 = 1/600
["Ferumbras"] = {chance = 30}, -- 30 = 1/30 etc
["Rat"] = {chance = 1}, -- 100% drop rate
["Rotworm"] = {chance = 2}, -- 50% drop rate
["Dog"] = {chance = 10} -- 10% drop rate
}
function onKill(cid, target, lastHit)
if (isPlayer(target)) then return true end
local monster = getCreatureName(target)
local rand
if (ignorecfg ~= 1) then
for index, arraymonster in ipairs(config) do
if ((arraymonster ~= monster) and (anycreature == 0)) then return true end
end
if (((config[monster])) == nil) then rand = anycrate else rand = ((config[monster].chance) / boost) end
else
rand = anycrate
end
local storageatual = getPlayerStorageValue(cid, storage)
local plural = "s"
local qtd = ""
if (rand < 1) then rand = 1 end
if (storageatual == 1) then plural = "" end
if (showqtd == 1) then qtd = " " .. qtdtext .. " " .. storageatual + 1 .. " lucky coin" .. plural .. "." end
if (math.random(rand) == 1) then
setPlayerStorageValue(cid, storage, storageatual + 1)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, msg .. qtd)
if (enableeffect == 1) then doSendMagicEffect(getPlayerPosition(cid), effect) end
end
return true
end
modalluckycoins.lua
Lua:
--: Configurações Gerais :--
local storage = 32143 --: Script storage, same as creaturescript luckypoints.lua and talkaction
local modalid = 1053 --: Same value on luckycoinstalk
function onModalWindow(player, modalWindowId, buttonId, choiceId)
player:unregisterEvent("ModalWindow_LuckyCoins")
if modalWindowId == modalid then
if buttonId == 100 and choiceId ~= nil and choiceId ~= 255 then
local itemprice = (lucky_items[ordem[choiceId]].price)
local pstorage = (player:getStorageValue(storage))
local itemid = (ordem[choiceId])
if ((pstorage) >= (itemprice)) then
player:setStorageValue(storage, (pstorage - itemprice))
player:addItem(itemid, 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You bought a " .. (ItemType(itemid):getName()) .. " for " .. (itemprice) .. " coin(s)." )
else
player:sendCancelMessage('You dont have enough lucky coins.')
end
end
end
end
talkactions/scripts/
luckycoinstalk.lua
Lua:
--: Configs :--
local storage = 32143 --: Script storage, same on all files
local msg = "Lucky Coins are used here to buy vip items by playing the game. You can buy it at our shop, tp at temple." --: Message to show
local msgtwo = "You can view your luckycoins by typing !luckycoins amount." --: If there's no param on command
local msgbuy = "These are the items that you can buy: Soft Boots"
local modalid = 1053 --: Same as luckycoinstalk
--: AMOUNT :--
local qtdtext = "You have" --: For translation issues
--: BUY :--
local title = "Buy items with your lucky coins!" --: Modal Title text
local message = "Click to buy a item!" --: Modal text
--: ITENS TO SELL FOR LUCKY COINS :--
-- [ITEM ID] = {price = <ITEM PRICE>},
lucky_items = {
[6132] = {price = 1}, -- SOFT BOOTS
[2514] = {price = 3}, -- MMS
[2537] = {price = 5}, -- Amazon Shield
[2499] = {price = 10}, -- Amazon Helmet
[2500] = {price = 100} -- Amazon Armor
}
ordem = {}
-- Limit of ~250 items i guess
function onSay(player, words, param)
local storageatual = player:getStorageValue(storage)
local plural = "s"
local qtd = ""
if (storageatual < 0) then storageatual = 0 player:setStorageValue(storage, 0) end
if (storageatual == 1) then plural = "" end
qtd = " " .. qtdtext .. " " .. storageatual .. " lucky coin" .. plural .. "."
if (param == "amount") then
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, qtd)
elseif (param == "buy") then
--if (onlypz == 1 and player:isPzLocked()) then player:sendCancelMessage('You are not in protection zone.') return false end adições futuras
for k in pairs (ordem) do ordem [k] = nil end
player:registerEvent("ModalWindow_LuckyCoins")
local window = ModalWindow(modalid, title, message .. qtd)
window:addButton(100, "Buy")
window:addButton(101, "Cancel")
for k in pairs(lucky_items) do
table.insert(ordem, k)
end
table.sort(ordem)
for i = 1, #ordem do
local k, v = ordem[i], lucky_items[ ordem[i] ]
window:addChoice(i, string.upper((ItemType(k):getName())) .. " - " .. lucky_items[k].price .. " " .. "lucky coin(s)")
end
window:setDefaultEnterButton(100)
window:setDefaultEscapeButton(101)
window:sendToPlayer(player)
else
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, msg .. " " .. msgtwo)
end
return false
end