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

TFS 0.X Auto assassin star recharge

fyalhed

Member
Joined
Nov 18, 2017
Messages
156
Reaction score
20
I'm trying to do a auto recharge for my assassin star...
Why it don't work?

No errors, just do not work :(

Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

local function autoRechargeAmmo(cid)
    -- get hand slot
    local ammo_in_slot
    local item1 = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local item2 = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    local bowattack, hand1, hand2 = 0, 0, 0
    if item1.uid ~= 0 then
        hand1 = getItemInfo(item1.itemid).attack
    end
    if item2.uid ~= 0 then
        hand2 = getItemInfo(item2.itemid).attack
    end
    if hand1 > hand2 then
       ammo_in_slot = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
        bowattack = hand1
    else
        ammo_in_slot = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    end
    --
    if ammo_in_slot == 0 then
        return false
    end
    ammo_in_slot = getPlayerSlotItem(cid, CONST_SLOT_AMMO).type
    if ammo_in_slot ~= 1 then
        return false
    end
    local ammo_itemid = getPlayerSlotItem(cid, CONST_SLOT_AMMO).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

function onGetFormulaValues(cid, level, skill, attack, factor)
   -- get attack mode
   local damagebase_min = wbdmg_distance_min
   local damagebase_max = wbdmg_distance_max
   if factor == 1.0 then -- player_fight_mode = offensive
       damagebase_min = damagebase_min * 3
       damagebase_max = damagebase_max * 3
   elseif factor == 2.0 then -- player_fight_mode = defensive
       damagebase_min = damagebase_min * 1
       damagebase_max = damagebase_max * 1
   else  -- player_fight_mode = balanced
       damagebase_min = damagebase_min * 2
       damagebase_max = damagebase_max * 2
   end
   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)
    return doCombat(cid, combat, var)
end
 
No!
I just wanna make a script to auto recharge XD
Like bots do, bot for player who play on hands, to be fair.
Soo, for players who play on hands u can make spell/talkactoion "RELOAD AMMO xD" soo when ammo end player hit the hotkey and ammo reloaded, for players who dont wanna use "bots" is good idea and simple for you xD Try find more than one solving options, this will help you in making server :p

Anyway, make this autorecharge in other file, only autorecharge function, try use onThink and make something like "if ammo slot empty then add item".
 
Soo, for players who play on hands u can make spell/talkactoion "RELOAD AMMO xD" soo when ammo end player hit the hotkey and ammo reloaded, for players who dont wanna use "bots" is good idea and simple for you xD Try find more than one solving options, this will help you in making server :p

Anyway, make this autorecharge in other file, only autorecharge function, try use onThink and make something like "if ammo slot empty then add item".

Make the player use a talkaction or a spell to recharge the ammo is almost let player refill on hands
On boots u have 2000 assassin stars on backpack and it refill everytime after over

I have to do it in movemment, but i have no idea why its not work
 
Using @Xikini base

Code:
local assassin_stars_itemID = 7368
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, assassin_stars_itemID, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end
local function autoRefillAssassinStars(cid)  
    -- find which hand has assassin stars equipped
    local hand_to_check = 0
    local left_hand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local right_hand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if left_hand.uid ~= 0 and left_hand.itemid == assassin_stars_itemID then
        print(111)
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        print(222)
        hand_to_check = CONST_SLOT_RIGHT
    else
        print("ERROR -- This should be impossible to ever see.")
        if left_hand.uid ~= 0 then
            print("" .. left_hand.uid .. ", " .. left_hand.itemid .. "")
        else
            print("" .. left_hand.uid .. ", 0")
        end
        if right_hand.uid ~= 0 then
            print("" .. right_hand.uid .. ", " .. right_hand.itemid .. "")
        else
            print("" .. right_hand.uid .. ", 0")
        end
        return false
    end
   
    print(333)
    -- check if only 1 ammo left
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    print(ammo_in_slot)
    if ammo_in_slot ~= 1 then
        print("Finished normally, ammo not refilled. (ammo in slot above 1)")
        return false
    end
   
    print(444)
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    print(ammo_count)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    print(ammo_count)
    if ammo_count > 0 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        print("Finished normally, ammo not refilled. (no ammo available for refill.)")
        return false
    end
    return true
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

