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

Auto recharge last arrow [0.4]

nintry

New Member
Joined
Oct 18, 2017
Messages
6
Reaction score
2
I need some help to make a function to:
- When player shot the last ammo (arrow, bolt...)
- If player have another ammo like that on inventory
- Automatically recharge

A guy here made some like that:
Feature - Auto recharge ammo
And some guys tried to convert to 0.4 with no sucess:
Compiling - Help to add Auto Recharge Ammo in 0.4

I've tried too with this errors:
Code:
weapons.cpp:447:48: error: ‘class Player’ has no member named ‘getItemTypeCount’; did you mean ‘__getItemTypeCount’?
                 uint32_t playerCount = player->getItemTypeCount(item->getID());
                                                ^~~~~~~~~~~~~~~~
weapons.cpp:451:37: error: ‘class Player’ has no member named ‘removeItemOfType’; did you mean ‘removeEnemy’?
                             player->removeItemOfType(item->getID(), 100);
                                     ^~~~~~~~~~~~~~~~
weapons.cpp:452:37: error: ‘class Player’ has no member named ‘addItem’; did you mean ‘addEnemy’?
                             player->addItem(itemid, 100, 0, CONST_SLOT_AMMO);
                                     ^~~~~~~
weapons.cpp:452:61: error: ‘CONST_SLOT_AMMO’ was not declared in this scope
                             player->addItem(itemid, 100, 0, CONST_SLOT_AMMO);
                                                             ^~~~~~~~~~~~~~~
weapons.cpp:456:37: error: ‘class Player’ has no member named ‘removeItemOfType’; did you mean ‘removeEnemy’?
                             player->removeItemOfType(item->getId(), playerCount);
                                     ^~~~~~~~~~~~~~~~
weapons.cpp:456:60: error: ‘class Item’ has no member named ‘getId’; did you mean ‘getID’?
                             player->removeItemOfType(item->getId(), playerCount);
                                                            ^~~~~
weapons.cpp:457:37: error: ‘class Player’ has no member named ‘addItem’; did you mean ‘addEnemy’?
                             player->addItem(itemid, playerCount, 0, CONST_SLOT_AMMO);
                                     ^~~~~~~
weapons.cpp:457:69: error: ‘CONST_SLOT_AMMO’ was not declared in this scope
                             player->addItem(itemid, playerCount, 0, CONST_SLOT_AMMO);
                                                                     ^~~~~~~~~~~~~~~
Makefile:8: recipe for target 'tfs' failed
make: *** [tfs] Error 1

weapons.cpp:
hastebin
 
Solution
X
Returning this error:
Code:
[16:11:58.024] [Error - Weapon Interface]
[16:11:58.024] data/weapons/scripts/distance_weapons/arrows/arrow.lua:onUseWeapon
[16:11:58.024] Description:
[16:11:58.024] ...ta/weapons/scripts/distance_weapons/arrows/arrow.lua:2: attempt to index local 'item' (a number value)
[16:11:58.024] stack traceback:
[16:11:58.024]    ...ta/weapons/scripts/distance_weapons/arrows/arrow.lua:2: in function 'getItemCount'
[16:11:58.024]    ...ta/weapons/scripts/distance_weapons/arrows/arrow.lua:10: in function 'autoRechargeAmmo'
[16:11:58.024]    ...ta/weapons/scripts/distance_weapons/arrows/arrow.lua:75: in function <...ta/weapons/scripts/distance_weapons/arrows/arrow.lua:74>
I'm not sure how your getting that...
What are u mean to change this line autoRechargeAmmo(cid, CONST_SLOT_AMMO)
You mean change autoRechargeAmmo(cid) to autoRechargeAmmo(cid, CONST_SLOT_AMMO)?

