Ir para conteúdo

[Encerrado] Adaptar Script - Ajuda!


Seagull

Posts Recomendados

Boa Tarde.

Gostaria de Ajuda para adaptar uma script URGENTE. Bom ela faz consulta em uma .lib, quero que funcione mais ou menos assim:

Você da use na pedra e no item, o resto e com a .lib.

 

Segue o codigo:

 

function onUse(cid, item, frompos, item2, topos)
if(not isCreature(item2.uid)) then
	local itemEx = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 2})
	local sloter = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
	local prick = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 3})

	if((itemEx.itemid == 0) or (sloter.itemid == 0) or (prick.itemid ~= 2555)) then
		return true
	end

	local slotItem = Slots:loadItem(itemEx)

	if(slotItem and slotItem:openNewSlot(cid, sloter)) then
		doSendMagicEffect(topos, 30)
	else
		doSendMagicEffect(topos, 2)
	end
end

return true
end

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

Quero que ao usar as pedras da LIB, aconteça o que esta na LIB. Suma a pedra de um status para o equipamento, só que quero que só precise dar "use with" na pedra e no item.

 

.LIB

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][i] = 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 

 

function onUse(cid, item, frompos, item2, topos)
   if(not isCreature(item2.uid)) then
    local itemEx = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 2})
    local sloter = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    local prick = getThingFromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 3})
    if((itemEx.itemid == 0) or (sloter.itemid == 0) or (prick.itemid ~= 2555)) then
	    return true
    end
    local slotItem = Slots:loadItem(itemEx)
    if(slotItem and slotItem:openNewSlot(cid, sloter)) then
	    doSendMagicEffect(topos, 30)
    else
	    doSendMagicEffect(topos, 2)
    end
   end
   return true
end 

Link para o comentário
Compartilhar em outros sites

  • 2 months later...
  • 4 years later...
A questão neste tópico de suporte foi encerrada por falta de respostas. Este tópico está fechado e foi movido para Suporte - Tópicos Sem Resposta.

+ Caso a dúvida não tenha sido resolvida você poderá criar outro tópico solicitando ajuda.
* Lembre-se que é permitido dar UP no tópico a cada 24 horas para assim o destacar e manter movimentado.
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...