• 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!

C++ [TFS 1.3] Charges are not removed from custom weapon type

charlyhustle

Member
Joined
Dec 9, 2011
Messages
55
Reaction score
9
Hi guys!

As the title suggests I created a new weapon type called gloves. I'm using gloves to train my attack speed skill.

I created a glove weapon and put in in weapons.xml (I'm using sniper gloves' id):

XML:
<!-- Attack Speed -->
<melee id="5875" action="removecharge" />

items.xml looks like this:

Code:
<item id="5875" name="speed training gloves">
<attribute key="description" value="Use these gloves as a weapon to train your attack speed." />
<attribute key="weight" value="5000" />
<attribute key="weaponType" value="gloves" />
<attribute key="charges" value="100" />
<attribute key="showcharges" value="1" />
<attribute key="decayTo" value="0" />
</item>

Removing charges from weapons like fiery spike sword works perfectly fine but the gloves stay at the same amount of charges.

Also when creating the item like "/i 5875, 100" it says:
"You see 100 speed training gloves that has 100 charges left."
instead of:
"You see a fiery spike sword (Atk:20 physical + 4 fire, Def:21 +2) that has 100 charges left."

I might have missed something while editing the sources but I'm pretty sure i've done every necessary change.
I also looked at the removecharges function but it doesn't seem that I would have to edit it since other weapon types aren't mentioned either inside the function itself.

Did I miss anything? I would highly appreciate any help!

(If you need to see source changes tell me and I will provide them!)

Thanks in advance!
 
Everything is correct. But here, you should change the line to 'removeCount,' which will decrease the charge from 100 to 99 until it reaches zero, yes.
removeCount is used for ammunition. My gloves are a weapon. I tested it anyway but same outcome. Makes no difference but I appreciate your contribution!

Does anyone else have an idea?
 
removeCount is used for ammunition. My gloves are a weapon. I tested it anyway but same outcome. Makes no difference but I appreciate your contribution!

Does anyone else have an idea?
config.lua, Check if you are about to remove charges for items "removeWeaponCharges"
 
Actually, removeCount is only for ammunition, and I haven't tested it... I just imagined it, haha. I went to check TFS 1.4, and indeed, there is a 'removecharge' function in the guns.xml file. Is it correctly set as 'true' in the line 'removeWeaponCharges = true' in your server's config.lua? And it still didn't work for you?
 
config.lua, Check if you are about to remove charges for items "removeWeaponCharges"
I got "removeWeaponCharges = true" in config
As I said the other weapons work fine.

I'm currently assuming it is because sniper gloves are not a weapon in items.otb but I can't get any of the item editors to work.
I think I tried them all by now lol.
 
By default, gloves are not a default weaponType.

I understand you say you have created a new type, but I assume the error is relating to this.

Here is the removing of the charge, best to debug here somewhere and figure out if the transform of the item is failing etc...
 
By default, gloves are not a default weaponType.

I understand you say you have created a new type, but I assume the error is relating to this.

Here is the removing of the charge, best to debug here somewhere and figure out if the transform of the item is failing etc...
I know gloves are not a weapon type. That's why I added them :D
I added gloves there:

C++:
const std::unordered_map<std::string, WeaponType_t> WeaponTypesMap = {
    {"sword", WEAPON_SWORD},
    {"club", WEAPON_CLUB},
    {"axe", WEAPON_AXE},
    {"shield", WEAPON_SHIELD},
    {"distance", WEAPON_DISTANCE},
    {"wand", WEAPON_WAND},
    {"ammunition", WEAPON_AMMO},
    {"gloves", WEAPON_GLOVES},
};

I'm currently assuming it is because sniper gloves are not a weapon in items.otb but I can't get any of the item editors to work.
I think I tried them all by now lol.

I got the assets editor to work and added a new weapon item with the sniper gloves sprite and it at least fixed the problem with the gloves showing an amount, but charges still don't get removed.
 
I know gloves are not a weapon type. That's why I added them :D
I added gloves there:

C++:
const std::unordered_map<std::string, WeaponType_t> WeaponTypesMap = {
    {"sword", WEAPON_SWORD},
    {"club", WEAPON_CLUB},
    {"axe", WEAPON_AXE},
    {"shield", WEAPON_SHIELD},
    {"distance", WEAPON_DISTANCE},
    {"wand", WEAPON_WAND},
    {"ammunition", WEAPON_AMMO},
    {"gloves", WEAPON_GLOVES},
};



I got the assets editor to work and added a new weapon item with the sniper gloves sprite and it at least fixed the problem with the gloves showing an amount, but charges still don't get removed.
Can you show what you have set in the assets editor
 
Here is the removing of the charge, best to debug here somewhere and figure out if the transform of the item is failing etc...

Yeah it's also my suspicion it has something to do with this although I thoroughly checked this case:

C++:
case WEAPONACTION_REMOVECHARGE: {
    uint16_t charges = item->getCharges();
    if (charges != 0 && g_config.getBoolean(ConfigManager::REMOVE_WEAPON_CHARGES)) {
        g_game.transformItem(item, item->getID(), charges - 1);
    }
    break;
}

And I don't see why it wouldn't work with the gloves when it works with swords, clubs and axes because the type is not mentioned there.
So either I forgot to add it anywhere else in the sources (which I doubt because I searched for every accurance of axe, sword and club and repeated it for gloves) or it's a lua related issue.
Post automatically merged:

Can you show what you have set in the assets editor
LegacyDatEditor 26.06.2024 20_54_12.png
OTBEditor 26.06.2024 20_54_30.png
 
Last edited:
I would add a std::cout just before the g_game.transformItem, and then test the removal of a charge. You can then be sure everything previous to that is working. If so, then the transforming of the item is the issue.
 
I would add a std::cout just before the g_game.transformItem, and then test the removal of a charge. You can then be sure everything previous to that is working. If so, then the transforming of the item is the issue.
I will try that and keep you updated!
Post automatically merged:

Okay while testing what you suggested I noticed I still had
XML:
<melee id="5875" action="removecount" />
instead of
XML:
<melee id="5875" action="removecharge" />
The little things sometime...

So I think what fixed it was adding the item to items.otb with the correct flags.

Only thing not working now is the
XML:
<attribute key="decayTo" value="0" />
because the gloves stay at 1 charge and won't get removed
 
Last edited:
I will try that and keep you updated!
Post automatically merged:

Okay while testing what you suggested I noticed I still had
XML:
<melee id="5875" action="removecount" />
instead of
XML:
<melee id="5875" action="removecharge" />
The little things sometime...

So I think what fixed it was adding the item to items.otb with the correct flags.

Only thing not working now is the
XML:
<attribute key="decayTo" value="0" />
because the gloves stay at 1 charge and won't get removed
Remove the decayTo attribute.
 
Back
Top