• 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
 
Her issue is it either makes an item with 1 charge, or an item with no charges.

Then when she uses the new item, since it has no charges or only 1 charge, it "decays" on the first hit. (no charges left).

in items.xml
What do you have for the attributes for item 2433?
 
Her issue is it either makes an item with 1 charge, or an item with no charges.

Then when she uses the new item, since it has no charges or only 1 charge, it "decays" on the first hit. (no charges left).

in items.xml
What do you have for the attributes for item 2433?
I Need an item to put charges on it and every hit i lose 1 charge from it but my problem now is that when i use more runes on this item 2433 its still have only 1 charge only
EDITED
Like this stick ,this stick on Spider its working with death runes when i charge it, my problem with it
Code:
21:03 You see an Death Stick (AS: 750) that has 87 charges left.
It can only be wielded properly by .
It weighs 14.50 oz.
This Death Stick radiates huge ammount of Death.
and my stick cannot charge more than 1 charge and if i charge it more i found msg (you don't have enough soul) and i already got soul
 
Last edited:
Well I can see the problem, I think. I removed the extra costs, and I made it so that it will enchant an item to max charges when charged.
Hope it works!

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)
  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
 
Well I can see the problem, I think. I removed the extra costs, and I made it so that it will enchant an item to max charges when charged.
Hope it works!

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)
  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
This stick does not accept more than one charge ,i need it to accept more than one charge like death stick has 87 charges and if i charge more it will count more
 
This stick does not accept more than one charge ,i need it to accept more than one charge like death stick has 87 charges and if i charge more it will count more
Add it in the item.xml?

--If that doesn't work, you'll need to use a custom client with an edited .dat and .otb

Unless you want to use a "ghetto" way of coding it.
Such as:
Code:
setItemAttribute(item.uid, "ghettoCharges", 500)

Then make a weapon.xml enchangedStaff.lua that removes 1 attribute per strike, then decays back to the original.

Which would be annoying :p.
 
Add it in the item.xml?

--If that doesn't work, you'll need to use a custom client with an edited .dat and .otb

Unless you want to use a "ghetto" way of coding it.
Such as:
Code:
setItemAttribute(item.uid, "ghettoCharges", 500)

Then make a weapon.xml enchangedStaff.lua that removes 1 attribute per strike, then decays back to the original.

Which would be annoying :p.
yea that's what i need to setAttribute to this item like you said and for sure i will make enchantedstaff.lua with new attack etc but my problem isn't with this i need this item to be able to charge more than one btw i've added these Attribute on items.xml
Code:
    <attribute key="charges" value="100"/>
    <attribute key="decayTo" value="2401"/>
 
ahahah Didn't you see my post before? I've added UID at script so what is the problem now? Btw this script doesn't work :(
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)
  setItemAttribute(item.uid, "ghettoCharges", 500)

  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
  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 loser girl
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)
  setItemAttribute(item.uid, "ghettoCharges", 500)

  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
  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])
  doItemSetAttribute(itemEx.uid, "charges", 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])

  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
 
Can you tell me what happens when you use my script?
Try this loser girl
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)
  setItemAttribute(item.uid, "ghettoCharges", 500)

  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
  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])
  doItemSetAttribute(itemEx.uid, "charges", 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])

  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
hmm same thing my stick doesn't accept more than one rune to charge with it and when i use more nothing happen ,i can use it only once till it decoy on attack
EDITED and i found this error when i used my item
Code:
[19/02/2015 12:42:38] [Error - Action Interface]
[19/02/2015 12:42:38] data/actions/scripts/New.lua:onUse
[19/02/2015 12:42:38] Description:
[19/02/2015 12:42:38] data/actions/scripts/New.lua:20: attempt to call global 'setItemAttribute' (a nil value)
[19/02/2015 12:42:38] stack traceback:
[19/02/2015 12:42:38]     data/actions/scripts/New.lua:20: in function <data/actions/scripts/New.lua:6>
 
Last edited:
Btw this is my new script and i've deleted some items that i don't need and this script do not take soul or mana
Code:
local config = {
  manaCost = 300,
  soulCost = 2
}

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

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

  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])
  doItemSetAttribute(itemEx.uid, "charges", 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])

  doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYDAMAGE)
  doDecayItem(itemEx.uid)
  doRemoveItem(item.uid, 1)
  return true
end
 
/sigh~

if(item.itemid == 2147 and isInArray({2401}, itemEx.itemid)) then
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" />
 
Last edited:
/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" />
/sigh

Already tried that and she said it didn't work.
http://otland.net/threads/charges.228893/#post-2206075
 
Back
Top