Ir para conteúdo

Alguem Me Ajdua Fazendo O Script Para Esse Slot System?


nari

Posts Recomendados

  • Explicação:

Pra quem conhece o sistema do mock, é praticamente igual, porém menos poggado, e também é possível a configuração de várias pedras, chamadas sloters (só pra por um bendito nome), portanto os bonus não são randômicos.

  • Script:

Crie algum arquivo .lua em data/lib e adcione isso:

 

 

SlotCondition = {}

 

Slots = {

config = {

maxSlots = 2,

msg = {

type = MESSAGE_STATUS_DEFAULT,

cantOpenSlot = "You cant open a slot on this item, or this isn't a valid sloter.",

maxStat = "You can't add more bonus on this item with this sloter.",

upgrade = "You upgrated the %s slot from %s to %s.",

failed = "You failed upgrading the slot.",

errorMsg = "Put the item on the table, and then the sloter, and use the hammer on it."

},

 

conditions = {

hp = {CONDITION_PARAM_STAT_MAXHEALTHPERCENT, 50},

mp = {CONDITION_PARAM_STAT_MAXMANAPERCENT, 51},

ml = {CONDITION_PARAM_STAT_MAGICLEVELPERCENT, 52},

club = {CONDITION_PARAM_SKILL_CLUBPERCENT, 53},

sword = {CONDITION_PARAM_SKILL_SWORDPERCENT, 54},

axe = {CONDITION_PARAM_SKILL_AXEPERCENT, 55},

shield = {CONDITION_PARAM_SKILL_SHIELDPERCENT, 56},

dist = {CONDITION_PARAM_SKILL_DISTANCEPERCENT, 57}

},

 

chance = function(level, status, max)

return 1-(1-((level/5) - (status/max)))

end

},

 

sloters = {

[8303] = {"hp", {1, 15, 6}},

[8302] = {"mp", {1, 8, 5}},

[8301] = {"ml", {1, 4, 5}},

[8310] = {"club", {1, 6, 6}},

[8299] = {"sword", {1, 6, 6}},

[8298] = {"axe", {1, 6, 6}},

[8309] = {"shield", {1, 4, 5}},

[8297] = {"dist", {1, 5, 5}}

},

 

appendItemName = function(self, txt)

return self:setItemName(self:getItemName() .. " " .. txt)

end,

 

playerMessage = function(self, cid, msg, ...)

return doPlayerSendTextMessage(cid, self.config.msg.type, self.config.msg[msg]:format(...))

end,

 

isHandEquipment = function(self)

local weptype = self:getItemWeaponType()

return (weptype > 0) and (weptype < 7)

end,

 

isEquipment = function(self)

return self:isHandEquipment() or (self.item.info.armor ~= 0)

end,

 

 

loadConditions = function(self)

for cond, id in pairs(self.config.conditions) do

SlotCondition[cond] = {}

 

for i = 1, 100 do

local slotCondition = createConditionObject(CONDITION_ATTRIBUTES)

setConditionParam(slotCondition, CONDITION_PARAM_TICKS, -1)

setConditionParam(slotCondition, id[1], 100+i)

setConditionParam(slotCondition, CONDITION_PARAM_BUFF, true)

setConditionParam(slotCondition, CONDITION_PARAM_SUBID, id[2])

 

SlotCondition[cond] = slotCondition

end

end

end,

 

setItemName = function(self, name)

return doItemSetAttribute(self.item.uid, "name", name)

end

}

 

Slots:loadConditions()

 

function Slots:loadItem(item)

local newObj = setmetatable({item = {uid = item.uid, info = getItemInfo(item.itemid)}}, {__index = function(self, index)

if(_G[index]) then

return setmetatable({callback = _G[index]}, {__call = function(self, ...)

return self.callback(item.uid, ...)

end})

else

return Slots[index]

end

end})

 

if(not newObj:isEquipment()) then return false end

 

newObj:getItemSlotCount()

return newObj

end

 

 

function Slots:getItemSlotCount()

local e, n = self:getItemName():gsub("%[.-%]", "")

self.item.slotCount = n

return true

end

 

function Slots:getItemStatusBonus(status)