This is my small stone script:
Code:
local function autoRechargeAmmo(cid, slot)
    local ammo_in_slot = getPlayerSlotItem(cid, slot).uid
    if ammo_in_slot == 0 then
        return false
    end
    ammo_in_slot = getPlayerSlotItem(cid, slot).type
    if ammo_in_slot ~= 1 then
        return false
    end
  
    local ammo_itemid = getPlayerSlotItem(cid, slot).itemid
    local ammo_count = getPlayerItemCount(cid, ammo_itemid) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, ammo_itemid, ammo_count)
            doPlayerAddItem(cid, ammo_itemid, ammo_count)
        end, 1
    )
    return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 2)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
    min = ((damagebase_min) * (attack) * (skill)) * -0.10
    max = ((damagebase_max) * (attack) * (skill)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
    autoRechargeAmmo(cid, CONST_SLOT_AMMO)
    return doCombat(cid, combat, var)
end

Is this not working because small stone break rarelly, while arrows broke every shot?
No it should still work.
You need to edit that line to work properly with your script.
Code:
CONST_SLOT_HEAD
CONST_SLOT_NECKLACE
CONST_SLOT_BACKPACK
CONST_SLOT_ARMOR
CONST_SLOT_RIGHT
CONST_SLOT_LEFT
CONST_SLOT_LEGS
CONST_SLOT_FEET
CONST_SLOT_RING
CONST_SLOT_AMMO
 
No it should still work.
You need to edit that line to work properly with your script.
Code:
CONST_SLOT_HEAD
CONST_SLOT_NECKLACE
CONST_SLOT_BACKPACK
CONST_SLOT_ARMOR
CONST_SLOT_RIGHT
CONST_SLOT_LEFT
CONST_SLOT_LEGS
CONST_SLOT_FEET
CONST_SLOT_RING
CONST_SLOT_AMMO

There is no way to detect where the small stone was before?
Because i could put right, and shield was on right and unequip shield...
 
There is no way to detect where the small stone was before?
Because i could put right, and shield was on right and unequip shield...
ah, I see your issue.
Try this.
LUA:
local function autoRechargeAmmo(cid, slot)
    local ammo_in_slot = getPlayerSlotItem(cid, slot).uid
    if ammo_in_slot == 0 then
        return false
    end
    ammo_in_slot = getPlayerSlotItem(cid, slot).type
    if ammo_in_slot ~= 1 then
        return false
    end
   
    local ammo_itemid = getPlayerSlotItem(cid, slot).itemid
    local ammo_count = getPlayerItemCount(cid, ammo_itemid) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, ammo_itemid, ammo_count)
            doPlayerAddItem(cid, ammo_itemid, ammo_count)
        end, 1
    )
    return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 2)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
    min = ((damagebase_min) * (attack) * (skill)) * -0.10
    max = ((damagebase_max) * (attack) * (skill)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
    if getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid > 0 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).type > 0 then
        autoRechargeAmmo(cid, CONST_SLOT_RIGHT)
    else
        autoRechargeAmmo(cid, CONST_SLOT_LEFT)
    end
    return doCombat(cid, combat, var)
end
 
ah, I see your issue.
Try this.
LUA:
local function autoRechargeAmmo(cid, slot)
    local ammo_in_slot = getPlayerSlotItem(cid, slot).uid
    if ammo_in_slot == 0 then
        return false
    end
    ammo_in_slot = getPlayerSlotItem(cid, slot).type
    if ammo_in_slot ~= 1 then
        return false
    end
  
    local ammo_itemid = getPlayerSlotItem(cid, slot).itemid
    local ammo_count = getPlayerItemCount(cid, ammo_itemid) - 1
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    addEvent (
        function ()
            doPlayerRemoveItem(cid, ammo_itemid, ammo_count)
            doPlayerAddItem(cid, ammo_itemid, ammo_count)
        end, 1
    )
    return true
end

local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 2)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

function onGetFormulaValues(cid, level, skill, attack, factor)
    min = ((damagebase_min) * (attack) * (skill)) * -0.10
    max = ((damagebase_max) * (attack) * (skill)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onUseWeapon(cid, var)
    if getPlayerSlotItem(cid, CONST_SLOT_RIGHT).uid > 0 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).type > 0 then
        autoRechargeAmmo(cid, CONST_SLOT_RIGHT)
    else
        autoRechargeAmmo(cid, CONST_SLOT_LEFT)
    end
    return doCombat(cid, combat, var)
end

Still not recharging :(
No errors on console
 
Back
Top