Bom galera eu resolvi fazer o Vault System a pedido de um amigo meu e decidi compartilhar com vocês.
Testado em 8.60 TFS 0.4
EDIT -- O script foi arrumado, pois havia um bug que o player ganhava golds.
Vamos lá.
1° - Vá em data/actions/scripts e crie um arquivo chamado vault.lua, e dentro você coloca isso:
local vaultStorage = 99991 -- storage em que ficara armazenado os golds
------------------//* Functions //-------------------
local function getPlayerFreeSpace(cid) -- by MaTTch
local checkSlots, space = {3,5,6,10}, 0
local function getContainerFree(container)
local free = 0
if(not isContainer(container.uid)) then
return free
end
for i = 0, (getItemInfo(container.itemid).maxItems -1) do
local item = getContainerItem(container.uid, i)
if(item.itemid == 0) then
free = free + 1
elseif(isContainer(item.uid)) then
free = free + getContainerFree(item)
end
end
return free
end
for _, i in ipairs(checkSlots) do
local slotItem = getPlayerSlotItem(cid, i)
if(i ~= CONST_SLOT_BACKPACK and slotItem.itemid == 0) then
space = space + 1
elseif(isContainer(slotItem.uid)) then
space = space + getContainerFree(slotItem)
end
end
return space
end
local function withdrawMoneySecurity(cid, value, storage) -- by MaTTch
local storageMoney, countValue = getPlayerStorageValue(cid, storage), 0
local config = {
[1] = {ITEM_CRYSTAL_COIN, math.floor(value/getItemInfo(ITEM_CRYSTAL_COIN).worth)},
[2] = {ITEM_PLATINUM_COIN, math.floor((value/getItemInfo(ITEM_PLATINUM_COIN).worth)-(math.floor(value/getItemInfo(ITEM_CRYSTAL_COIN).worth)*100))},
[3] = {ITEM_GOLD_COIN, math.floor(value%100)}
}
for i = 1, #config do
local count = config[i][2]
if(count > 0) then
while(count > 0) do
storageMoney = getPlayerStorageValue(cid, storage)
local a, itemCap = count > 100 and 100 or count, getItemInfo(config[i][1]).weight
if(getPlayerFreeCap(cid) >= (itemCap*a)) then
if(getPlayerFreeSpace(cid) >= 1) then
doPlayerAddItem(cid, config[i][1], a)
setPlayerStorageValue(cid, storage, (storageMoney - (getItemInfo(config[i][1]).worth * a)))
countValue = countValue + (getItemInfo(config[i][1]).worth * a)
count = count - a
else
return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have enough space in container. You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
end
else
return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have enough cap. You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
end
end
end
end
return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have took "..countValue.." gold"..(countValue > 1 and "s" or "").." from vault.")
end
------------------//* End Functions //-------------------
function onUse(cid, item, fromPosition, itemEx, toPosition)
local cidMoney, vaultMoney = getPlayerMoney(cid), getPlayerStorageValue(cid, vaultStorage)
if(vaultMoney <= 0) then
if(cidMoney <= 0) then
return doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You do not have money.")
end
doPlayerRemoveMoney(cid, cidMoney)
setPlayerStorageValue(cid, vaultStorage, cidMoney)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You have added "..cidMoney.." gold"..(cidMoney > 1 and "s" or "").." to vault. Now your money is kept in the vault chest, you can take it whenever you want.")
else
withdrawMoneySecurity(cid, vaultMoney, vaultStorage)
end
return true
end
2° - Agora em data/actions/actions.xml adicione a tag:
<action itemid="ID" event="script" value="vault.lua"/>
Em ID você escolhe o id do item que quiser.
3° - Agora em data/creaturescripts/scripts crie um arquivo com o nome vaultLook.lua, e dentro coloque isso:
local config = {
vaultId = ID, -- itemid do vault
vaultStorage = 99991 -- storage em que ficara armazenado os golds
}
function onLook(cid, thing, position, lookDistance)
local show = getPlayerStorageValue(cid, config.vaultStorage)
if(thing.itemid == config.vaultId) then
local str = "You see"..(getItemInfo(thing.itemid).article and " "..getItemInfo(thing.itemid).article.." " or " ")..getItemInfo(thing.itemid).name..".\nYou have "..(show < 0 and 0 or show).." gold"..(show > 1 and "s" or "").." in the vault."
if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
str = str .. "\nItemID: ["..thing.itemid.."].\nPosition: [X: "..getThingPos(thing.uid).x.."] [Y: "..getThingPos(thing.uid).y.."] [Z: "..getThingPos(thing.uid).z.."]."
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, str)
return false
end
return true
end
4° - Agora em data/creaturescripts/creaturescripts.xml adicione a tag:
<event type="look" name="vaultLook" event="script" value="vaultLook.lua"/>
5° - Agora em data/creaturescripts/login.lua lá embaixo adicione junto dos outros:
registerCreatureEvent(cid, "vaultLook")
E agora o sistema já esta pronto para ser usado.
- Aah mas como funciona?
Você clica uma vez no cofre (vault) e deposita todo seu dinheiro nele, ao clicar de novo você pega-os de volta, e caso não tiver cap ou espaço na bag você pega somente o possível e o restante ficara la até você quiser pegar.
--> Versão do Vault System em editText
Créditos:
MaTTch (eu)