local bonus = self:getItemName():match("%[".. status .."%+(.-)%%%]")

 

return tonumber(bonus) or 0

end

 

function Slots:getItemBonus()

local result = {}

self:getItemName():gsub("%[(.-)%+.-%%%]", function(s) table.insert(result, {s, self:getItemStatusBonus(s)}) return "" end)

 

return result

end

 

function Slots:openNewSlot(cid, sloter)

local sloterInfo = self.sloters[sloter.itemid]

 

if(not sloterInfo) then

self:playerMessage(cid, "errorMsg")

return false

end

 

local statusBonus = self:getItemStatusBonus(sloterInfo[1])

 

if((statusBonus == 0) and self.item.slotCount == self.config.maxSlots) then

self:playerMessage(cid, "cantOpenSlot")

return false

end

 

if(self:isEquipment()) then

if(statusBonus >= sloterInfo[2][2]) then

self:playerMessage(cid, "maxStat")

return false

end

 

doRemoveItem(sloter.uid, 1)

 

if(math.random(0, 100) < (self.config.chance(sloterInfo[2][3], statusBonus, sloterInfo[2][2]) * 100)) then

if(statusBonus > 0) then

self:setItemName(self:getItemName():gsub("%[".. sloterInfo[1] .."%+(.-)%%%]", ("[%s+%s%%]"):format(sloterInfo[1], statusBonus + sloterInfo[2][1] .. "%")))

else

self:appendItemName(("[%s+%s%%]"):format(sloterInfo[1], statusBonus + sloterInfo[2][1]))

end

 

self:playerMessage(cid, "upgrade", sloterInfo[1], statusBonus .. "%", statusBonus + sloterInfo[2][1] .. "%")

 

return true

end

 

self:playerMessage(cid, "failed")

 

return false

else

self:playerMessage(cid, "cantOpenSlot")

return false

end

end

 

Set = {

config = {

checkTime = 2000

},

 

isOnline = function(self)

local players = getOnlinePlayers()

 

for i, v in ipairs(players) do

if(getCreatureByName(v) == self.cid) then

return true

end

end

 

return false

end

}

 

function Set:loadSetFromPlayer(cid, n)

local newSet = setmetatable({cid = cid}, {__index = self})

 

return n and newSet:loadBonus() or newSet:removeConditions()

end

 

function Set:removeConditions(subid)

if(subid) then

doRemoveCondition(self.cid, CONDITION_ATTRIBUTES, subid)

 

return true

end

 

for cond, id in pairs(Slots.config.conditions) do

doRemoveCondition(self.cid, CONDITION_ATTRIBUTES, id[2])

end

end

 

function Set:loadBonus()

if(not self:isOnline()) then return false end

 

for subid = 50, #Slots.config.conditions do

doRemoveCondition(self.cid, CONDITION_ATTRIBUTES, subid)

end

 

local bonus = {}

 

for slot = 1, 9 do

local slotItem = getPlayerSlotItem(self.cid, slot)

 

if(slotItem.itemid ~= 0) then

local item = Slots:loadItem(slotItem)

 

if(item) then

for i, v in ipairs(item:getItemBonus()) do

if((slot == 5) or (slot == 6)) then

if(item:isHandEquipment()) then

bonus[v[1]] = (bonus[v[1]] or 0) + v[2]

end

else

bonus[v[1]] = (bonus[v[1]] or 0) + v[2]

end

end

end

end

end

 

for cond, id in pairs(Slots.config.conditions) do

if(bonus[cond]) then

local v = (cond == "hp") and getCreatureHealth(self.cid) or (cond == "mp") and getCreatureMana(self.cid)

 

doAddCondition(self.cid, SlotCondition[cond][bonus[cond] > 100 and 100 or bonus[cond]])

doCreatureAddHealth(self.cid, (cond == "hp") and (v - getCreatureHealth(self.cid)) or 0)

doCreatureAddMana(self.cid, (cond == "mp") and (v - getCreatureMana(self.cid)) or 0)

else

doRemoveCondition(self.cid, CONDITION_ATTRIBUTES, id[2])

end

 

end

 

addEvent(self.loadBonus, self.config.checkTime, self)

end

Editado por Nari
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...