• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Charges

Mera Mero

Guess Who?
Joined
Dec 27, 2014
Messages
417
Reaction score
86
Hi , I've found script that changes item id 2401 to 2433 to use item 2433 on attack But when I used it once it's returned to 2401 but i need this item 2433 to have charges Limit 500 hmm i mean with that after 500 hits item 2433 returns to 2401 and every charge need 1 x item
Code:
local config = {
    manaCost = 300,
    soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(item.itemid == 2147 and itemEx.itemid == 2342) then
        doTransformItem(itemEx.uid, 2343)
        doDecayItem(itemEx.uid)
        doRemoveItem(item.uid, 1)

        doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        return true
    end

    if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
        doTransformItem(itemEx.uid, 2433)
        doRemoveItem(item.uid, 1)

        doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        return true
    end

    if(isInArray(enchantableGems, item.itemid)) then
        local subtype = item.type
        if(subtype == 0) then
            subtype = 1
        end

        local mana = config.manaCost * subtype
        if(getPlayerMana(cid) < mana) then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
            return true
        end

        local soul = config.soulCost * subtype
        if(getPlayerSoul(cid) < soul) then
            doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
            return true
        end

        local a = table.find(enchantableGems, item.itemid)
        if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
            return false
        end

        doTransformItem(item.uid, enchantedGems[a])
        doPlayerAddMana(cid, -mana)
        doPlayerAddSoul(cid, -soul)

        doPlayerAddSpentMana(cid, mana)
        doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
        return true
    end


        local b = table.find(enchantedGems, item.itemid)
        if(b == nil) then
            return false
        end

        local subtype = itemEx.type
        if(not isInArray({2544, 8905}, itemEx.itemid)) then
            subtype = 1000
        end

        doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
        doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
        doDecayItem(itemEx.uid)
        doRemoveItem(item.uid, 1)
        return true
end
And I've added charges on items.xml
Code:
    <attribute key="charges" value="500"/>
    <attribute key="decayTo" value="2401"/>
Action.xml
Code:
    <action itemid="2147" event="script" value="Death.lua"/>
TFS 0.3.6
 
/sigh~


First of all wtf is all that about?

Second...
Code:
//doTransformItem(uid, newId[, count/subType])  <<<<------------------------------------------ LOOK AT ME
lua_register(m_luaState, "doTransformItem", LuaInterface::luaDoTransformItem);

And finally...
Code:
    if(item.itemid == 2147 and itemEx.itemid == 2401 and doRemoveItem(item.uid, 1)) then
        doTransformItem(itemEx.uid, 2433, 500)
        doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
        return true
    end

Play by play recap of how I figured this out:
1. Went into items.xml and put charges on the magic staff
2. Went in-game and typed /i magic staff
> 100 charges
3. Looked at luascript.cpp to see if there were any parameters for count/charges for the function doTransformItem and ofc there was
4. Added it.
5. Mission complete!

Edit:
Oh I almost forgot!
<attribute key="showcharges" value="1" />
Ah thanks for your help, Its works well but there is one problem more ,when i used my rune on it the stick charged with 500 charges from 1 rune only :S and i need it to charge by 1 rune to give 1 charge and when i tired to use runes more on it doesn't remove any of them only first time
 
I guess try this:
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if(item.itemid == 2147 and itemEx.itemid == 2342) then
  doTransformItem(itemEx.uid, 2343)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
  doTransformItem(itemEx.uid, 2433, 1)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
   if(item.itemid == 2147 and isInArray({2433}, itemEx.itemid)) then
     local subtype = item.type
     if subtype >= 500 then
       doSendMagicEffect(toPosition, CONST_ME_POFF)
       return true
     end
  doTransformItem(itemEx.uid, 2433, subtype+1)
  doRemoveItem(item.uid, 1)
    
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(isInArray(enchantableGems, item.itemid)) then
  local subtype = item.type
  if(subtype == 0) then
  subtype = 1
  end

  local mana = config.manaCost
  if(getPlayerMana(cid) < mana) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
  return true
  end

  local soul = config.soulCost
  if(getPlayerSoul(cid) < soul) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
  return true
  end

  local a = table.find(enchantableGems, item.itemid)
  if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
  return false
  end
     local info = getItemInfo(enchantedGems[a])
  doTransformItem(item.uid, enchantedGems[a], info.charges)
  doPlayerAddMana(cid, -mana)
  doPlayerAddSoul(cid, -soul)

  doPlayerAddSpentMana(cid, mana)
  doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
  return true
  end


  local b = table.find(enchantedGems, item.itemid)
  if(b == nil) then
  return false
  end

  local subtype = itemEx.type
  if(not isInArray({2544, 8905}, itemEx.itemid)) then
  subtype = 1000
  end

  doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
 
I guess try this:
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if(item.itemid == 2147 and itemEx.itemid == 2342) then
  doTransformItem(itemEx.uid, 2343)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
  doTransformItem(itemEx.uid, 2433, 1)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
   if(item.itemid == 2147 and isInArray({2433}, itemEx.itemid)) then
     local subtype = item.type
     if subtype >= 500 then
       doSendMagicEffect(toPosition, CONST_ME_POFF)
       return true
     end
  doTransformItem(itemEx.uid, 2433, subtype+1)
  doRemoveItem(item.uid, 1)
  
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(isInArray(enchantableGems, item.itemid)) then
  local subtype = item.type
  if(subtype == 0) then
  subtype = 1
  end

  local mana = config.manaCost
  if(getPlayerMana(cid) < mana) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
  return true
  end

  local soul = config.soulCost
  if(getPlayerSoul(cid) < soul) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
  return true
  end

  local a = table.find(enchantableGems, item.itemid)
  if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
  return false
  end
     local info = getItemInfo(enchantedGems[a])
  doTransformItem(item.uid, enchantedGems[a], info.charges)
  doPlayerAddMana(cid, -mana)
  doPlayerAddSoul(cid, -soul)

  doPlayerAddSpentMana(cid, mana)
  doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
  return true
  end


  local b = table.find(enchantedGems, item.itemid)
  if(b == nil) then
  return false
  end

  local subtype = itemEx.type
  if(not isInArray({2544, 8905}, itemEx.itemid)) then
  subtype = 1000
  end

  doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
Something weird when i used it on stick gave me 2 charges and everytime i use it it give me 2 charges only not more and if i use like one from 100 runes stackable its give me same number as runes for example if i have 100 runes and i use one from them i will find my stick got 99 charges LoL and when i charge more this number is go to down like runes i think the problem with doTransformItem, Script of @Xagul worked good but the problem is the stick doesn't accept more than 1 rune and when i used 1 rune on it ,it gave me 500 charges
 
Try this then, I had a few typos.
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if(item.itemid == 2147 and itemEx.itemid == 2342) then
  doTransformItem(itemEx.uid, 2343)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
  doTransformItem(itemEx.uid, 2433, 1)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
   elseif(item.itemid == 2147 and isInArray({2433}, itemEx.itemid)) then
     local subtype = itemEx.type
  doTransformItem(itemEx.uid, 2433, subtype+1)
  doRemoveItem(item.uid, 1)
    
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(isInArray(enchantableGems, item.itemid)) then
  local subtype = item.type
  if(subtype == 0) then
  subtype = 1
  end

  local mana = config.manaCost
  if(getPlayerMana(cid) < mana) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
  return true
  end

  local soul = config.soulCost
  if(getPlayerSoul(cid) < soul) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
  return true
  end

  local a = table.find(enchantableGems, item.itemid)
  if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
  return false
  end
     local info = getItemInfo(enchantedGems[a])
  doTransformItem(item.uid, enchantedGems[a], info.charges)
  doPlayerAddMana(cid, -mana)
  doPlayerAddSoul(cid, -soul)

  doPlayerAddSpentMana(cid, mana)
  doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
  return true
  end


  local b = table.find(enchantedGems, item.itemid)
  if(b == nil) then
  return false
  end

  local subtype = itemEx.type
  if(not isInArray({2544, 8905}, itemEx.itemid)) then
  subtype = 1000
  end

  doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
 
Try this then, I had a few typos.
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
  if(item.itemid == 2147 and itemEx.itemid == 2342) then
  doTransformItem(itemEx.uid, 2343)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
  doTransformItem(itemEx.uid, 2433, 1)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
   elseif(item.itemid == 2147 and isInArray({2433}, itemEx.itemid)) then
     local subtype = itemEx.type
  doTransformItem(itemEx.uid, 2433, subtype+1)
  doRemoveItem(item.uid, 1)
   
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(isInArray(enchantableGems, item.itemid)) then
  local subtype = item.type
  if(subtype == 0) then
  subtype = 1
  end

  local mana = config.manaCost
  if(getPlayerMana(cid) < mana) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
  return true
  end

  local soul = config.soulCost
  if(getPlayerSoul(cid) < soul) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
  return true
  end

  local a = table.find(enchantableGems, item.itemid)
  if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
  return false
  end
     local info = getItemInfo(enchantedGems[a])
  doTransformItem(item.uid, enchantedGems[a], info.charges)
  doPlayerAddMana(cid, -mana)
  doPlayerAddSoul(cid, -soul)

  doPlayerAddSpentMana(cid, mana)
  doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
  return true
  end


  local b = table.find(enchantedGems, item.itemid)
  if(b == nil) then
  return false
  end

  local subtype = itemEx.type
  if(not isInArray({2544, 8905}, itemEx.itemid)) then
  subtype = 1000
  end

  doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
YES THANKS ITS WORKING GOOD NOW
 
Yea, my bad. the whole script is a clusterfuck to begin with.

Anyways, glad it's working.
sorry but when i tried to change id of enchanted gem id 2147 to rune id 2314 ,it doesn't work may i know why please? but i think the problem with isInArray(enchantableGems, item.itemid)) :(
 
Can you post the new script?
Lazy ass :p
Okey >.<
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

  if(item.itemid == 2314 and isInArray({2401}, itemEx.itemid)) then
  doTransformItem(itemEx.uid, 2433, 1)
  doRemoveItem(item.uid, 1)

  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
   elseif(item.itemid == 2314 and isInArray({2433}, itemEx.itemid)) then
     local subtype = itemEx.type
  doTransformItem(itemEx.uid, 2433, subtype+1)
  doRemoveItem(item.uid, 1)
   
  doSendMagicEffect(toPosition, CONST_ME_MAGIC_RED)
  return true
  end

  if(isInArray(enchantableGems, item.itemid)) then
  local subtype = item.type
  if(subtype == 0) then
  subtype = 1
  end

  local mana = config.manaCost
  if(getPlayerMana(cid) < mana) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
  return true
  end

  local soul = config.soulCost
  if(getPlayerSoul(cid) < soul) then
  doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHSOUL)
  return true
  end

  local a = table.find(enchantableGems, item.itemid)
  if(a == nil or not isInArray(enchantingAltars[a], itemEx.itemid)) then
  return false
  end
     local info = getItemInfo(enchantedGems[a])
  doTransformItem(item.uid, enchantedGems[a], info.charges)
  doPlayerAddMana(cid, -mana)
  doPlayerAddSoul(cid, -soul)

  doPlayerAddSpentMana(cid, mana)
  doSendMagicEffect(fromPosition, CONST_ME_HOLYDAMAGE)
  return true
  end


  local b = table.find(enchantedGems, item.itemid)
  if(b == nil) then
  return false
  end

  local subtype = itemEx.type
  if(not isInArray({2401, 2401}, itemEx.itemid)) then
  subtype = 1000
  end

  doTransformItem(itemEx.uid, enchantedItems[itemEx.itemid][b], subtype)
  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
 
Lol the fights begin.

I don't mind helping, I help everyone. I just like teasing people that make silly requests.

Mera Mero, if you think about it, making a max is really easy.

To stop a script from running, you just put "return true" or "return false"

So if the number of charges on the item is already 500, then all you have to do is "return true"

for example
Code:
if subtype >= 500 then
  return true
end
 
Lol the fights begin.

I don't mind helping, I help everyone. I just like teasing people that make silly requests.

Mera Mero, if you think about it, making a max is really easy.

To stop a script from running, you just put "return true" or "return false"

So if the number of charges on the item is already 500, then all you have to do is "return true"

for example
Code:
if subtype >= 500 then
  return true
end
Actually i'm not fighting but this guy i don't know what is his problem with me :( btw i tried to make it like you said and made reload ,it doesn't work and didn't give me error too :S
Code:
if subtype >= 5 then
  return true
end
 
Back
Top