Why it's not entering in
Code:
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, assassin_stars_itemID, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end

Is printing:
Code:
111
333
2
Finished normally, ammo not refilled. (ammo in slot above 1)
111
333
1
444
29
29
1001
1002
Finished normally, ammo refilled.
 
If i change this line to blank rune ID:
Code:
doPlayerAddItem(cid, 2260, ammo_count)

Code:
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, 2260, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end

It's adding blank runes on hands normal, but if i back to assassin stars it is not adding assassin star on hands:
full code:
Code:
local assassin_stars_itemID = 7368
local function refillAssassinStars(cid, ammo_count)
    if isPlayer(cid) then
        print(01001)
        doPlayerRemoveItem(cid, assassin_stars_itemID, ammo_count)
        doPlayerAddItem(cid, 2260, ammo_count)
        print(01002)
        print("Finished normally, ammo refilled.")
    end
end
local function autoRefillAssassinStars(cid)  
    -- find which hand has assassin stars equipped
    local hand_to_check = 0
    local left_hand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local right_hand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    if left_hand.uid ~= 0 and left_hand.itemid == assassin_stars_itemID then
        print(111)
        hand_to_check = CONST_SLOT_LEFT
    elseif right_hand.uid ~= 0 and right_hand.itemid == assassin_stars_itemID then
        print(222)
        hand_to_check = CONST_SLOT_RIGHT
    else
        print("ERROR -- This should be impossible to ever see.")
        if left_hand.uid ~= 0 then
            print("" .. left_hand.uid .. ", " .. left_hand.itemid .. "")
        else
            print("" .. left_hand.uid .. ", 0")
        end
        if right_hand.uid ~= 0 then
            print("" .. right_hand.uid .. ", " .. right_hand.itemid .. "")
        else
            print("" .. right_hand.uid .. ", 0")
        end
        return false
    end
   
    print(333)
    -- check if only 1 ammo left
    local ammo_in_slot = getPlayerSlotItem(cid, hand_to_check).type
    print(ammo_in_slot)
    if ammo_in_slot ~= 1 then
        print("Finished normally, ammo not refilled. (ammo in slot above 1)")
        return false
    end
   
    print(444)
    -- refill assassin stars
    local ammo_count = getPlayerItemCount(cid, assassin_stars_itemID) - 1
    print(ammo_count)
    ammo_count = ammo_count >= 100 and 100 or ammo_count
    print(ammo_count)
    if ammo_count > 0 then
        addEvent(refillAssassinStars, 1, cid, ammo_count)
    else
        print("Finished normally, ammo not refilled. (no ammo available for refill.)")
        return false
    end
    return true
end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_BLOCKARMOR, 1)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, 18)
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
function onGetFormulaValues(cid, level, skill, attack, factor)
    -- get attack mode
    local damagebase_min = wbdmg_distance_min
    local damagebase_max = wbdmg_distance_max
    if factor == 1.0 then -- player_fight_mode = offensive
        damagebase_min = damagebase_min * 3
        damagebase_max = damagebase_max * 3
    elseif factor == 2.0 then -- player_fight_mode = defensive
        damagebase_min = damagebase_min * 1
        damagebase_max = damagebase_max * 1
    else  -- player_fight_mode = balanced
        damagebase_min = damagebase_min * 2
        damagebase_max = damagebase_max * 2
    end
    min = ((damagebase_min) * (attack * 12) * (skill * 3)) * -0.10
    max = ((damagebase_max) * (attack * 12) * (skill * 3)) * -1.00
    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")
function onUseWeapon(cid, var)
    autoRefillAssassinStars(cid)
    return doCombat(cid, combat, var)
end

Why?
 
Back
Top